This repository was archived by the owner on Mar 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
feat: Initial draft of GAPIC Bazel Extensions gapic-generator-python #342
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement") | ||
|
|
||
| py_binary( | ||
| name = "gapic_generator_python", | ||
| srcs = glob(["gapic/**/*.py"]), | ||
| data = glob(["gapic/**/*.j2"]), | ||
| main = "gapic/cli/generate.py", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "@com_google_protobuf//:protobuf_python", | ||
| requirement("click"), | ||
| requirement("google-api-core"), | ||
| requirement("googleapis-common-protos"), | ||
| requirement("grpcio"), | ||
| requirement("protobuf"), | ||
| requirement("jinja2"), | ||
| requirement("pypandoc"), | ||
| requirement("PyYAML"), | ||
| ], | ||
| python_version = "PY3", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| workspace(name = "gapic_generator_python") | ||
|
|
||
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
| http_archive( | ||
| name = "rules_python", | ||
| url = "https://github.com/bazelbuild/rules_python/archive/748aa53d7701e71101dfd15d800e100f6ff8e5d1.zip", | ||
| strip_prefix = "rules_python-748aa53d7701e71101dfd15d800e100f6ff8e5d1" | ||
| ) | ||
| load("@rules_python//python:repositories.bzl", "py_repositories") | ||
| py_repositories() | ||
|
|
||
| # Only needed if using the packaging rules. | ||
| load("@rules_python//python:pip.bzl", "pip_repositories") | ||
| pip_repositories() | ||
|
|
||
|
|
||
|
|
||
| load("@rules_python//python:pip.bzl", "pip_import") | ||
|
|
||
| pip_import( # or pip3_import | ||
| name = "gapic_generator_python_pip_deps", | ||
| requirements = "@gapic_generator_python//:requirements.txt", | ||
| python_interpreter = "python3", | ||
| ) | ||
|
|
||
| load("@gapic_generator_python_pip_deps//:requirements.bzl", "pip_install") | ||
| pip_install() | ||
|
|
||
| local_repository( | ||
| name = "com_google_api_codegen", | ||
| path = "/usr/local/google/home/vam/_/projects/github/vam-google/gapic-generator", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| load("@rules_python//python:pip.bzl", "pip_import") | ||
|
|
||
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
|
||
| def com_google_protoc_java_resource_names_plugin_repositories(): | ||
| _protobuf_version = "3.11.2" | ||
| _protobuf_version_in_link = "v%s" % _protobuf_version | ||
| _maybe( | ||
| http_archive, | ||
| name = "com_google_protobuf", | ||
| urls = ["https://github.com/protocolbuffers/protobuf/archive/%s.zip" % _protobuf_version_in_link], | ||
| strip_prefix = "protobuf-%s" % _protobuf_version, | ||
| ) | ||
|
|
||
| _maybe( | ||
| http_archive, | ||
| name = "bazel_skylib", | ||
| sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d", | ||
| strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b", | ||
| urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"], | ||
| ) | ||
|
|
||
|
|
||
| pip_import( | ||
| name = "examples_helloworld", | ||
| requirements = "@rules_python//examples/helloworld:requirements.txt", | ||
| ) | ||
|
|
||
|
|
||
| def _maybe(repo_rule, name, strip_repo_prefix = "", **kwargs): | ||
| if not name.startswith(strip_repo_prefix): | ||
| return | ||
| repo_name = name[len(strip_repo_prefix):] | ||
| if repo_name in native.existing_rules(): | ||
| return | ||
| repo_rule(name = repo_name, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| click >= 6.7 | ||
| google-api-core >= 1.14.3 | ||
| googleapis-common-protos >= 1.6.0 | ||
| grpcio >= 1.24.3 | ||
| jinja2 >= 2.10 | ||
| protobuf >= 3.7.1 | ||
| pypandoc >= 1.4 | ||
| PyYAML >= 5.1.1 |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| load("@com_google_api_codegen//rules_gapic:gapic.bzl", "proto_custom_library") | ||
|
|
||
| def py_gapic_library2(name, srcs, **kwargs): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we pass custom options through **kwargs? Is it straightforward?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes we can, we can also always add those custom options explicitly as args in this rule. It is straightforward to do (I did not add any because of my lack of knowledge and context here).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent. We will try using kwargs first and see if explicit args are necessary. |
||
| # srcjar_target_name = "%s_srcjar" % name | ||
| srcjar_target_name = name | ||
| srcjar_output_suffix = ".srcjar" | ||
|
|
||
| proto_custom_library( | ||
| name = srcjar_target_name, | ||
| deps = srcs, | ||
| plugin = Label("@gapic_generator_python//:gapic_generator_python"), | ||
| plugin_args = [], | ||
| plugin_file_args = {}, | ||
| output_type = "python_gapic", | ||
| output_suffix = srcjar_output_suffix, | ||
| **kwargs | ||
| ) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way we can be more specific about the python version requirement? Some of the code in the generator requires features from >=3.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are ways to be more specific, but they have their own issues (i.e. make the build less hermetic and less portable). Practically speaking, it should be picking the latest installed version of python on the host machine, and if there is 3.6+ bazel will pick it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Good to know.