@@ -103,6 +103,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
103103def _create_whl_repos (module_ctx , pip_attr , whl_map , whl_overrides , group_map , simpleapi_cache ):
104104 logger = repo_utils .logger (module_ctx )
105105 python_interpreter_target = pip_attr .python_interpreter_target
106+ is_hub_reproducible = True
106107
107108 # if we do not have the python_interpreter set in the attributes
108109 # we programmatically find it.
@@ -240,7 +241,7 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
240241 )
241242 whl_library_args .update ({k : v for k , (v , default ) in maybe_args_with_default .items () if v == default })
242243
243- if pip_attr . experimental_index_url :
244+ if get_index_urls :
244245 # TODO @aignas 2024-05-26: move to a separate function
245246 found_something = False
246247 for requirement in requirements :
@@ -250,6 +251,8 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
250251 continue
251252
252253 found_something = True
254+ is_hub_reproducible = False
255+
253256 if pip_attr .netrc :
254257 whl_library_args ["netrc" ] = pip_attr .netrc
255258 if pip_attr .auth_patterns :
@@ -300,7 +303,7 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
300303 # packages they want to download, in that case there will be always
301304 # a requirement here, so we will not be in this code branch.
302305 continue
303- elif pip_attr . experimental_index_url :
306+ elif get_index_urls :
304307 logger .warn (lambda : "falling back to pip for installing the right file for {}" .format (requirement .requirement_line ))
305308
306309 whl_library_args ["requirement" ] = requirement .requirement_line
@@ -318,6 +321,8 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
318321 ),
319322 )
320323
324+ return is_hub_reproducible
325+
321326def _pip_impl (module_ctx ):
322327 """Implementation of a class tag that creates the pip hub and corresponding pip spoke whl repositories.
323328
@@ -427,6 +432,7 @@ def _pip_impl(module_ctx):
427432 hub_group_map = {}
428433
429434 simpleapi_cache = {}
435+ is_extension_reproducible = True
430436
431437 for mod in module_ctx .modules :
432438 for pip_attr in mod .tags .parse :
@@ -463,7 +469,8 @@ def _pip_impl(module_ctx):
463469 else :
464470 pip_hub_map [pip_attr .hub_name ].python_versions .append (pip_attr .python_version )
465471
466- _create_whl_repos (module_ctx , pip_attr , hub_whl_map , whl_overrides , hub_group_map , simpleapi_cache )
472+ is_hub_reproducible = _create_whl_repos (module_ctx , pip_attr , hub_whl_map , whl_overrides , hub_group_map , simpleapi_cache )
473+ is_extension_reproducible = is_extension_reproducible and is_hub_reproducible
467474
468475 for hub_name , whl_map in hub_whl_map .items ():
469476 pip_repository (
@@ -477,6 +484,20 @@ def _pip_impl(module_ctx):
477484 groups = hub_group_map .get (hub_name ),
478485 )
479486
487+ if bazel_features .external_deps .extension_metadata_has_reproducible :
488+ return module_ctx .extension_metadata (reproducible = is_extension_reproducible )
489+ else :
490+ return None
491+
492+ def _pip_non_reproducible (module_ctx ):
493+ _pip_impl (module_ctx )
494+
495+ if bazel_features .external_deps .extension_metadata_has_reproducible :
496+ # We allow for calling the PyPI index and that will go into the MODULE.bazel.lock file
497+ return module_ctx .extension_metadata (reproducible = False )
498+ else :
499+ return None
500+
480501def _pip_parse_ext_attrs ():
481502 attrs = dict ({
482503 "experimental_extra_index_urls" : attr .string_list (
@@ -676,17 +697,6 @@ Apply any overrides (e.g. patches) to a given Python distribution defined by
676697other tags in this extension.""" ,
677698)
678699
679- def _extension_extra_args ():
680- args = {}
681-
682- if bazel_features .external_deps .module_extension_has_os_arch_dependent :
683- args = args | {
684- "arch_dependent" : True ,
685- "os_dependent" : True ,
686- }
687-
688- return args
689-
690700pip = module_extension (
691701 doc = """\
692702 This extension is used to make dependencies from pip available.
@@ -729,7 +739,54 @@ extension.
729739""" ,
730740 ),
731741 },
732- ** _extension_extra_args ()
742+ )
743+
744+ pip_internal = module_extension (
745+ doc = """\
746+ This extension is used to make dependencies from pypi available.
747+
748+ For now this is intended to be used internally so that usage of the `pip`
749+ extension in `rules_python` does not affect the evaluations of the extension
750+ for the consumers.
751+
752+ pip.parse:
753+ To use, call `pip.parse()` and specify `hub_name` and your requirements file.
754+ Dependencies will be downloaded and made available in a repo named after the
755+ `hub_name` argument.
756+
757+ Each `pip.parse()` call configures a particular Python version. Multiple calls
758+ can be made to configure different Python versions, and will be grouped by
759+ the `hub_name` argument. This allows the same logical name, e.g. `@pypi//numpy`
760+ to automatically resolve to different, Python version-specific, libraries.
761+
762+ pip.whl_mods:
763+ This tag class is used to help create JSON files to describe modifications to
764+ the BUILD files for wheels.
765+ """ ,
766+ implementation = _pip_non_reproducible ,
767+ tag_classes = {
768+ "override" : _override_tag ,
769+ "parse" : tag_class (
770+ attrs = _pip_parse_ext_attrs (),
771+ doc = """\
772+ This tag class is used to create a pypi hub and all of the spokes that are part of that hub.
773+ This tag class reuses most of the pypi attributes that are found in
774+ @rules_python//python/pip_install:pip_repository.bzl.
775+ The exception is it does not use the arg 'repo_prefix'. We set the repository
776+ prefix for the user and the alias arg is always True in bzlmod.
777+ """ ,
778+ ),
779+ "whl_mods" : tag_class (
780+ attrs = _whl_mod_attrs (),
781+ doc = """\
782+ This tag class is used to create JSON file that are used when calling wheel_builder.py. These
783+ JSON files contain instructions on how to modify a wheel's project. Each of the attributes
784+ create different modifications based on the type of attribute. Previously to bzlmod these
785+ JSON files where referred to as annotations, and were renamed to whl_modifications in this
786+ extension.
787+ """ ,
788+ ),
789+ },
733790)
734791
735792def _whl_mods_repo_impl (rctx ):
0 commit comments