@@ -28,6 +28,7 @@ load("//python/private:parse_requirements.bzl", "host_platform", "parse_requirem
2828load ("//python/private:parse_whl_name.bzl" , "parse_whl_name" )
2929load ("//python/private:pypi_index.bzl" , "simpleapi_download" )
3030load ("//python/private:render_pkg_aliases.bzl" , "whl_alias" )
31+ load ("//python/private:repo_utils.bzl" , "repo_utils" )
3132load ("//python/private:version_label.bzl" , "version_label" )
3233load ("//python/private:whl_target_platforms.bzl" , "select_whl" )
3334load (":pip_repository.bzl" , "pip_repository" )
@@ -100,6 +101,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
100101 )
101102
102103def _create_whl_repos (module_ctx , pip_attr , whl_map , whl_overrides , group_map , simpleapi_cache ):
104+ logger = repo_utils .logger (module_ctx )
103105 python_interpreter_target = pip_attr .python_interpreter_target
104106
105107 # if we do not have the python_interpreter set in the attributes
@@ -160,32 +162,18 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
160162
161163 # Create a new wheel library for each of the different whls
162164
163- requirements_by_platform = parse_requirements (
164- module_ctx ,
165- requirements_by_platform = pip_attr .requirements_by_platform ,
166- requirements_linux = pip_attr .requirements_linux ,
167- requirements_lock = pip_attr .requirements_lock ,
168- requirements_osx = pip_attr .requirements_darwin ,
169- requirements_windows = pip_attr .requirements_windows ,
170- extra_pip_args = pip_attr .extra_pip_args ,
171- )
172-
173- index_urls = {}
165+ get_index_urls = None
174166 if pip_attr .experimental_index_url :
175167 if pip_attr .download_only :
176168 fail ("Currently unsupported to use `download_only` and `experimental_index_url`" )
177169
178- index_urls = simpleapi_download (
179- module_ctx ,
170+ get_index_urls = lambda ctx , distributions : simpleapi_download (
171+ ctx ,
180172 attr = struct (
181173 index_url = pip_attr .experimental_index_url ,
182174 extra_index_urls = pip_attr .experimental_extra_index_urls or [],
183175 index_url_overrides = pip_attr .experimental_index_url_overrides or {},
184- sources = list ({
185- req .distribution : None
186- for reqs in requirements_by_platform .values ()
187- for req in reqs
188- }),
176+ sources = distributions ,
189177 envsubst = pip_attr .envsubst ,
190178 # Auth related info
191179 netrc = pip_attr .netrc ,
@@ -195,6 +183,19 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
195183 parallel_download = pip_attr .parallel_download ,
196184 )
197185
186+ requirements_by_platform = parse_requirements (
187+ module_ctx ,
188+ requirements_by_platform = pip_attr .requirements_by_platform ,
189+ requirements_linux = pip_attr .requirements_linux ,
190+ requirements_lock = pip_attr .requirements_lock ,
191+ requirements_osx = pip_attr .requirements_darwin ,
192+ requirements_windows = pip_attr .requirements_windows ,
193+ extra_pip_args = pip_attr .extra_pip_args ,
194+ get_index_urls = get_index_urls ,
195+ python_version = major_minor ,
196+ logger = logger ,
197+ )
198+
198199 repository_platform = host_platform (module_ctx .os )
199200 for whl_name , requirements in requirements_by_platform .items ():
200201 requirement = select_requirement (
@@ -255,37 +256,22 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
255256 )
256257 whl_library_args .update ({k : v for k , (v , default ) in maybe_args_with_default .items () if v == default })
257258
258- if index_urls :
259- whls = []
260- sdist = None
261- for sha256 in requirement .srcs .shas :
262- # For now if the artifact is marked as yanked we just ignore it.
263- #
264- # See https://packaging.python.org/en/latest/specifications/simple-repository-api/#adding-yank-support-to-the-simple-api
265-
266- maybe_whl = index_urls [whl_name ].whls .get (sha256 )
267- if maybe_whl and not maybe_whl .yanked :
268- whls .append (maybe_whl )
269- continue
270-
271- maybe_sdist = index_urls [whl_name ].sdists .get (sha256 )
272- if maybe_sdist and not maybe_sdist .yanked :
273- sdist = maybe_sdist
274- continue
275-
276- print ("WARNING: Could not find a whl or an sdist with sha256={}" .format (sha256 )) # buildifier: disable=print
277-
259+ if requirement .whls or requirement .sdist :
260+ logger .debug (lambda : "Selecting a compatible dist for {} from dists:\n {}" .format (
261+ repository_platform ,
262+ json .encode (
263+ struct (
264+ whls = requirement .whls ,
265+ sdist = requirement .sdist ,
266+ ),
267+ ),
268+ ))
278269 distribution = select_whl (
279- whls = whls ,
280- want_abis = [
281- "none" ,
282- "abi3" ,
283- "cp" + major_minor .replace ("." , "" ),
284- # Older python versions have wheels for the `*m` ABI.
285- "cp" + major_minor .replace ("." , "" ) + "m" ,
286- ],
270+ whls = requirement .whls ,
287271 want_platform = repository_platform ,
288- ) or sdist
272+ ) or requirement .sdist
273+
274+ logger .debug (lambda : "Selected: {}" .format (distribution ))
289275
290276 if distribution :
291277 whl_library_args ["requirement" ] = requirement .srcs .requirement
@@ -303,7 +289,7 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
303289 # This is no-op because pip is not used to download the wheel.
304290 whl_library_args .pop ("download_only" , None )
305291 else :
306- print ( "WARNING: falling back to pip for installing the right file for {}" .format (requirement .requirement_line )) # buildifier: disable=print
292+ logger . warn ( " falling back to pip for installing the right file for {}" .format (requirement .requirement_line ))
307293
308294 # We sort so that the lock-file remains the same no matter the order of how the
309295 # args are manipulated in the code going before.
0 commit comments