Skip to content

Commit 7b2c8c2

Browse files
committed
Separate py_grpc_library and py_proto_library.
By popular demand, we'll now be offering separate py_grpc_library and py_proto_library targets sharing the same interface as within google3. This change necessitated some modifications to how we pull in our own Python-level dependencies and how we make those available to those pulling in our project via Bazel. There is now a grpc_python_deps() Bazel workspace rule that pulls in the appropriate dependencies, which should be called from the client project's WORKSPACE file. A test has been added to the bazel/test/ directory to verify that this behavior works as intended. It's worth noting that the protobuf repository's usage of Starlark bind() caused a great deal of trouble in ensuring that we could also pull in six. This change also required a change in the way generated proto code is imported in the channelz and health-check modules, as well as in their associated tests. We were importing them two different ways, each relative. This resulted in two different module objects being imported into the process, which were incompatible. I am not sure exactly what caused this behavior to begin, as this should have been possible before this PR. As a workaround, I am simply trying two different absolute imports and using the one that works. This should function both inside and outside of Bazel environments.
1 parent 74b981a commit 7b2c8c2

File tree

39 files changed

+571
-204
lines changed

39 files changed

+571
-204
lines changed

WORKSPACE

+16-27
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,6 @@ register_toolchains(
1818
"//third_party/toolchains/bazel_0.23.2_rbe_windows:cc-toolchain-x64_windows",
1919
)
2020

21-
git_repository(
22-
name = "io_bazel_rules_python",
23-
commit = "fdbb17a4118a1728d19e638a5291b4c4266ea5b8",
24-
remote = "https://github.com/bazelbuild/rules_python.git",
25-
)
26-
27-
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories", "pip_import")
28-
29-
pip_import(
30-
name = "grpc_python_dependencies",
31-
requirements = "//:requirements.bazel.txt",
32-
)
33-
34-
http_archive(
35-
name = "cython",
36-
build_file = "//third_party:cython.BUILD",
37-
sha256 = "d68138a2381afbdd0876c3cb2a22389043fa01c4badede1228ee073032b07a27",
38-
strip_prefix = "cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c",
39-
urls = [
40-
"https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
41-
],
42-
)
43-
44-
load("//bazel:grpc_python_deps.bzl", "grpc_python_deps")
45-
46-
grpc_python_deps()
47-
4821
load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
4922

5023
# Create toolchain configuration for remote execution.
@@ -65,3 +38,19 @@ rbe_autoconfig(
6538
},
6639
),
6740
)
41+
42+
load("@com_github_grpc_grpc//bazel:grpc_python_deps.bzl", "grpc_python_deps")
43+
grpc_python_deps()
44+
45+
46+
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories", "pip_import")
47+
48+
pip_import(
49+
name = "grpc_python_dependencies",
50+
requirements = "@com_github_grpc_grpc//:requirements.bazel.txt",
51+
)
52+
53+
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories")
54+
load("@grpc_python_dependencies//:requirements.bzl", "pip_install")
55+
pip_repositories()
56+
pip_install()

bazel/grpc_python_deps.bzl

+64-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,67 @@
1-
load("//third_party/py:python_configure.bzl", "python_configure")
2-
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories")
3-
load("@grpc_python_dependencies//:requirements.bzl", "pip_install")
1+
"""Load dependencies needed to compile and test the grpc python library as a 3rd-party consumer."""
2+
3+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
4+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5+
load("@com_github_grpc_grpc//third_party/py:python_configure.bzl", "python_configure")
46

57
def grpc_python_deps():
8+
native.bind(
9+
name = "six",
10+
actual = "@six_archive//:six",
11+
)
12+
13+
# protobuf binds to the name "six", so we can't use it here.
14+
# See https://github.com/bazelbuild/bazel/issues/1952 for why bind is
15+
# horrible.
16+
if "six_archive" not in native.existing_rules():
17+
http_archive(
18+
name = "six_archive",
19+
strip_prefix = "six-1.12.0",
20+
build_file = "@com_github_grpc_grpc//third_party:six.BUILD",
21+
sha256 = "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73",
22+
urls = ["https://files.pythonhosted.org/packages/dd/bf/4138e7bfb757de47d1f4b6994648ec67a51efe58fa907c1e11e350cddfca/six-1.12.0.tar.gz"],
23+
)
24+
25+
if "enum34" not in native.existing_rules():
26+
http_archive(
27+
name = "enum34",
28+
build_file = "@com_github_grpc_grpc//third_party:enum34.BUILD",
29+
strip_prefix = "enum34-1.1.6",
30+
sha256 = "8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1",
31+
urls = ["https://files.pythonhosted.org/packages/bf/3e/31d502c25302814a7c2f1d3959d2a3b3f78e509002ba91aea64993936876/enum34-1.1.6.tar.gz"],
32+
)
33+
34+
if "futures" not in native.existing_rules():
35+
http_archive(
36+
name = "futures",
37+
build_file = "@com_github_grpc_grpc//third_party:futures.BUILD",
38+
strip_prefix = "futures-3.3.0",
39+
sha256 = "7e033af76a5e35f58e56da7a91e687706faf4e7bdfb2cbc3f2cca6b9bcda9794",
40+
urls = ["https://files.pythonhosted.org/packages/47/04/5fc6c74ad114032cd2c544c575bffc17582295e9cd6a851d6026ab4b2c00/futures-3.3.0.tar.gz"],
41+
)
42+
43+
if "io_bazel_rules_python" not in native.existing_rules():
44+
git_repository(
45+
name = "io_bazel_rules_python",
46+
commit = "fdbb17a4118a1728d19e638a5291b4c4266ea5b8",
47+
remote = "https://github.com/bazelbuild/rules_python.git",
48+
)
49+
650
python_configure(name = "local_config_python")
7-
pip_repositories()
8-
pip_install()
51+
52+
native.bind(
53+
name = "python_headers",
54+
actual = "@local_config_python//:python_headers",
55+
)
56+
57+
if "cython" not in native.existing_rules():
58+
http_archive(
59+
name = "cython",
60+
build_file = "@com_github_grpc_grpc//third_party:cython.BUILD",
61+
sha256 = "d68138a2381afbdd0876c3cb2a22389043fa01c4badede1228ee073032b07a27",
62+
strip_prefix = "cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c",
63+
urls = [
64+
"https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
65+
],
66+
)
67+

0 commit comments

Comments
 (0)