@@ -587,6 +587,7 @@ def resolve(args):
587
587
with open (os .path .join (tempdir , "sitecustomize.py" ), "w" ) as f :
588
588
f .write ("import site; import os; site.addsitedir(os.path.dirname(__file__))" )
589
589
590
+ downloaded_wheel_urls = {}
590
591
for i , o in enumerate (ordering ):
591
592
# Install the wheels since they can be dependent at build time
592
593
for _ , _ , filelist in os .walk (args .directory ):
@@ -615,30 +616,19 @@ def resolve(args):
615
616
pip_args += ["--requirement=" + f .name ]
616
617
pip_args += ["--constraint=" + f2 .name ]
617
618
pip_args += args .pip_args
618
- # https://github.com/pypa/pip/blob/9.0.1/pip/__init__.py#L209
619
- if pip_main (pip_args , env ):
620
- shutil .rmtree (tempdir )
621
- sys .exit (1 )
619
+ with CaptureOutput () as output :
620
+ if pip_main (pip_args , env ):
621
+ print ("pip command failed: " + str (pip_args ))
622
+ shutil .rmtree (tempdir )
623
+ sys .exit (1 )
624
+ dls = re .findall (r'(?:Downloading|Using cached) (\S*\.whl)' , output .stdout .getvalue ().decode ())
625
+ downloaded_wheel_urls .update ({
626
+ url [url .rfind ("/" )+ 1 :]: url
627
+ for url in dls
628
+ })
622
629
623
630
shutil .rmtree (tempdir )
624
631
625
- # Find all http/s URLs explicitly stated in the requirements.txt file - these
626
- # URLs will be passed through to the bazel rules below to support wheels that
627
- # are not in any index.
628
- url_pattern = re .compile (r'(https?://\S+).*' )
629
- def get_url (line ):
630
- m = url_pattern .match (line )
631
- return m .group (1 ) if m else None
632
- requirements_urls = []
633
- for inputfile in args .input :
634
- with open (inputfile ) as f :
635
- requirements_urls += [get_url (x ) for x in f .readlines () if get_url (x )]
636
- def requirement_download_url (wheel_name ):
637
- for url in requirements_urls :
638
- if wheel_name in url :
639
- return url
640
- return None
641
-
642
632
# Enumerate the .whl files we downloaded.
643
633
whls = wheels_from_dir (args .directory )
644
634
@@ -691,6 +681,11 @@ def transitive_build_deps(wheel, build_info):
691
681
# deterministic sha256.
692
682
if args .digests :
693
683
for w in whls :
684
+ # If we downloaded a whl file instead of building it locally, we can use its digest as is.
685
+ if w .basename () in downloaded_wheel_urls :
686
+ wheel_digests [w .name ()] = digest (w .path ())
687
+ continue
688
+
694
689
# If the current (not-yet-updated) requirements.bzl already has a sha256 and it
695
690
# matches with the sha of the wheel that we bulit during resolve (typical for
696
691
# binary distributions), then we can just use that.
@@ -743,7 +738,7 @@ def whl_library(wheel):
743
738
attrs += [("wheel_name" , quote (wheel .basename ()))]
744
739
if args .digests :
745
740
attrs += [("sha256" , quote (wheel_digests [wheel .name ()]))]
746
- url = requirement_download_url (wheel .basename ())
741
+ url = downloaded_wheel_urls . get (wheel .basename (), None )
747
742
if url :
748
743
attrs += [("urls" , '[{}]' .format (quote (url )))]
749
744
if args .output_format != 'download' :
0 commit comments