@@ -2,7 +2,6 @@ load("//:repositories.bzl", "all_requirements")
2
2
3
3
DEFAULT_REPOSITORY_NAME = "pip"
4
4
5
-
6
5
def _pip_repository_impl (rctx ):
7
6
python_interpreter = rctx .attr .python_interpreter
8
7
if rctx .attr .python_interpreter_target != None :
@@ -25,33 +24,34 @@ def _pip_repository_impl(rctx):
25
24
]
26
25
pypath = ":" .join ([str (p ) for p in [rules_root ] + thirdparty_roots ])
27
26
27
+ args = [
28
+ python_interpreter ,
29
+ "-m" ,
30
+ "extract_wheels" ,
31
+ "--requirements" ,
32
+ rctx .path (rctx .attr .requirements ),
33
+ "--repo" ,
34
+ "@%s" % rctx .attr .name ,
35
+ ]
36
+
28
37
result = rctx .execute (
29
- [
30
- python_interpreter ,
31
- "-m" ,
32
- "extract_wheels" ,
33
- "--requirements" ,
34
- rctx .path (rctx .attr .requirements ),
35
- "--repo" ,
36
- "@%s" % rctx .attr .name ,
37
- ],
38
- environment = {
38
+ args ,
39
+ environment = {
39
40
# Manually construct the PYTHONPATH since we cannot use the toolchain here
40
- "PYTHONPATH" : pypath
41
+ "PYTHONPATH" : pypath ,
41
42
},
42
- timeout = rctx .attr .timeout ,
43
+ timeout = rctx .attr .timeout ,
43
44
)
44
45
if result .return_code :
45
46
fail ("rules_python_external failed: %s (%s)" % (result .stdout , result .stderr ))
46
47
47
48
return
48
49
49
-
50
50
pip_repository = repository_rule (
51
- attrs = {
52
- "requirements" : attr .label (allow_single_file = True , mandatory = True , ),
51
+ attrs = {
52
+ "requirements" : attr .label (allow_single_file = True , mandatory = True ),
53
53
"wheel_env" : attr .string_dict (),
54
- "python_interpreter" : attr .string (default = "python3" ),
54
+ "python_interpreter" : attr .string (default = "python3" ),
55
55
"python_interpreter_target" : attr .label (allow_single_file = True , doc = """
56
56
If you are using a custom python interpreter built by another repository rule,
57
57
use this attribute to specify its BUILD target. This allows pip_repository to invoke
@@ -61,11 +61,12 @@ python_interpreter.
61
61
# 600 is documented as default here: https://docs.bazel.build/versions/master/skylark/lib/repository_ctx.html#execute
62
62
"timeout" : attr .int (default = 600 ),
63
63
},
64
- implementation = _pip_repository_impl ,
64
+ implementation = _pip_repository_impl ,
65
65
)
66
66
67
-
68
- def pip_install (requirements , name = DEFAULT_REPOSITORY_NAME , ** kwargs ):
67
+ def pip_install (requirements , name = DEFAULT_REPOSITORY_NAME , ** kwargs ):
69
68
pip_repository (
70
- name = name , requirements = requirements , ** kwargs
69
+ name = name ,
70
+ requirements = requirements ,
71
+ ** kwargs
71
72
)
0 commit comments