Skip to content

Commit e0f9d9e

Browse files
Google APIscopybara-github
authored andcommitted
Integrate Python GAPIC Microgenerator in googleapis.
This PR uses using documentai as an example. Depends on googleapis/gapic-generator-python#402 PiperOrigin-RevId: 309824146
1 parent 4ca990c commit e0f9d9e

5 files changed

Lines changed: 57 additions & 40 deletions

File tree

.kokoro/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ source .kokoro/setup.sh
1010
#
1111
# Run build and tests
1212
#
13-
${BAZEL} --output_user_root=${BAZEL_ROOT} build --keep_going //...
14-
${BAZEL} --output_user_root=${BAZEL_ROOT} test --flaky_test_attempts=3 --keep_going //...
13+
${BAZEL} --output_user_root=${BAZEL_ROOT} build --keep_going //... ${EXTRA_BUILD_FAGS}
14+
${BAZEL} --output_user_root=${BAZEL_ROOT} test --flaky_test_attempts=3 --keep_going //... ${EXTRA_BUILD_FAGS}

.kokoro/setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ chmod +x bazel
1212
mkdir bazel_root
1313
cd -
1414

15+
# gapic-generator-python requires python 3.6+
16+
pyenv global 3.6.1
17+
1518
BAZEL=${KOKORO_ROOT}/tools/bazel
1619
BAZEL_ROOT=${KOKORO_ROOT}/tools/bazel_root
20+
EXTRA_BUILD_FAGS="--extra_toolchains=@gapic_generator_python//:pyenv3_toolchain --define=gapic_gen_python=3.6"

WORKSPACE

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ http_archive(
3131
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/0.9.0/bazel_skylib-0.9.0.tar.gz"],
3232
)
3333

34+
# Python rules should go early in the dependencies list, otherwise a wrong
35+
# version of the library will be selected as a transitive dependency of gRPC.
36+
http_archive(
37+
name = "rules_python",
38+
url = "https://github.com/bazelbuild/rules_python/archive/748aa53d7701e71101dfd15d800e100f6ff8e5d1.zip",
39+
strip_prefix = "rules_python-748aa53d7701e71101dfd15d800e100f6ff8e5d1"
40+
)
41+
3442
http_archive(
3543
name = "com_google_protobuf",
3644
strip_prefix = "protobuf-fe1790ca0df67173702f70d5646b82f48f412b99", # this is 3.11.2
@@ -192,6 +200,32 @@ protoc_docs_plugin_repositories()
192200

193201
protoc_docs_plugin_register_toolchains()
194202

203+
load("@rules_python//python:repositories.bzl", "py_repositories")
204+
py_repositories()
205+
206+
load("@rules_python//python:pip.bzl", "pip_repositories")
207+
pip_repositories()
208+
209+
# Change upstream repository once PR is merged
210+
http_archive(
211+
name = "gapic_generator_python",
212+
urls = ["https://github.com/googleapis/gapic-generator-python/archive/d18ed416240a064fffac0fd7915b61f6415fe140.zip"],
213+
strip_prefix = "gapic-generator-python-d18ed416240a064fffac0fd7915b61f6415fe140",
214+
)
215+
216+
load("@gapic_generator_python//:repositories.bzl",
217+
"gapic_generator_python",
218+
"gapic_generator_register_toolchains"
219+
)
220+
221+
gapic_generator_python()
222+
223+
gapic_generator_register_toolchains()
224+
225+
load("@gapic_generator_python_pip_deps//:requirements.bzl", "pip_install")
226+
227+
pip_install()
228+
195229
##############################################################################
196230
# Go
197231
##############################################################################

google/cloud/documentai/v1beta2/BUILD.bazel

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -150,60 +150,29 @@ go_gapic_assembly_pkg(
150150
##############################################################################
151151
# Python
152152
##############################################################################
153+
# This library is using Python microgenerator.
154+
# DO NOT OVERRIDE this Python section with autogenerated rules.
153155
load(
154156
"@com_google_googleapis_imports//:imports.bzl",
155-
"moved_proto_library",
156-
"py_gapic_assembly_pkg",
157-
"py_gapic_library",
158-
"py_grpc_library",
159-
"py_proto_library",
157+
py_gapic_assembly_pkg = "py_gapic_assembly_pkg2",
158+
py_gapic_library = "py_gapic_library2",
160159
)
161160

162-
moved_proto_library(
163-
name = "documentai_moved_proto",
161+
py_gapic_library(
162+
name = "documentai_py_gapic2",
164163
srcs = [":documentai_proto"],
165-
deps = [
166-
"//google/api:annotations_proto",
167-
"//google/api:client_proto",
168-
"//google/api:field_behavior_proto",
169-
"//google/longrunning:operations_proto",
170-
"//google/rpc:status_proto",
171-
"//google/type:color_proto",
172-
"@com_google_protobuf//:timestamp_proto",
173-
],
174164
)
175165

176-
py_proto_library(
177-
name = "documentai_py_proto",
178-
plugin = "@protoc_docs_plugin//:docs_plugin",
179-
deps = [":documentai_moved_proto"],
180-
)
181-
182-
py_grpc_library(
183-
name = "documentai_py_grpc",
184-
srcs = [":documentai_moved_proto"],
185-
deps = [":documentai_py_proto"],
186-
)
187166

188167
py_gapic_library(
189168
name = "documentai_py_gapic",
190-
src = ":documentai_proto_with_info",
191-
gapic_yaml = "documentai_gapic.yaml",
192-
package = "google.cloud.documentai.v1beta2",
193-
service_yaml = "documentai_v1beta2.yaml",
194-
deps = [
195-
":documentai_py_grpc",
196-
":documentai_py_proto",
197-
],
169+
srcs = [":documentai_proto"],
198170
)
199171

200-
# Open Source Packages
201172
py_gapic_assembly_pkg(
202173
name = "documentai-v1beta2-py",
203174
deps = [
204175
":documentai_py_gapic",
205-
":documentai_py_grpc",
206-
":documentai_py_proto",
207176
],
208177
)
209178

repository_rules.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ def switched_rules_by_language(
170170
python and grpc and gapic,
171171
"@com_google_api_codegen//rules_gapic/python:py_gapic_pkg.bzl",
172172
)
173+
rules["py_gapic_library2"] = _switch(
174+
python and grpc and gapic,
175+
"@gapic_generator_python//rules_python_gapic:py_gapic.bzl",
176+
"py_gapic_library",
177+
)
178+
rules["py_gapic_assembly_pkg2"] = _switch(
179+
python and grpc and gapic,
180+
"@gapic_generator_python//rules_python_gapic:py_gapic_pkg.bzl",
181+
"py_gapic_assembly_pkg",
182+
)
173183

174184
#
175185
# Go

0 commit comments

Comments
 (0)