@@ -2,7 +2,6 @@ load("//:repositories.bzl", "all_requirements")
22
33DEFAULT_REPOSITORY_NAME = "pip"
44
5-
65def _pip_repository_impl (rctx ):
76 python_interpreter = rctx .attr .python_interpreter
87 if rctx .attr .python_interpreter_target != None :
@@ -25,33 +24,34 @@ def _pip_repository_impl(rctx):
2524 ]
2625 pypath = ":" .join ([str (p ) for p in [rules_root ] + thirdparty_roots ])
2726
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+
2837 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 = {
3940 # Manually construct the PYTHONPATH since we cannot use the toolchain here
40- "PYTHONPATH" : pypath
41+ "PYTHONPATH" : pypath ,
4142 },
42- timeout = rctx .attr .timeout ,
43+ timeout = rctx .attr .timeout ,
4344 )
4445 if result .return_code :
4546 fail ("rules_python_external failed: %s (%s)" % (result .stdout , result .stderr ))
4647
4748 return
4849
49-
5050pip_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 ),
5353 "wheel_env" : attr .string_dict (),
54- "python_interpreter" : attr .string (default = "python3" ),
54+ "python_interpreter" : attr .string (default = "python3" ),
5555 "python_interpreter_target" : attr .label (allow_single_file = True , doc = """
5656If you are using a custom python interpreter built by another repository rule,
5757use this attribute to specify its BUILD target. This allows pip_repository to invoke
@@ -61,11 +61,12 @@ python_interpreter.
6161 # 600 is documented as default here: https://docs.bazel.build/versions/master/skylark/lib/repository_ctx.html#execute
6262 "timeout" : attr .int (default = 600 ),
6363 },
64- implementation = _pip_repository_impl ,
64+ implementation = _pip_repository_impl ,
6565)
6666
67-
68- def pip_install (requirements , name = DEFAULT_REPOSITORY_NAME , ** kwargs ):
67+ def pip_install (requirements , name = DEFAULT_REPOSITORY_NAME , ** kwargs ):
6968 pip_repository (
70- name = name , requirements = requirements , ** kwargs
69+ name = name ,
70+ requirements = requirements ,
71+ ** kwargs
7172 )
0 commit comments