Skip to content

Commit 8c6703d

Browse files
authored
chore(migration): Migrate code from googleapis/gapic-generator-python into packages/gapic-generator (#16183)
See #14907. This PR should be merged with a merge-commit, not a squash-commit, in order to preserve the git history.
2 parents 76a8b58 + e3731d5 commit 8c6703d

File tree

1,029 files changed

+359401
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,029 files changed

+359401
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: Gapic Generator Specialized Tests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'packages/gapic-generator/**'
7+
- '.github/workflows/gapic-generator-tests.yml'
8+
push:
9+
branches: [main]
10+
paths:
11+
- 'packages/gapic-generator/**'
12+
13+
concurrency:
14+
group: gapic-gen-${{ github.head_ref || github.run_id }}
15+
cancel-in-progress: true
16+
17+
env:
18+
SHOWCASE_VERSION: 0.35.0
19+
PROTOC_VERSION: 3.20.2
20+
LATEST_STABLE_PYTHON: 3.14
21+
ALL_PYTHON: "['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']"
22+
23+
jobs:
24+
check_changes:
25+
# We use a job-level 'if' with dorny/paths-filter because GitHub's top-level
26+
# 'on: pull_request: paths' can be bypassed during repository-wide migrations
27+
# or structural changes. This ensures these specialized (and heavy) matrix
28+
# jobs stay silent on PRs that do not touch the generator.
29+
runs-on: ubuntu-latest
30+
outputs:
31+
run_generator: ${{ steps.filter.outputs.generator }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: dorny/paths-filter@v3
35+
id: filter
36+
with:
37+
filters: |
38+
generator:
39+
- 'packages/gapic-generator/**'
40+
- '.github/workflows/gapic-generator-tests.yml'
41+
42+
# Preserve the workaround for env variables in matrix
43+
python_config:
44+
needs: check_changes
45+
if: ${{ needs.check_changes.outputs.run_generator == 'true' }}
46+
runs-on: ubuntu-latest
47+
outputs:
48+
all_python: ${{ env.ALL_PYTHON }}
49+
latest_stable_python: ${{ env.LATEST_STABLE_PYTHON }}
50+
steps:
51+
- run: echo "Initializing config for gapic-generator"
52+
53+
showcase-unit:
54+
needs: python_config
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
python: ${{ fromJSON(needs.python_config.outputs.all_python) }}
59+
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
60+
logging_scope: ["", "google"]
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v5
64+
- name: Set up Python
65+
uses: actions/setup-python@v6
66+
with:
67+
python-version: "${{ matrix.python }}"
68+
- name: Install System Deps & Protoc
69+
run: |
70+
sudo apt-get update && sudo apt-get install -y curl pandoc unzip
71+
sudo mkdir -p /usr/src/protoc/ && sudo chown -R ${USER} /usr/src/
72+
curl --location https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip --output /usr/src/protoc/protoc.zip
73+
cd /usr/src/protoc/ && unzip protoc.zip
74+
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
75+
- name: Run Nox
76+
env:
77+
GOOGLE_SDK_PYTHON_LOGGING_SCOPE: ${{ matrix.logging_scope }}
78+
run: |
79+
pip install nox
80+
cd packages/gapic-generator
81+
nox -s showcase_unit${{ matrix.variant }}-${{ matrix.python }}
82+
83+
showcase-mypy:
84+
needs: python_config
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v5
88+
- name: Set up Python
89+
uses: actions/setup-python@v6
90+
with:
91+
python-version: ${{ needs.python_config.outputs.latest_stable_python }}
92+
- name: Install System Deps
93+
run: sudo apt-get update && sudo apt-get install -y pandoc
94+
- name: Run Mypy
95+
run: |
96+
pip install nox
97+
cd packages/gapic-generator
98+
nox -s showcase_mypy
99+
100+
goldens:
101+
needs: python_config
102+
runs-on: ubuntu-latest
103+
steps:
104+
- uses: actions/checkout@v5
105+
- name: Set up Python
106+
uses: actions/setup-python@v6
107+
with:
108+
python-version: ${{ needs.python_config.outputs.latest_stable_python }}
109+
- name: Install System Deps
110+
run: sudo apt-get update && sudo apt-get install -y pandoc
111+
- name: Run Goldens
112+
run: |
113+
pip install nox
114+
cd packages/gapic-generator
115+
for pkg in credentials eventarc logging redis; do
116+
nox -f tests/integration/goldens/$pkg/noxfile.py -s format lint unit-${{ needs.python_config.outputs.latest_stable_python }}
117+
done
118+
119+
goldens-prerelease:
120+
needs: python_config
121+
runs-on: ubuntu-latest
122+
steps:
123+
- uses: actions/checkout@v5
124+
- name: Set up Python
125+
uses: actions/setup-python@v6
126+
with:
127+
python-version: ${{ needs.python_config.outputs.latest_stable_python }}
128+
- name: Install System Deps
129+
run: sudo apt-get update && sudo apt-get install -y pandoc
130+
- name: Run Goldens (Prerelease)
131+
run: |
132+
pip install nox
133+
cd packages/gapic-generator
134+
for pkg in credentials eventarc logging redis; do
135+
nox -f tests/integration/goldens/$pkg/noxfile.py -s core_deps_from_source prerelease_deps
136+
done
137+
138+
fragment-snippet:
139+
needs: python_config
140+
strategy:
141+
matrix:
142+
python: ["3.10", "3.14"]
143+
runs-on: ubuntu-latest
144+
steps:
145+
- uses: actions/checkout@v5
146+
- name: Set up Python
147+
uses: actions/setup-python@v6
148+
with:
149+
python-version: ${{ matrix.python }}
150+
# This fixes the Pandoc error
151+
- name: Install System Deps & Protoc
152+
run: |
153+
sudo apt-get update && sudo apt-get install -y curl pandoc unzip
154+
sudo mkdir -p /usr/src/protoc/ && sudo chown -R ${USER} /usr/src/
155+
curl --location https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip --output /usr/src/protoc/protoc.zip
156+
cd /usr/src/protoc/ && unzip protoc.zip
157+
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
158+
- name: Run Tests
159+
run: |
160+
pip install nox
161+
cd packages/gapic-generator
162+
# Run fragment for current matrix python
163+
nox -s fragment-${{ matrix.python }}
164+
# Run snippetgen only on the latest stable to avoid the "Python not found" error
165+
if [ "${{ matrix.python }}" == "${{ needs.python_config.outputs.latest_stable_python }}" ]; then
166+
nox -s snippetgen
167+
fi

.librarian/state.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4220,3 +4220,12 @@ libraries:
42204220
preserve_regex: []
42214221
remove_regex: []
42224222
tag_format: '{id}-v{version}'
4223+
- id: gapic-generator
4224+
version: 1.30.13
4225+
last_generated_commit: ""
4226+
apis: []
4227+
source_roots:
4228+
- packages/gapic-generator
4229+
preserve_regex: []
4230+
remove_regex: []
4231+
tag_format: '{id}-v{version}'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# See https://github.com/bazelbuild/bazelisk
2+
USE_BAZEL_VERSION=6.5.0

packages/gapic-generator/.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# New protobuf requires C++17
2+
build --repo_env=BAZEL_CXXOPTS="-std=c++17"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[run]
2+
branch = True
3+
omit =
4+
gapic/cli/*.py
5+
*_pb2.py
6+
7+
[report]
8+
fail_under = 100
9+
show_missing = True
10+
exclude_lines =
11+
# Re-enable the standard pragma
12+
pragma: NO COVER
13+
# Enable an English version.
14+
Impossible; skip coverage checks.
15+
# Ignore debug-only repr
16+
def __repr__
17+
# Abstract methods by definition are not invoked
18+
@abstractmethod
19+
@abc.abstractmethod
20+

packages/gapic-generator/.flake8

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[flake8]
2+
ignore =
3+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): E123, E124
4+
# Closing bracket mismatches opening bracket's line.
5+
# This works poorly with type annotations in method declarations.
6+
E123, E124
7+
# Line over-indented for visual indent.
8+
# This works poorly with type annotations in method declarations.
9+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): E126, E128, E131
10+
E126, E128, E131
11+
# Line break after binary operator.
12+
# This catches line breaks after "and" / "or" as a means of breaking up
13+
# long if statements, which PEP 8 explicitly encourages.
14+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): W504
15+
W504
16+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): E203
17+
E203
18+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): E501
19+
E501
20+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): E712
21+
E712
22+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): E711
23+
E711
24+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): E722
25+
E722
26+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): E741
27+
E741
28+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): F401
29+
F401
30+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): F541
31+
F541
32+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): F841
33+
F841
34+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): F811
35+
F811
36+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): W503
37+
W503
38+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): W291
39+
W291
40+
exclude =
41+
# Exclude golden files
42+
tests/integration
43+
# Exclude generated protobuf code
44+
*_pb2.py
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "gapic-generator",
3+
"name_pretty": "Google API Client Generator for Python",
4+
"client_documentation": "https://gapic-generator-python.readthedocs.io/en/stable/",
5+
"product_documentation": "",
6+
"issue_tracker": "https://github.com/googleapis/google-cloud-python/issues",
7+
"release_level": "stable",
8+
"language": "python",
9+
"library_type": "CORE",
10+
"repo": "googleapis/google-cloud-python",
11+
"distribution_name": "gapic-generator",
12+
"default_version": "",
13+
"codeowner_team": "@googleapis/cloud-sdk-python-team"
14+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
load("//:gapic_generator_python.bzl", "pandoc_binary", "pandoc_toolchain")
2+
load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement")
3+
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
4+
5+
toolchain_type(
6+
name = "pandoc_toolchain_type",
7+
visibility = ["//visibility:public"],
8+
)
9+
10+
pandoc_toolchain(
11+
exec_compatible_with = [
12+
"@platforms//os:linux",
13+
"@platforms//cpu:arm64",
14+
],
15+
platform = "linux_arm_64",
16+
)
17+
18+
pandoc_toolchain(
19+
exec_compatible_with = [
20+
"@platforms//os:linux",
21+
"@platforms//cpu:x86_64",
22+
],
23+
platform = "linux_x86_64",
24+
)
25+
26+
pandoc_toolchain(
27+
exec_compatible_with = [
28+
"@platforms//os:osx",
29+
"@platforms//cpu:arm64",
30+
],
31+
platform = "macOS_arm_64",
32+
)
33+
34+
pandoc_toolchain(
35+
exec_compatible_with = [
36+
"@platforms//os:osx",
37+
"@platforms//cpu:x86_64",
38+
],
39+
platform = "macOS_x86_64",
40+
)
41+
42+
pandoc_toolchain(
43+
exec_compatible_with = [
44+
"@platforms//os:windows",
45+
"@platforms//cpu:x86_64",
46+
],
47+
platform = "windows_x86_64",
48+
)
49+
50+
pandoc_binary(
51+
name = "pandoc_binary",
52+
)
53+
54+
py_runtime(
55+
name = "pyenv3_runtime",
56+
interpreter = ":pyenv3wrapper.sh",
57+
python_version = "PY3",
58+
)
59+
60+
py_runtime_pair(
61+
name = "pyenv3_runtime_pair",
62+
py3_runtime = ":pyenv3_runtime",
63+
)
64+
65+
toolchain(
66+
name = "pyenv3_toolchain",
67+
toolchain = ":pyenv3_runtime_pair",
68+
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
69+
)
70+
71+
py_binary(
72+
name = "gapic_plugin",
73+
srcs = glob(["gapic/**/*.py"]),
74+
data = [":pandoc_binary"] + glob([
75+
"gapic/**/*.j2",
76+
"gapic/**/.*.j2",
77+
]),
78+
main = "gapic/cli/generate_with_pandoc.py",
79+
python_version = "PY3",
80+
visibility = ["//visibility:public"],
81+
deps = [
82+
"@com_github_grpc_grpc//src/python/grpcio/grpc:grpcio",
83+
requirement("protobuf"),
84+
requirement("click"),
85+
requirement("google-api-core"),
86+
requirement("googleapis-common-protos"),
87+
requirement("jinja2"),
88+
requirement("MarkupSafe"),
89+
requirement("pypandoc"),
90+
requirement("PyYAML"),
91+
requirement("grpc-google-iam-v1"),
92+
],
93+
)

0 commit comments

Comments
 (0)