@@ -46,18 +46,20 @@ def hub_builder(
4646 _available_interpreters = available_interpreters ,
4747 _simpleapi_download_fn = simpleapi_download_fn ,
4848 _simpleapi_cache = simpleapi_cache ,
49+ _get_index_urls = {},
4950 # keep sorted
5051 add = lambda * a , ** k : _add (self , * a , ** k ),
51- get_index_urls = lambda * a , ** k : _get_index_urls (self , * a , ** k ),
5252 detect_interpreter = lambda * a , ** k : _detect_interpreter (self , * a , ** k ),
53+ get_index_urls = lambda version : self ._get_index_urls [version ],
5354 platforms = lambda version : self .python_versions [version ],
5455 add_whl_library = lambda * a , ** k : _add_whl_library (self , * a , ** k ),
5556 )
5657
5758 # buildifier: enable=uninitialized
5859 return self
5960
60- def _add (self , * , python_version ):
61+ def _add (self , * , pip_attr ):
62+ python_version = pip_attr .python_version
6163 if python_version in self .python_versions :
6264 fail ((
6365 "Duplicate pip python version '{version}' for hub " +
@@ -74,39 +76,40 @@ def _add(self, *, python_version):
7476 minor_mapping = self ._minor_mapping ,
7577 config = self .config ,
7678 )
79+ self ._get_index_urls [python_version ] = _get_index_urls (self , pip_attr )
7780
7881def _get_index_urls (self , pip_attr ):
79- get_index_urls = None
80- if pip_attr .experimental_index_url :
81- skip_sources = [
82- normalize_name ( s )
83- for s in pip_attr . simpleapi_skip
84- ]
85- get_index_urls = lambda ctx , distributions : self . _simpleapi_download_fn (
86- ctx ,
87- attr = struct (
88- index_url = pip_attr . experimental_index_url ,
89- extra_index_urls = pip_attr .experimental_extra_index_urls or [],
90- index_url_overrides = pip_attr . experimental_index_url_overrides or {},
91- sources = [
92- d
93- for d in distributions
94- if normalize_name ( d ) not in skip_sources
95- ],
96- envsubst = pip_attr .envsubst ,
97- # Auth related info
98- netrc = pip_attr . netrc ,
99- auth_patterns = pip_attr . auth_patterns ,
100- ),
101- cache = self . _simpleapi_cache ,
102- parallel_download = pip_attr .parallel_download ,
103- )
104- elif pip_attr .experimental_extra_index_urls :
105- fail ( "'experimental_extra_index_urls' is a no-op unless 'experimental_index_url' is set" )
106- elif pip_attr . experimental_index_url_overrides :
107- fail ( "'experimental_index_url_overrides' is a no-op unless 'experimental_index_url' is set" )
108-
109- return get_index_urls
82+ if not pip_attr . experimental_index_url :
83+ if pip_attr .experimental_extra_index_urls :
84+ fail ( "'experimental_extra_index_urls' is a no-op unless 'experimental_index_url' is set" )
85+ elif pip_attr . experimental_index_url_overrides :
86+ fail ( "'experimental_index_url_overrides' is a no-op unless 'experimental_index_url' is set" )
87+
88+ return None
89+
90+ skip_sources = [
91+ normalize_name ( s )
92+ for s in pip_attr .simpleapi_skip
93+ ]
94+ return lambda ctx , distributions : self . _simpleapi_download_fn (
95+ ctx ,
96+ attr = struct (
97+ index_url = pip_attr . experimental_index_url ,
98+ extra_index_urls = pip_attr . experimental_extra_index_urls or [ ],
99+ index_url_overrides = pip_attr .experimental_index_url_overrides or {} ,
100+ sources = [
101+ d
102+ for d in distributions
103+ if normalize_name ( d ) not in skip_sources
104+ ] ,
105+ envsubst = pip_attr .envsubst ,
106+ # Auth related info
107+ netrc = pip_attr .netrc ,
108+ auth_patterns = pip_attr . auth_patterns ,
109+ ),
110+ cache = self . _simpleapi_cache ,
111+ parallel_download = pip_attr . parallel_download ,
112+ )
110113
111114def _detect_interpreter (self , pip_attr ):
112115 python_interpreter_target = pip_attr .python_interpreter_target
0 commit comments