Skip to content

Commit e7545c7

Browse files
authored
build: fix generate_protos session (#28)
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)
1 parent b4bb224 commit e7545c7

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

packages/google-cloud-access-context-manager/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ pylintrc
5858
pylintrc.test
5959

6060
# Exclude python-asset which is copied for testing
61-
python-asset/
61+
python-asset/
62+
63+
# Exclude api-common-protos which is only needed for generation
64+
api-common-protos

packages/google-cloud-access-context-manager/noxfile.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,40 @@ def test(session, library):
174174
system(session)
175175

176176

177-
# @nox.session(python="3.8")
178-
# def generate_protos(session):
179-
# """Generates the protos using protoc.
180-
#
181-
# THIS SESSION CAN ONLY BE RUN LOCALLY
182-
# Clone `api-common-protos` in the parent directory
183-
#
184-
# Some notes on the `google` directory:
185-
# 1. The `_pb2.py` files are produced by protoc.
186-
# 2. The .proto files are non-functional but are left in the repository
187-
# to make it easier to understand diffs.
188-
# 3. The `google` directory also has `__init__.py` files to create proper modules.
189-
# If a new subdirectory is added, you will need to create more `__init__.py`
190-
# files.
191-
# """
192-
# session.install("grpcio-tools")
193-
# protos = [str(p) for p in (Path(".").glob("google/**/*.proto"))]
194-
195-
# session.run(
196-
# "python",
197-
# "-m",
198-
# "grpc_tools.protoc",
199-
# "--proto_path=../api-common-protos",
200-
# "--proto_path=.",
201-
# "--python_out=.",
202-
# *protos,
203-
# )
177+
@nox.session(python="3.8")
178+
def generate_protos(session):
179+
"""Generates the protos using protoc.
180+
181+
Some notes on the `google` directory:
182+
1. The `_pb2.py` files are produced by protoc.
183+
2. The .proto files are non-functional but are left in the repository
184+
to make it easier to understand diffs.
185+
3. The `google` directory also has `__init__.py` files to create proper modules.
186+
If a new subdirectory is added, you will need to create more `__init__.py`
187+
files.
188+
"""
189+
session.install("grpcio-tools")
190+
protos = [str(p) for p in (Path(".").glob("google/**/*.proto"))]
191+
192+
# Clone googleapis/api-common-protos
193+
api_common_protos = "api-common-protos"
194+
try:
195+
session.run("git", "-C", api_common_protos, "pull", external=True)
196+
except nox.command.CommandFailed:
197+
session.run(
198+
"git",
199+
"clone",
200+
"--single-branch",
201+
f"https://github.com/googleapis/{api_common_protos}",
202+
external=True,
203+
)
204+
205+
session.run(
206+
"python",
207+
"-m",
208+
"grpc_tools.protoc",
209+
"--proto_path=api-common-protos",
210+
"--proto_path=.",
211+
"--python_out=.",
212+
*protos,
213+
)

0 commit comments

Comments
 (0)