@@ -90,6 +90,7 @@ def hub_builder(
9090 # Functions to download according to the config
9191 # dict[str python_version, callable]
9292 _get_index_urls = {},
93+ _default_index_url = {},
9394 # Tells whether to use the downloader for a package.
9495 # dict[str python_version, dict[str package_name, bool use_downloader]]
9596 _use_downloader = {},
@@ -385,32 +386,33 @@ def _add_library(self, *, repos_dict, name, args):
385386 repos_dict [name ] = args
386387
387388def _set_get_index_urls (self , mctx , pip_attr ):
389+ python_version = pip_attr .python_version
390+
388391 # Resolve the index URL through envsubst so the ``$VAR`` / ``${VAR:-default}``
389392 # form is honored when deciding whether the experimental index-url mode is
390393 # active. Without this, an unsubstituted template like ``$RULES_PYTHON_PIP_INDEX_URL``
391394 # is treated as truthy and the mode is forced on, even when the env var
392395 # would expand to the empty string.
393- default_index_url = envsubst (
396+ self . _default_index_url [ python_version ] = envsubst (
394397 pip_attr .experimental_index_url ,
395398 pip_attr .envsubst ,
396399 mctx .getenv ,
397400 ) or self ._config .index_url
398401 default_extra_index_urls = pip_attr .experimental_extra_index_urls or []
399402
400- if not default_index_url :
403+ if not self . _default_index_url [ python_version ] :
401404 # parallel_download is set to True by default, so we are not checking/validating it
402405 # here
403406 return False
404407
405- python_version = pip_attr .python_version
406408 self ._use_downloader .setdefault (python_version , {}).update ({
407409 normalize_name (s ): False
408410 for s in pip_attr .simpleapi_skip
409411 })
410412 self ._get_index_urls [python_version ] = lambda ctx , distributions , * , index_url = None , extra_index_urls = None : self ._simpleapi_download_fn (
411413 ctx ,
412414 attr = struct (
413- index_url = (index_url or default_index_url ).rstrip ("/" ),
415+ index_url = (index_url or self . _default_index_url [ python_version ] ).rstrip ("/" ),
414416 extra_index_urls = [
415417 x .rstrip ("/" )
416418 for x in (extra_index_urls or default_extra_index_urls )
@@ -579,7 +581,13 @@ def _create_whl_repos(
579581 for src in whl .srcs :
580582 repo = _whl_repo (
581583 src = src ,
582- index_url = whl .index_url ,
584+ index_url = (
585+ whl .index_url or
586+ "{}/{}" .format (
587+ self ._default_index_url [python_version ],
588+ whl .name ,
589+ )
590+ ).rstrip ("/" ),
583591 whl_library_args = whl_library_args ,
584592 download_only = pip_attr .download_only ,
585593 netrc = self ._config .netrc or pip_attr .netrc ,
0 commit comments