File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed
Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ boto3==1.9.253
1212
1313In ` WORKSPACE `
1414```
15- rules_python_external_version = "37dad8910495ad71bae391db7a843a0f7a3ea902 "
15+ rules_python_external_version = "{COMMIT_SHA} "
1616
1717git_repository(
1818 name = "rules_python_external",
@@ -32,14 +32,13 @@ pip_repository(
3232
3333In ` BUILD `
3434```
35+ load("@py_deps//:requirements.bzl", "requirement")
36+
3537py_binary(
3638 name = "main",
3739 srcs = ["main.py"],
3840 deps = [
39- " @py_deps//boto3",
41+ requirement("boto3"), # or @py_deps//pypi__boto3
4042 ],
4143)
4244```
43-
44- N.B package names are sanitized to ` {package_name}.replace("-", "_").replace(".", "_").lower() ` . You can use the macro
45- provided in ` load("@py_deps//:requirements.bzl", "requirement") ` to automatically transform the name.
Original file line number Diff line number Diff line change 2424
2525
2626def sanitise_name (name ):
27- return name .replace ("-" , "_" ).replace ("." , "_" ).lower ()
27+ """
28+ There are certain requirements around Bazel labels that we need to consider.
29+
30+ rules-python automatically adds the repository root to the PYTHONPATH, meaning a package that has the same name as
31+ a module is picked up. We workaround this by prefixing with `pypi__`. Alternatively we could require
32+ `--noexperimental_python_import_all_repositories` be set, however this breaks rules_docker.
33+ See: https://github.com/bazelbuild/bazel/issues/2636
34+
35+ Due to restrictions on Bazel labels we also cannot allow hyphens. See https://github.com/bazelbuild/bazel/issues/6841
36+ """
37+ return "pypi__" + name .replace ("-" , "_" ).replace ("." , "_" ).lower ()
2838
2939
3040def extract_wheel (whl , directory , extras ):
@@ -90,7 +100,7 @@ def main():
90100
91101def requirement(name):
92102 name_key = name.replace("-", "_").replace(".", "_").lower()
93- return "{repo}//" + name_key
103+ return "{repo}//pypi__ " + name_key
94104""" .format (
95105 requirement_labels = "," .join (targets ), repo = args .repo
96106 )
You can’t perform that action at this time.
0 commit comments