@@ -24,6 +24,24 @@ def _construct_pypath(rctx):
2424 pypath = separator .join ([str (p ) for p in [rules_root ] + thirdparty_roots ])
2525 return pypath
2626
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+
2745def _parse_optional_attrs (rctx , args ):
2846 """Helper function to parse common attributes of pip_repository and whl_library repository rules.
2947
@@ -83,15 +101,7 @@ exports_files(["requirements.bzl"])
83101"""
84102
85103def _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 )
95105
96106 if rctx .attr .incremental and not rctx .attr .requirements_lock :
97107 fail ("Incremental mode requires a requirements_lock attribute be specified." )
@@ -114,6 +124,11 @@ def _pip_repository_impl(rctx):
114124 "--timeout" ,
115125 str (rctx .attr .timeout ),
116126 ]
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 )]
117132 else :
118133 args = [
119134 python_interpreter ,
@@ -266,10 +281,12 @@ py_binary(
266281)
267282
268283def _impl_whl_library (rctx ):
284+ python_interpreter = _resolve_python_interpreter (rctx )
285+
269286 # pointer to parent repo so these rules rerun if the definitions in requirements.bzl change.
270287 _parent_repo_label = Label ("@{parent}//:requirements.bzl" .format (parent = rctx .attr .repo ))
271288 args = [
272- rctx . attr . python_interpreter ,
289+ python_interpreter ,
273290 "-m" ,
274291 "python.pip_install.parse_requirements_to_bzl.extract_single_wheel" ,
275292 "--requirement" ,
0 commit comments