Skip to content

Commit 344a698

Browse files
Merge pull request #4 from dillon-giacoppo/DEPLOY-445-prefix-packages
2 parents b5d058d + 3ca9487 commit 344a698

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ boto3==1.9.253
1212

1313
In `WORKSPACE`
1414
```
15-
rules_python_external_version = "37dad8910495ad71bae391db7a843a0f7a3ea902"
15+
rules_python_external_version = "{COMMIT_SHA}"
1616
1717
git_repository(
1818
name = "rules_python_external",
@@ -32,14 +32,13 @@ pip_repository(
3232

3333
In `BUILD`
3434
```
35+
load("@py_deps//:requirements.bzl", "requirement")
36+
3537
py_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.

src/extract_wheels.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@
2424

2525

2626
def 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

3040
def extract_wheel(whl, directory, extras):
@@ -90,7 +100,7 @@ def main():
90100
91101
def 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
)

0 commit comments

Comments
 (0)