Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make GAPIC Bazel rules production ready #402

Merged
merged 8 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
34 changes: 30 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("//:gapic_generator_python.bzl", "pandoc_binary", "pandoc_toolchain")
load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement")
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")

toolchain_type(
name = "pandoc_toolchain_type",
Expand All @@ -23,14 +24,37 @@ pandoc_toolchain(
)

pandoc_binary(
name = "pandoc_binary"
name = "pandoc_binary",
)

config_setting(
name = "gapic_gen_python_3_6",
values = {"define": "gapic_gen_python=3.6"},
)

py_runtime(
name = "pyenv3_runtime",
interpreter = ":pyenv3wrapper.sh",
software-dov marked this conversation as resolved.
Show resolved Hide resolved
python_version="PY3",
)

py_runtime_pair(
name = "pyenv3_runtime_pair",
py3_runtime = ":pyenv3_runtime",
)

toolchain(
name = "pyenv3_toolchain",
toolchain = ":pyenv3_runtime_pair",
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)

py_binary(
name = "gapic_plugin",
srcs = glob(["gapic/**/*.py"]),
data = [":pandoc_binary"] + glob(["gapic/**/*.j2"]),
main = "gapic/cli/generate_with_pandoc.py",
python_version = "PY3",
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:protobuf_python",
Expand All @@ -42,6 +66,8 @@ py_binary(
requirement("MarkupSafe"),
requirement("pypandoc"),
requirement("PyYAML"),
],
python_version = "PY3",
)
] + select({
":gapic_gen_python_3_6": [requirement("dataclasses")],
"//conditions:default": [],
}),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: no newline

2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protobuf_deps()

#
# Import grpc as a native bazel dependency. This avoids duplication and also
# spedds up loading phase a lot (otherwise python_rules will be building grpcio
# speeds up loading phase a lot (otherwise python_rules will be building grpcio
# from sources in a single-core speed, which takes around 5 minutes on a regular
# workstation)
#
Expand Down
1 change: 1 addition & 0 deletions gapic/cli/generate_with_pandoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
if __name__ == '__main__':
os.environ['PYPANDOC_PANDOC'] = os.path.join(
os.path.abspath(__file__).rsplit("gapic", 1)[0], "pandoc")
os.environ['LC_ALL'] = 'C.UTF-8'
generate.generate()
4 changes: 4 additions & 0 deletions pyenv3wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

HOME_DIR=$(getent passwd "$(whoami)" | cut -d: -f6)
software-dov marked this conversation as resolved.
Show resolved Hide resolved
exec "$HOME_DIR/.pyenv/shims/python3" "$@"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ MarkupSafe==1.1.1
protobuf==3.11.3
pypandoc==1.5
PyYAML==5.3.1
dataclasses==0.6