Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions BUILD.bazel
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",
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Good to know.

)
32 changes: 32 additions & 0 deletions WORKSPACE
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",
)
36 changes: 36 additions & 0 deletions repositories.bzl
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)
8 changes: 8 additions & 0 deletions requirements.txt
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 added rules_python_gapic/BUILD.bazel
Empty file.
18 changes: 18 additions & 0 deletions rules_python_gapic/py_gapic.bzl
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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass custom options through **kwargs? Is it straightforward?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
)