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

bazel: Bump rules_python version to 0.1.0 #15236

Merged
merged 9 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion DEPENDENCY_POLICY.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Dependency declarations must:
be used if no CPE for the project is available in the CPE database. CPEs should be _versionless_
with a `:*` suffix, since the version can be computed from `version`.

When build or test code references Python modules, they should be imported via `pip3_import` in
When build or test code references Python modules, they should be specified via `pip_install` in
[bazel/repositories_extra.bzl](bazel/repositories_extra.bzl). Python modules should not be listed in
`repository_locations.bzl` entries. `requirements.txt` files for Python dependencies must pin to
exact versions, e.g. `PyYAML==5.3.1` and ideally also include a [SHA256
Expand Down
9 changes: 3 additions & 6 deletions bazel/EXTERNAL_DEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,13 @@ to binaries, libraries, headers, etc.

# Adding external dependencies to Envoy (Python)

Python dependencies should be added via `pip3` and `rules_python`. The process
Python dependencies should be added via `pip` and `rules_python`. The process
is:

1. Define a `pip3_import()` pointing at your target `requirements.txt` in
1. Define a `pip_install()` pointing at your target `requirements.txt` in
[`bazel/repositories_extra.bzl`](repositories_extra.bzl)

2. Add a `pip_install()` invocation in
[`bazel/dependency_imports.bzl`](dependency_imports.bzl).

3. Add a `requirements("<package name")` in the `BUILD` file that depends on
2. Add a `requirements("<package name")` in the `BUILD` file that depends on
this package.

You can use [`tools/config_validation/BUILD`](../tools/config_validation/BUILD) as an example
Expand Down
15 changes: 0 additions & 15 deletions bazel/dependency_imports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependenci
load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
load("@upb//bazel:workspace_deps.bzl", "upb_deps")
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
load("@config_validation_pip3//:requirements.bzl", config_validation_pip_install = "pip_install")
load("@configs_pip3//:requirements.bzl", configs_pip_install = "pip_install")
load("@headersplit_pip3//:requirements.bzl", headersplit_pip_install = "pip_install")
load("@kafka_pip3//:requirements.bzl", kafka_pip_install = "pip_install")
load("@protodoc_pip3//:requirements.bzl", protodoc_pip_install = "pip_install")
load("@thrift_pip3//:requirements.bzl", thrift_pip_install = "pip_install")
load("@fuzzing_pip3//:requirements.bzl", fuzzing_pip_install = "pip_install")
load("@rules_antlr//antlr:deps.bzl", "antlr_dependencies")
load("@proxy_wasm_rust_sdk//bazel:dependencies.bzl", "proxy_wasm_rust_sdk_dependencies")

Expand Down Expand Up @@ -81,11 +74,3 @@ def envoy_dependency_imports(go_version = GO_VERSION):
sum = "h1:ux/56T2xqZO/3cP1I2F86qpeoYPCOzk+KF/UH/Ar+lk=",
version = "v0.0.0-20180726023541-3605ed457bf7",
)

config_validation_pip_install()
configs_pip_install()
headersplit_pip_install()
kafka_pip_install()
protodoc_pip_install()
thrift_pip_install()
fuzzing_pip_install()
7 changes: 6 additions & 1 deletion bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,12 @@ def _com_google_absl():
)

def _com_google_protobuf():
external_http_archive("rules_python")
external_http_archive(
name = "rules_python",
patches = ["@envoy//bazel:rules_python.patch"],
phlax marked this conversation as resolved.
Show resolved Hide resolved
patch_args = ["-p1"],
)

