Skip to content

Commit

Permalink
chore: fix generation (for real)
Browse files Browse the repository at this point in the history
Release-As: 1.52.0
  • Loading branch information
busunkim96 committed Jun 4, 2020
1 parent 70a49c3 commit 281b5d1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
64 changes: 42 additions & 22 deletions packages/googleapis-common-protos/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,14 @@ def lint_setup_py(session):
session.run("python", "setup.py", "check", "--strict")


@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"))]
session.run(
"python", "-m", "grpc_tools.protoc", "--proto_path=.", "--python_out=.", *protos
)


def default(session):
# Install all test dependencies, then install this package in-place.
session.install("mock", "pytest", "pytest-cov")
session.install("-e", ".")

# Install googleapis-api-common-protos
# This *must* be the last install command to get the package from source.
session.install("..")
session.install("e", "..")

# Run py.test against the unit tests.
session.run(
Expand Down Expand Up @@ -112,7 +93,7 @@ def system(session):

# Install googleapis-api-common-protos
# This *must* be the last install command to get the package from source.
session.install("..")
session.install("e", "..")

# Run py.test against the system tests.
if system_test_exists:
Expand Down Expand Up @@ -150,7 +131,7 @@ def test(session, library):
f"https://github.com/googleapis/{library}",
external=True,
)

session.cd(library)

unit(session)
Expand All @@ -160,3 +141,42 @@ def test(session, library):
if library == "python-pubsub":
session.install("psutil")
system(session)


@nox.session(python="3.8")
def generate_protos(session):
"""Generates the protos using protoc.
This session but be last to avoid overwriting the protos used in CI runs.
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.
"""
# longrunning operations directory is non-standard for backwards compatibility
# see comments in directory for details
# Temporarily rename the operations_pb2.py to keep it from getting overwritten
os.replace(
"google/longrunning/operations_pb2.py",
"google/longrunning/operations_pb2-COPY.py",
)

session.install("grpcio-tools")
protos = [str(p) for p in (Path(".").glob("google/**/*.proto"))]
session.run(
"python", "-m", "grpc_tools.protoc", "--proto_path=.", "--python_out=.", *protos
)

# Clean up LRO directory
os.replace(
"google/longrunning/operations_pb2.py",
"google/longrunning/operations_proto_pb2.py",
)
os.replace(
"google/longrunning/operations_pb2-COPY.py",
"google/longrunning/operations_pb2.py",
)
2 changes: 1 addition & 1 deletion packages/googleapis-common-protos/synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"git": {
"name": ".",
"remote": "git@github.com:googleapis/python-api-common-protos",
"sha": "56fe5cd29a697b8c732c44e39adc7ded7aa69640"
"sha": "f3e2589fd93cb1585d70d91facfe2a618f68969a"
}
},
{
Expand Down
14 changes: 0 additions & 14 deletions packages/googleapis-common-protos/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,9 @@
s.move(templated_files / "LICENSE")
s.move(templated_files / ".github")

# longrunning operations directory is non-standard for backwards compatibility
# see comments in directory for details
# Temporarily rename the operations_pb2.py to keep it from getting overwritten
os.replace("google/longrunning/operations_pb2.py", "google/longrunning/operations_pb2-COPY.py")

# Generate _pb2.py files and format them
s.shell.run(["nox", "-s", "generate_protos"], hide_output=False)

# Clean up LRO directory
os.replace(
"google/longrunning/operations_pb2.py", "google/longrunning/operations_proto_pb2.py"
)
os.replace(
"google/longrunning/operations_pb2-COPY.py", "google/longrunning/operations_pb2.py"
)


s.shell.run(["nox", "-s", "blacken"], hide_output=False)

# Add license headers
Expand Down

0 comments on commit 281b5d1

Please sign in to comment.