@@ -818,15 +818,14 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None):
818818 builder = self ._build_one_pep517
819819 else :
820820 builder = self ._build_one_legacy
821- if builder (req , temp_dir .path , python_tag = python_tag ):
821+ wheel_path = builder (req , temp_dir .path , python_tag = python_tag )
822+ if wheel_path is not None :
823+ wheel_name = os .path .basename (wheel_path )
824+ dest_path = os .path .join (output_dir , wheel_name )
822825 try :
823- wheel_name = os .listdir (temp_dir .path )[0 ]
824- wheel_path = os .path .join (output_dir , wheel_name )
825- shutil .move (
826- os .path .join (temp_dir .path , wheel_name ), wheel_path
827- )
826+ shutil .move (wheel_path , dest_path )
828827 logger .info ('Stored in directory: %s' , output_dir )
829- return wheel_path
828+ return dest_path
830829 except Exception :
831830 pass
832831 # Ignore return, we can't do anything else useful.
@@ -844,29 +843,39 @@ def _base_setup_args(self, req):
844843 ] + list (self .global_options )
845844
846845 def _build_one_pep517 (self , req , tempd , python_tag = None ):
846+ """Build one InstallRequirement using the PEP 517 build process.
847+
848+ Returns path to wheel if successfully built. Otherwise, returns None.
849+ """
847850 assert req .metadata_directory is not None
848851 try :
849852 req .spin_message = 'Building wheel for %s (PEP 517)' % (req .name ,)
850853 logger .debug ('Destination directory: %s' , tempd )
851- wheelname = req .pep517_backend .build_wheel (
854+ wheel_name = req .pep517_backend .build_wheel (
852855 tempd ,
853856 metadata_directory = req .metadata_directory
854857 )
855858 if python_tag :
856859 # General PEP 517 backends don't necessarily support
857860 # a "--python-tag" option, so we rename the wheel
858861 # file directly.
859- newname = replace_python_tag (wheelname , python_tag )
862+ new_name = replace_python_tag (wheel_name , python_tag )
860863 os .rename (
861- os .path .join (tempd , wheelname ),
862- os .path .join (tempd , newname )
864+ os .path .join (tempd , wheel_name ),
865+ os .path .join (tempd , new_name )
863866 )
864- return True
867+ # Reassign to simplify the return at the end of function
868+ wheel_name = new_name
865869 except Exception :
866870 logger .error ('Failed building wheel for %s' , req .name )
867- return False
871+ return None
872+ return os .path .join (tempd , wheel_name )
868873
869874 def _build_one_legacy (self , req , tempd , python_tag = None ):
875+ """Build one InstallRequirement using the "legacy" build process.
876+
877+ Returns path to wheel if successfully built. Otherwise, returns None.
878+ """
870879 base_args = self ._base_setup_args (req )
871880
872881 spin_message = 'Building wheel for %s (setup.py)' % (req .name ,)
@@ -881,11 +890,12 @@ def _build_one_legacy(self, req, tempd, python_tag=None):
881890 try :
882891 call_subprocess (wheel_args , cwd = req .setup_py_dir ,
883892 show_stdout = False , spinner = spinner )
884- return True
885893 except Exception :
886894 spinner .finish ("error" )
887895 logger .error ('Failed building wheel for %s' , req .name )
888- return False
896+ return None
897+ # listdir's return value is sorted to be deterministic
898+ return os .path .join (tempd , sorted (os .listdir (tempd ))[0 ])
889899
890900 def _clean_one (self , req ):
891901 base_args = self ._base_setup_args (req )
0 commit comments