Skip to content

Commit 9d2c5a5

Browse files
authored
feat: Initial draft of GAPIC Bazel Extensions gapic-generator-python (#342)
Initial draft of GAPIC Bazel Extensions gapic-generator-python
1 parent a6451bb commit 9d2c5a5

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement")
2+
3+
py_binary(
4+
name = "gapic_plugin",
5+
srcs = glob(["gapic/**/*.py"]),
6+
data = glob(["gapic/**/*.j2"]),
7+
main = "gapic/cli/generate.py",
8+
visibility = ["//visibility:public"],
9+
deps = [
10+
"@com_google_protobuf//:protobuf_python",
11+
requirement("click"),
12+
requirement("google-api-core"),
13+
requirement("googleapis-common-protos"),
14+
requirement("grpcio"),
15+
requirement("jinja2"),
16+
requirement("pypandoc"),
17+
requirement("PyYAML"),
18+
],
19+
python_version = "PY3",
20+
)

packages/gapic-generator/WORKSPACE

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
workspace(name = "gapic_generator_python")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
#
6+
# Import rules_python
7+
#
8+
http_archive(
9+
name = "rules_python",
10+
strip_prefix = "rules_python-748aa53d7701e71101dfd15d800e100f6ff8e5d1",
11+
url = "https://github.com/bazelbuild/rules_python/archive/748aa53d7701e71101dfd15d800e100f6ff8e5d1.zip",
12+
)
13+
14+
load("@rules_python//python:repositories.bzl", "py_repositories")
15+
16+
py_repositories()
17+
18+
load("@rules_python//python:pip.bzl", "pip_repositories")
19+
20+
pip_repositories()
21+
22+
#
23+
# Import gapic-generator-python specific dependencies
24+
#
25+
load("//:repositories.bzl", "gapic_generator_python")
26+
27+
gapic_generator_python()
28+
29+
load("@gapic_generator_python_pip_deps//:requirements.bzl", "pip_install")
30+
31+
pip_install()
32+
33+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
34+
35+
protobuf_deps()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("@rules_python//python:pip.bzl", "pip_import")
3+
4+
def gapic_generator_python():
5+
_maybe(
6+
pip_import,
7+
name = "gapic_generator_python_pip_deps",
8+
python_interpreter = "python3",
9+
requirements = "@gapic_generator_python//:requirements.txt",
10+
)
11+
12+
_protobuf_version = "3.11.2"
13+
_protobuf_version_in_link = "v%s" % _protobuf_version
14+
_maybe(
15+
http_archive,
16+
name = "com_google_protobuf",
17+
urls = ["https://github.com/protocolbuffers/protobuf/archive/%s.zip" % _protobuf_version_in_link],
18+
strip_prefix = "protobuf-%s" % _protobuf_version,
19+
)
20+
21+
_maybe(
22+
http_archive,
23+
name = "bazel_skylib",
24+
strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
25+
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
26+
)
27+
28+
_maybe(
29+
http_archive,
30+
name = "com_google_api_codegen",
31+
strip_prefix = "gapic-generator-b32c73219d617f90de70bfa6ff0ea0b0dd638dfe",
32+
urls = ["https://github.com/googleapis/gapic-generator/archive/b32c73219d617f90de70bfa6ff0ea0b0dd638dfe.zip"],
33+
)
34+
35+
def _maybe(repo_rule, name, strip_repo_prefix = "", **kwargs):
36+
if not name.startswith(strip_repo_prefix):
37+
return
38+
repo_name = name[len(strip_repo_prefix):]
39+
if repo_name in native.existing_rules():
40+
return
41+
repo_rule(name = repo_name, **kwargs)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
click >= 6.7
2+
google-api-core >= 1.14.3
3+
googleapis-common-protos >= 1.6.0
4+
grpcio >= 1.24.3
5+
jinja2 >= 2.10
6+
protobuf >= 3.7.1
7+
pypandoc >= 1.4
8+
PyYAML >= 5.1.1

packages/gapic-generator/rules_python_gapic/BUILD.bazel

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@com_google_api_codegen//rules_gapic:gapic.bzl", "proto_custom_library")
16+
17+
def py_gapic_library(name, srcs, **kwargs):
18+
# srcjar_target_name = "%s_srcjar" % name
19+
srcjar_target_name = name
20+
srcjar_output_suffix = ".srcjar"
21+
22+
proto_custom_library(
23+
name = srcjar_target_name,
24+
deps = srcs,
25+
plugin = Label("@gapic_generator_python//:gapic_plugin"),
26+
plugin_args = [],
27+
plugin_file_args = {},
28+
output_type = "python_gapic",
29+
output_suffix = srcjar_output_suffix,
30+
**kwargs
31+
)

0 commit comments

Comments
 (0)