@@ -762,15 +762,13 @@ def _populate_requirements_cache(
762762 # Download to a temporary directory first, then copy to cache.
763763 # This allows us to track exactly which packages are needed for this
764764 # requirements file.
765- download_dir = tempfile . mkdtemp ( dir = temp_directory )
765+ download_dir = None
766766
767767 cmd_args = [
768768 Stager ._get_python_executable (),
769769 '-m' ,
770770 'pip' ,
771771 'download' ,
772- '--dest' ,
773- download_dir ,
774772 '--find-links' ,
775773 cache_dir ,
776774 '-r' ,
@@ -781,23 +779,54 @@ def _populate_requirements_cache(
781779 ]
782780
783781 if populate_cache_with_sdists :
784- cmd_args .extend (['--no-binary' , ':all:' ])
782+ download_dir = tempfile .mkdtemp (dir = temp_directory )
783+ cmd_args .extend (['--dest' , download_dir , '--no-binary' , ':all:' ])
784+ _LOGGER .info ('Executing command: %s' , cmd_args )
785+ processes .check_call (cmd_args )
785786 else :
786787 language_implementation_tag = 'cp'
787788 abi_suffix = 'm' if sys .version_info < (3 , 8 ) else ''
788789 abi_tag = 'cp%d%d%s' % (
789790 sys .version_info [0 ], sys .version_info [1 ], abi_suffix )
790- platform_tag = Stager ._get_platform_for_default_sdk_container ()
791- cmd_args .extend ([
792- '--implementation' ,
793- language_implementation_tag ,
794- '--abi' ,
795- abi_tag ,
796- '--platform' ,
797- platform_tag
798- ])
799- _LOGGER .info ('Executing command: %s' , cmd_args )
800- processes .check_output (cmd_args , stderr = processes .STDOUT )
791+ preferred_platform = Stager ._get_platform_for_default_sdk_container ()
792+
793+ # Fallback platform tags in case the preferred modern tag is too strict
794+ # for some dependencies on PyPI when cross-downloading.
795+ platforms = [preferred_platform ]
796+ if preferred_platform == 'manylinux_2_28_x86_64' :
797+ platforms .extend (['manylinux2014_x86_64' , 'manylinux2010_x86_64' ])
798+ elif preferred_platform == 'manylinux2014_x86_64' :
799+ platforms .append ('manylinux2010_x86_64' )
800+
801+ last_exception = None
802+ for platform in platforms :
803+ attempt_download_dir = tempfile .mkdtemp (dir = temp_directory )
804+ attempt_cmd_args = cmd_args + [
805+ '--dest' ,
806+ attempt_download_dir ,
807+ '--implementation' ,
808+ language_implementation_tag ,
809+ '--abi' ,
810+ abi_tag ,
811+ '--platform' ,
812+ platform
813+ ]
814+ _LOGGER .info ('Executing command: %s' , attempt_cmd_args )
815+ try :
816+ processes .check_call (attempt_cmd_args )
817+ download_dir = attempt_download_dir
818+ last_exception = None
819+ break
820+ except Exception as e :
821+ _LOGGER .warning (
822+ 'Pip download failed with platform %s, trying fallback: %s' ,
823+ platform ,
824+ e )
825+ shutil .rmtree (attempt_download_dir )
826+ last_exception = e
827+
828+ if last_exception :
829+ raise last_exception
801830
802831 # Get list of downloaded packages and copy them to the cache
803832 downloaded_packages = set ()
0 commit comments