|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | -import os |
15 | | -import subprocess |
16 | | -import shutil |
17 | | - |
18 | | - |
19 | 14 | import synthtool as s |
20 | 15 | import synthtool.gcp as gcp |
21 | 16 | 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') |
55 | 17 |
|
56 | 18 | # ---------------------------------------------------------------------------- |
57 | 19 | # Add templated files |
|
66 | 28 | s.move(templated_files / "renovate.json") |
67 | 29 | s.move(templated_files / ".github", excludes=["workflows"]) |
68 | 30 |
|
69 | | -# Generate _pb2.py files and format them |
70 | | -s.shell.run(["nox", "-s", "generate_protos"], hide_output=False) |
71 | | - |
72 | 31 | s.shell.run(["nox", "-s", "blacken"], hide_output=False) |
73 | 32 |
|
74 | 33 | # Add license headers |
75 | 34 | 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