Skip to content

Commit

Permalink
build: fix generate_protos session (#28)
Browse files Browse the repository at this point in the history
Uncomment `generate_protos` and clone `api-common-protos` inside the session so it can be run in autosynth.

Fixes #27  🦕

Verify locally by doing `nox -s generate_protos` (no additional setup should be required)
  • Loading branch information
busunkim96 committed Apr 14, 2021
1 parent 166c54c commit 302c106
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -58,4 +58,7 @@ pylintrc
pylintrc.test

# Exclude python-asset which is copied for testing
python-asset/
python-asset/

# Exclude api-common-protos which is only needed for generation
api-common-protos
64 changes: 37 additions & 27 deletions noxfile.py
Expand Up @@ -174,30 +174,40 @@ def test(session, library):
system(session)


# @nox.session(python="3.8")
# def generate_protos(session):
# """Generates the protos using protoc.
#
# THIS SESSION CAN ONLY BE RUN LOCALLY
# Clone `api-common-protos` in the parent directory
#
# Some notes on the `google` directory:
# 1. The `_pb2.py` files are produced by protoc.
# 2. The .proto files are non-functional but are left in the repository
# to make it easier to understand diffs.
# 3. The `google` directory also has `__init__.py` files to create proper modules.
# If a new subdirectory is added, you will need to create more `__init__.py`
# files.
# """
# session.install("grpcio-tools")
# protos = [str(p) for p in (Path(".").glob("google/**/*.proto"))]

# session.run(
# "python",
# "-m",
# "grpc_tools.protoc",
# "--proto_path=../api-common-protos",
# "--proto_path=.",
# "--python_out=.",
# *protos,
# )
@nox.session(python="3.8")
def generate_protos(session):
"""Generates the protos using protoc.
Some notes on the `google` directory:
1. The `_pb2.py` files are produced by protoc.
2. The .proto files are non-functional but are left in the repository
to make it easier to understand diffs.
3. The `google` directory also has `__init__.py` files to create proper modules.
If a new subdirectory is added, you will need to create more `__init__.py`
files.
"""
session.install("grpcio-tools")
protos = [str(p) for p in (Path(".").glob("google/**/*.proto"))]

# Clone googleapis/api-common-protos
api_common_protos = "api-common-protos"
try:
session.run("git", "-C", api_common_protos, "pull", external=True)
except nox.command.CommandFailed:
session.run(
"git",
"clone",
"--single-branch",
f"https://github.com/googleapis/{api_common_protos}",
external=True,
)

session.run(
"python",
"-m",
"grpc_tools.protoc",
"--proto_path=api-common-protos",
"--proto_path=.",
"--python_out=.",
*protos,
)

0 comments on commit 302c106

Please sign in to comment.