Skip to content

Commit ecefb3b

Browse files
apply PR comments
1 parent 0aaa43b commit ecefb3b

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

README.md

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

1313
In `WORKSPACE`
1414

15-
```
15+
```python
1616
rules_python_external_version = "{COMMIT_SHA}"
1717

1818
http_archive(
@@ -28,14 +28,14 @@ rules_python_external_dependencies()
2828

2929
load("@rules_python_external//:defs.bzl", "pip_install")
3030
pip_install(
31-
name = "py_deps"
31+
name = "py_deps",
3232
requirements = "//:requirements.txt",
3333
)
3434
```
3535

3636
Example `BUILD` file.
3737

38-
```
38+
```python
3939
load("@py_deps//:requirements.bzl", "requirement")
4040

4141
py_binary(

defs.bzl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ def _pip_repository_impl(rctx):
99

1010
rctx.file("BUILD", "")
1111

12+
# Get the root directory of these rules
13+
rules_root = rctx.path(Label("//:BUILD")).dirname
14+
thirdparty_roots = [
15+
# Includes all the external dependencies from repositories.bzl
16+
rctx.path(Label("@" + repo + "//:BUILD.bazel")).dirname
17+
for repo in all_requirements
18+
]
19+
pypath = ":".join([str(p) for p in [rules_root] + thirdparty_roots])
20+
1221
result = rctx.execute(
1322
[
1423
rctx.which(rctx.attr.python_interpreter),
@@ -20,14 +29,7 @@ def _pip_repository_impl(rctx):
2029
],
2130
environment={
2231
# Manually construct the PYTHONPATH since we cannot use the toolchain here
23-
"PYTHONPATH": ":".join(
24-
# Includes the root of this repo and all the external dependencies from repositories.bzl
25-
[str(rctx.path(rctx.attr._script).dirname.dirname)]
26-
+ [
27-
str(rctx.path(Label("@" + repo + "//:BUILD.bazel")).dirname)
28-
for repo in all_requirements
29-
]
30-
)
32+
"PYTHONPATH": pypath
3133
},
3234
)
3335
if result.return_code:

0 commit comments

Comments
 (0)