@@ -24,6 +24,24 @@ def _construct_pypath(rctx):
24
24
pypath = separator .join ([str (p ) for p in [rules_root ] + thirdparty_roots ])
25
25
return pypath
26
26
27
+ def _resolve_python_interpreter (rctx ):
28
+ """Helper function to find the python interpreter from the common attributes
29
+
30
+ Args:
31
+ rctx: Handle to the rule repository context.
32
+ Returns: Python interpreter path.
33
+ """
34
+ python_interpreter = rctx .attr .python_interpreter
35
+ if rctx .attr .python_interpreter_target != None :
36
+ target = rctx .attr .python_interpreter_target
37
+ python_interpreter = rctx .path (target )
38
+ else :
39
+ if "/" not in python_interpreter :
40
+ python_interpreter = rctx .which (python_interpreter )
41
+ if not python_interpreter :
42
+ fail ("python interpreter not found" )
43
+ return python_interpreter
44
+
27
45
def _parse_optional_attrs (rctx , args ):
28
46
"""Helper function to parse common attributes of pip_repository and whl_library repository rules.
29
47
@@ -83,15 +101,7 @@ exports_files(["requirements.bzl"])
83
101
"""
84
102
85
103
def _pip_repository_impl (rctx ):
86
- python_interpreter = rctx .attr .python_interpreter
87
- if rctx .attr .python_interpreter_target != None :
88
- target = rctx .attr .python_interpreter_target
89
- python_interpreter = rctx .path (target )
90
- else :
91
- if "/" not in python_interpreter :
92
- python_interpreter = rctx .which (python_interpreter )
93
- if not python_interpreter :
94
- fail ("python interpreter not found" )
104
+ python_interpreter = _resolve_python_interpreter (rctx )
95
105
96
106
if rctx .attr .incremental and not rctx .attr .requirements_lock :
97
107
fail ("Incremental mode requires a requirements_lock attribute be specified." )
@@ -114,6 +124,11 @@ def _pip_repository_impl(rctx):
114
124
"--timeout" ,
115
125
str (rctx .attr .timeout ),
116
126
]
127
+
128
+ if rctx .attr .python_interpreter :
129
+ args += ["--python_interpreter" , rctx .attr .python_interpreter ]
130
+ if rctx .attr .python_interpreter_target :
131
+ args += ["--python_interpreter_target" , str (rctx .attr .python_interpreter_target )]
117
132
else :
118
133
args = [
119
134
python_interpreter ,
@@ -266,10 +281,12 @@ py_binary(
266
281
)
267
282
268
283
def _impl_whl_library (rctx ):
284
+ python_interpreter = _resolve_python_interpreter (rctx )
285
+
269
286
# pointer to parent repo so these rules rerun if the definitions in requirements.bzl change.
270
287
_parent_repo_label = Label ("@{parent}//:requirements.bzl" .format (parent = rctx .attr .repo ))
271
288
args = [
272
- rctx . attr . python_interpreter ,
289
+ python_interpreter ,
273
290
"-m" ,
274
291
"python.pip_install.parse_requirements_to_bzl.extract_single_wheel" ,
275
292
"--requirement" ,
0 commit comments