external_http_archive(
"com_google_protobuf",
patches = ["@envoy//bazel:protobuf.patch"],
Expand Down
17 changes: 8 additions & 9 deletions bazel/repositories_extra.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
load("@rules_python//python:repositories.bzl", "py_repositories")
load("@rules_python//python:pip.bzl", "pip3_import", "pip_repositories")
load("@rules_python//python:pip.bzl", "pip_install")
load("@proxy_wasm_cpp_host//bazel/cargo:crates.bzl", "proxy_wasm_cpp_host_fetch_remote_crates")

# Python dependencies.
def _python_deps():
py_repositories()
pip_repositories()

pip3_import(
pip_install(
name = "config_validation_pip3",
requirements = "@envoy//tools/config_validation:requirements.txt",
extra_pip_args = ["--require-hashes"],
Expand All @@ -19,7 +18,7 @@ def _python_deps():
# use_category = ["devtools"],
# cpe = "cpe:2.3:a:pyyaml:pyyaml:*",
)
pip3_import(
pip_install(
name = "configs_pip3",
requirements = "@envoy//configs:requirements.txt",
extra_pip_args = ["--require-hashes"],
Expand All @@ -37,7 +36,7 @@ def _python_deps():
# release_date = "2019-02-23"
# use_category = ["test"],
)
pip3_import(
pip_install(
name = "kafka_pip3",
requirements = "@envoy//source/extensions/filters/network/kafka:requirements.txt",
extra_pip_args = ["--require-hashes"],
Expand All @@ -55,7 +54,7 @@ def _python_deps():
# release_date = "2019-02-23"
# use_category = ["test"],
)
pip3_import(
pip_install(
name = "headersplit_pip3",
requirements = "@envoy//tools/envoy_headersplit:requirements.txt",
extra_pip_args = ["--require-hashes"],
Expand All @@ -67,7 +66,7 @@ def _python_deps():
# use_category = ["devtools"],
# cpe = "cpe:2.3:a:llvm:clang:*",
)
pip3_import(
pip_install(
name = "protodoc_pip3",
requirements = "@envoy//tools/protodoc:requirements.txt",
extra_pip_args = ["--require-hashes"],
Expand All @@ -79,7 +78,7 @@ def _python_deps():
# use_category = ["docs"],
# cpe = "cpe:2.3:a:pyyaml:pyyaml:*",
)
pip3_import(
pip_install(
name = "thrift_pip3",
requirements = "@envoy//test/extensions/filters/network/thrift_proxy:requirements.txt",
extra_pip_args = ["--require-hashes"],
Expand All @@ -97,7 +96,7 @@ def _python_deps():
# release_date = "2020-05-21"
# use_category = ["test"],
)
pip3_import(
pip_install(
name = "fuzzing_pip3",
requirements = "@rules_fuzzing//fuzzing:requirements.txt",
extra_pip_args = ["--require-hashes"],
Expand Down
7 changes: 3 additions & 4 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,11 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_name = "Python rules for Bazel",
project_desc = "Bazel rules for the Python language",
project_url = "https://github.com/bazelbuild/rules_python",
# TODO(htuch): revert back to a point releases when pip3_import appears.
version = "a0fbf98d4e3a232144df4d0d80b577c7a693b570",
sha256 = "76a8fd4e7eca2a3590f816958faa0d83c9b2ce9c32634c5c375bcccf161d3bb5",
version = "0.1.0",
sha256 = "48f7e716f4098b85296ad93f5a133baf712968c13fbc2fdf3a6136158fe86eac",
strip_prefix = "rules_python-{version}",
urls = ["https://github.com/bazelbuild/rules_python/archive/{version}.tar.gz"],
release_date = "2020-04-09",
release_date = "2020-10-15",
phlax marked this conversation as resolved.
Show resolved Hide resolved
use_category = ["build"],
),
six = dict(
Expand Down
15 changes: 15 additions & 0 deletions bazel/rules_python.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/python/pip_install/repositories.bzl b/python/pip_install/repositories.bzl
index df63674..80824e4 100644
--- a/python/pip_install/repositories.bzl
+++ b/python/pip_install/repositories.bzl
@@ -16,8 +16,8 @@ _RULE_DEPS = [
),
(
"pypi__setuptools",
- "https://files.pythonhosted.org/packages/54/28/c45d8b54c1339f9644b87663945e54a8503cfef59cf0f65b3ff5dd17cf64/setuptools-42.0.2-py2.py3-none-any.whl",
- "c8abd0f3574bc23afd2f6fd2c415ba7d9e097c8a99b845473b0d957ba1e2dac6",
+ "https://files.pythonhosted.org/packages/3d/f2/1489d3b6c72d68bf79cd0fba6b6c7497df4ebf7d40970e2d7eceb8d0ea9c/setuptools-51.0.0-py3-none-any.whl",
phlax marked this conversation as resolved.
Show resolved Hide resolved
+ "8c177936215945c9a37ef809ada0fab365191952f7a123618432bbfac353c529",
),
(
"pypi__wheel",
2 changes: 1 addition & 1 deletion tools/dependency/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def TestOnlyIgnore(dep):
if dep.startswith('remotejdk'):
return True
# Python (pip3)
if '_pip3_' in dep:
if '_pip3' in dep:
htuch marked this conversation as resolved.
Show resolved Hide resolved
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion tools/dependency/validate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_invalid_build_graph_structure(self):
def test_valid_test_only_deps(self):
validator = self.BuildValidator({'a': FakeDep('dataplane_core')}, {'//source/...': ['a']})
validator.ValidateTestOnlyDeps()
validator = self.BuildValidator({'a': FakeDep('test_only')}, {'//test/...': ['a', 'b__pip3_']})
validator = self.BuildValidator({'a': FakeDep('test_only')}, {'//test/...': ['a', 'b__pip3']})
validator.ValidateTestOnlyDeps()

def test_invalid_test_only_deps(self):
Expand Down