Skip to content

Commit

Permalink
feat: Initial draft of GAPIC Bazel Extensions gapic-generator-python (#…
Browse files Browse the repository at this point in the history
…342)

Initial draft of GAPIC Bazel Extensions gapic-generator-python
  • Loading branch information
vam-google authored Mar 16, 2020
1 parent e3c178c commit cc7ab0b
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 0 deletions.
20 changes: 20 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement")

py_binary(
name = "gapic_plugin",
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("jinja2"),
requirement("pypandoc"),
requirement("PyYAML"),
],
python_version = "PY3",
)
35 changes: 35 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
workspace(name = "gapic_generator_python")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

#
# Import rules_python
#
http_archive(
name = "rules_python",
strip_prefix = "rules_python-748aa53d7701e71101dfd15d800e100f6ff8e5d1",
url = "https://github.com/bazelbuild/rules_python/archive/748aa53d7701e71101dfd15d800e100f6ff8e5d1.zip",
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

load("@rules_python//python:pip.bzl", "pip_repositories")

pip_repositories()

#
# Import gapic-generator-python specific dependencies
#
load("//:repositories.bzl", "gapic_generator_python")

gapic_generator_python()

load("@gapic_generator_python_pip_deps//:requirements.bzl", "pip_install")

pip_install()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
41 changes: 41 additions & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@rules_python//python:pip.bzl", "pip_import")

def gapic_generator_python():
_maybe(
pip_import,
name = "gapic_generator_python_pip_deps",
python_interpreter = "python3",
requirements = "@gapic_generator_python//:requirements.txt",
)

_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",
strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
)

_maybe(
http_archive,
name = "com_google_api_codegen",
strip_prefix = "gapic-generator-b32c73219d617f90de70bfa6ff0ea0b0dd638dfe",
urls = ["https://github.com/googleapis/gapic-generator/archive/b32c73219d617f90de70bfa6ff0ea0b0dd638dfe.zip"],
)

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.
31 changes: 31 additions & 0 deletions rules_python_gapic/py_gapic.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@com_google_api_codegen//rules_gapic:gapic.bzl", "proto_custom_library")

def py_gapic_library(name, srcs, **kwargs):
# 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_plugin"),
plugin_args = [],
plugin_file_args = {},
output_type = "python_gapic",
output_suffix = srcjar_output_suffix,
**kwargs
)

0 comments on commit cc7ab0b

Please sign in to comment.