@@ -73,35 +73,15 @@ def _create_whl_repos(
7373 * ,
7474 pip_attr ,
7575 whl_overrides ,
76+ evaluate_markers = None ,
7677 get_index_urls = None ):
7778 exposed_packages = {}
7879 whl_libraries = {}
7980 whl_map = {}
8081
8182 logger = repo_utils .logger (module_ctx , "pypi:create_whl_repos" )
82- python_interpreter_target = pip_attr .python_interpreter_target
8383
84- # if we do not have the python_interpreter set in the attributes
85- # we programmatically find it.
8684 hub_name = pip_attr .hub_name
87- if python_interpreter_target == None and not pip_attr .python_interpreter :
88- python_name = "python_{}_host" .format (
89- pip_attr .python_version .replace ("." , "_" ),
90- )
91- if python_name not in INTERPRETER_LABELS :
92- fail ((
93- "Unable to find interpreter for pip hub '{hub_name}' for " +
94- "python_version={version}: Make sure a corresponding " +
95- '`python.toolchain(python_version="{version}")` call exists.' +
96- "Expected to find {python_name} among registered versions:\n {labels}"
97- ).format (
98- hub_name = hub_name ,
99- version = pip_attr .python_version ,
100- python_name = python_name ,
101- labels = " \n " .join (INTERPRETER_LABELS ),
102- ))
103- python_interpreter_target = INTERPRETER_LABELS [python_name ]
104-
10585 pip_name = "{}_{}" .format (
10686 hub_name ,
10787 version_label (pip_attr .python_version ),
@@ -135,28 +115,7 @@ def _create_whl_repos(
135115 requirements_by_platform = pip_attr .requirements_by_platform ,
136116 extra_pip_args = pip_attr .extra_pip_args ,
137117 get_index_urls = get_index_urls ,
138- # NOTE @aignas 2024-08-02: , we will execute any interpreter that we find either
139- # in the PATH or if specified as a label. We will configure the env
140- # markers when evaluating the requirement lines based on the output
141- # from the `requirements_files_by_platform` which should have something
142- # similar to:
143- # {
144- # "//:requirements.txt": ["cp311_linux_x86_64", ...]
145- # }
146- #
147- # We know the target python versions that we need to evaluate the
148- # markers for and thus we don't need to use multiple python interpreter
149- # instances to perform this manipulation. This function should be executed
150- # only once by the underlying code to minimize the overhead needed to
151- # spin up a Python interpreter.
152- evaluate_markers = lambda module_ctx , requirements : evaluate_markers (
153- module_ctx ,
154- requirements = requirements ,
155- python_interpreter = pip_attr .python_interpreter ,
156- python_interpreter_target = python_interpreter_target ,
157- srcs = pip_attr .evaluate_markers_srcs ,
158- logger = logger ,
159- ),
118+ evaluate_markers = evaluate_markers ,
160119 logger = logger ,
161120 )
162121
@@ -189,7 +148,7 @@ def _create_whl_repos(
189148 group_name = group_name ,
190149 pip_data_exclude = pip_attr .pip_data_exclude ,
191150 python_interpreter = pip_attr .python_interpreter ,
192- python_interpreter_target = python_interpreter_target ,
151+ python_interpreter_target = pip_attr . python_interpreter_target ,
193152 whl_patches = {
194153 p : json .encode (args )
195154 for p , args in whl_overrides .get (whl_name , {}).items ()
@@ -467,6 +426,50 @@ You cannot use both the additive_build_content and additive_build_content_file a
467426 logger = repo_utils .logger (module_ctx , "pypi:requirements_files_by_platform" ),
468427 )
469428
429+ # if we do not have the python_interpreter set in the attributes
430+ # we programmatically find it.
431+ python_interpreter_target = pip_attr .python_interpreter_target
432+ if python_interpreter_target == None and not pip_attr .python_interpreter :
433+ python_name = "python_{}_host" .format (
434+ pip_attr .python_version .replace ("." , "_" ),
435+ )
436+ if python_name not in INTERPRETER_LABELS :
437+ fail ((
438+ "Unable to find interpreter for pip hub '{hub_name}' for " +
439+ "python_version={version}: Make sure a corresponding " +
440+ '`python.toolchain(python_version="{version}")` call exists.' +
441+ "Expected to find {python_name} among registered versions:\n {labels}"
442+ ).format (
443+ hub_name = hub_name ,
444+ version = pip_attr .python_version ,
445+ python_name = python_name ,
446+ labels = " \n " .join (INTERPRETER_LABELS ),
447+ ))
448+ python_interpreter_target = INTERPRETER_LABELS [python_name ]
449+
450+ # NOTE @aignas 2024-08-02: , we will execute any interpreter that we find either
451+ # in the PATH or if specified as a label. We will configure the env
452+ # markers when evaluating the requirement lines based on the output
453+ # from the `requirements_files_by_platform` which should have something
454+ # similar to:
455+ # {
456+ # "//:requirements.txt": ["cp311_linux_x86_64", ...]
457+ # }
458+ #
459+ # We know the target python versions that we need to evaluate the
460+ # markers for and thus we don't need to use multiple python interpreter
461+ # instances to perform this manipulation. This function should be executed
462+ # only once by the underlying code to minimize the overhead needed to
463+ # spin up a Python interpreter.
464+ evaluate_markers_fn = lambda module_ctx , requirements : evaluate_markers (
465+ module_ctx ,
466+ requirements = requirements ,
467+ python_interpreter = pip_attr .python_interpreter ,
468+ python_interpreter_target = python_interpreter_target ,
469+ srcs = pip_attr ._evaluate_markers_srcs ,
470+ logger = repo_utils .logger (module_ctx , "pypi:evaluate_markers" ),
471+ )
472+
470473 result = _create_whl_repos (
471474 module_ctx ,
472475 pip_attr = struct (
@@ -475,7 +478,6 @@ You cannot use both the additive_build_content and additive_build_content_file a
475478 enable_implicit_namespace_pkgs = pip_attr .enable_implicit_namespace_pkgs ,
476479 environment = pip_attr .environment ,
477480 envsubst = pip_attr .envsubst ,
478- evaluate_markers_srcs = pip_attr ._evaluate_markers_srcs ,
479481 experimental_requirement_cycles = pip_attr .experimental_requirement_cycles ,
480482 experimental_target_platforms = pip_attr .experimental_target_platforms ,
481483 extra_pip_args = pip_attr .extra_pip_args ,
@@ -484,14 +486,15 @@ You cannot use both the additive_build_content and additive_build_content_file a
484486 netrc = pip_attr .netrc ,
485487 pip_data_exclude = pip_attr .pip_data_exclude ,
486488 python_interpreter = pip_attr .python_interpreter ,
487- python_interpreter_target = pip_attr . python_interpreter_target ,
489+ python_interpreter_target = python_interpreter_target ,
488490 python_version = pip_attr .python_version ,
489491 quiet = pip_attr .quiet ,
490492 requirements_by_platform = requirements_by_platform ,
491493 timeout = pip_attr .timeout ,
492494 whl_modifications = pip_attr .whl_modifications ,
493495 ),
494496 whl_overrides = whl_overrides ,
497+ evaluate_markers = evaluate_markers_fn ,
495498 get_index_urls = get_index_urls ,
496499 )
497500 whl_libraries .update (result .whl_libraries )
0 commit comments