Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit cdff356

Browse files
chore: remove pb2 file generation during post processing step (#266)
* chore: remove pb2 file generation during post processing --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 9a50722 commit cdff356

File tree

3 files changed

+0
-125
lines changed

3 files changed

+0
-125
lines changed

google/longrunning/operations_pb2_grpc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Copyright 2020 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");

noxfile.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222

2323
BLACK_VERSION = "black==22.3.0"
2424

25-
# `grpcio-tools` 1.59.0 or newer is required for protobuf 5.x compatibility.
26-
GRPCIO_TOOLS_VERSION = "grpcio-tools==1.59.0"
27-
2825
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
2926
UNIT_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
3027

@@ -261,59 +258,3 @@ def tests_local(session, protobuf_implementation):
261258
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
262259
},
263260
)
264-
265-
266-
@nox.session(python="3.8")
267-
def generate_protos(session):
268-
"""Generates the protos using protoc.
269-
270-
This session but be last to avoid overwriting the protos used in CI runs.
271-
272-
Some notes on the `google` directory:
273-
1. The `_pb2.py` files are produced by protoc.
274-
2. The .proto files are non-functional but are left in the repository
275-
to make it easier to understand diffs.
276-
3. The `google` directory also has `__init__.py` files to create proper modules.
277-
If a new subdirectory is added, you will need to create more `__init__.py`
278-
files.
279-
"""
280-
# longrunning operations directory is non-standard for backwards compatibility
281-
# see comments in directory for details
282-
# Temporarily rename the operations_pb2.py to keep it from getting overwritten
283-
os.replace(
284-
"google/longrunning/operations_pb2.py",
285-
"google/longrunning/operations_pb2-COPY.py",
286-
)
287-
288-
session.install(GRPCIO_TOOLS_VERSION)
289-
protos = [str(p) for p in (Path(".").glob("google/**/*.proto"))]
290-
session.run(
291-
"python", "-m", "grpc_tools.protoc", "--proto_path=.", "--python_out=.", *protos
292-
)
293-
294-
# Some files contain service definitions for which `_pb2_grpc.py` files must be generated.
295-
service_protos = ["google/longrunning/operations.proto"]
296-
session.run(
297-
"python",
298-
"-m",
299-
"grpc_tools.protoc",
300-
"--proto_path=.",
301-
"--grpc_python_out=.",
302-
*service_protos,
303-
)
304-
305-
# More LRO non-standard fixes: rename the file and fix the import statement
306-
operations_grpc_py = Path("google/longrunning/operations_pb2_grpc.py")
307-
file_contents = operations_grpc_py.read_text()
308-
file_contents = file_contents.replace("operations_pb2", "operations_proto_pb2")
309-
operations_grpc_py.write_text(file_contents)
310-
311-
# Clean up LRO directory
312-
os.replace(
313-
"google/longrunning/operations_pb2.py",
314-
"google/longrunning/operations_proto_pb2.py",
315-
)
316-
os.replace(
317-
"google/longrunning/operations_pb2-COPY.py",
318-
"google/longrunning/operations_pb2.py",
319-
)

owlbot.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,9 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import os
15-
import subprocess
16-
import shutil
17-
18-
1914
import synthtool as s
2015
import synthtool.gcp as gcp
2116
from synthtool.languages import python
22-
from synthtool.sources import git
23-
24-
GOOGLEAPIS_REPO = "googleapis/googleapis"
25-
26-
# ----------------------------------------------------------------------------
27-
# Get gapic metadata proto from googleapis
28-
# ----------------------------------------------------------------------------
29-
30-
# Clean up googleapis
31-
shutil.rmtree('googleapis', ignore_errors=True)
32-
33-
# Clone googleapis
34-
googleapis_url = git.make_repo_clone_url(GOOGLEAPIS_REPO)
35-
subprocess.run(["git", "clone", googleapis_url])
36-
37-
# This is required in order for s.copy() to work
38-
s._tracked_paths.add("googleapis")
39-
40-
# Gapic metadata proto needed by gapic-generator-python
41-
# Desired import is "from google.gapic.metadata import gapic_metadata_pb2"
42-
s.copy("googleapis/gapic", "google/gapic", excludes=["lang/", "packaging/", "**/BUILD.bazel"],)
43-
44-
s.copy("googleapis/google/api/*.proto", "google/api")
45-
s.copy("googleapis/google/cloud/extended_operations.proto", "google/cloud")
46-
s.copy("googleapis/google/cloud/location/locations.proto", "google/cloud/location")
47-
s.copy("googleapis/google/logging/type/*.proto", "google/logging/type")
48-
s.copy("googleapis/google/longrunning/*.proto", "google/longrunning")
49-
s.copy("googleapis/google/rpc/*.proto", "google/rpc")
50-
s.copy("googleapis/google/rpc/context/*.proto", "google/rpc/context")
51-
s.copy("googleapis/google/type/*.proto", "google/type")
52-
53-
# Clean up googleapis
54-
shutil.rmtree('googleapis')
5517

5618
# ----------------------------------------------------------------------------
5719
# Add templated files
@@ -66,34 +28,7 @@
6628
s.move(templated_files / "renovate.json")
6729
s.move(templated_files / ".github", excludes=["workflows"])
6830

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

7433
# Add license headers
7534
python.fix_pb2_headers()
76-
77-
LICENSE = """
78-
# Copyright 2020 Google LLC
79-
#
80-
# Licensed under the Apache License, Version 2.0 (the "License");
81-
# you may not use this file except in compliance with the License.
82-
# You may obtain a copy of the License at
83-
#
84-
# http://www.apache.org/licenses/LICENSE-2.0
85-
#
86-
# Unless required by applicable law or agreed to in writing, software
87-
# distributed under the License is distributed on an "AS IS" BASIS,
88-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
89-
# See the License for the specific language governing permissions and
90-
# limitations under the License."""
91-
92-
PB2_GRPC_HEADER = r"""(\# Generated by the gRPC Python protocol compiler plugin\. DO NOT EDIT!$)
93-
(.*?$)"""
94-
95-
s.replace(
96-
"**/*_pb2_grpc.py",
97-
PB2_GRPC_HEADER,
98-
fr"{LICENSE}\n\n\g<1>\n\n\g<2>", # add line breaks to avoid stacking replacements
99-
)

0 commit comments

Comments
 (0)