1111import re
1212import shutil
1313import subprocess
14+ import sys
1415
1516import sh
1617
2122from pythonforandroid .archs import ArchARM , ArchARMv7_a , ArchAarch_64 , Archx86 , Archx86_64
2223from pythonforandroid .logger import (info , warning , info_notify , info_main , shprint , Out_Style , Out_Fore )
2324from pythonforandroid .pythonpackage import get_package_name
24- from pythonforandroid .recipe import CythonRecipe , Recipe
25+ from pythonforandroid .recipe import CythonRecipe , Recipe , PyProjectRecipe
2526from pythonforandroid .recommendations import (
2627 check_ndk_version , check_target_api , check_ndk_api ,
2728 RECOMMENDED_NDK_API , RECOMMENDED_TARGET_API )
@@ -101,6 +102,14 @@ class Context:
101102
102103 java_build_tool = 'auto'
103104
105+ skip_prebuilt = False
106+
107+ extra_index_urls = []
108+
109+ use_prebuilt_version_for = []
110+
111+ save_wheel_dir = ''
112+
104113 @property
105114 def packages_path (self ):
106115 '''Where packages are downloaded before being unpacked'''
@@ -503,6 +512,10 @@ def build_recipes(build_order, python_modules, ctx, project_dir,
503512 recipe .prepare_build_dir (arch .arch )
504513
505514 info_main ('# Prebuilding recipes' )
515+ # ensure we have `ctx.python_recipe` and `ctx.hostpython`
516+ Recipe .get_recipe ("python3" , ctx ).prebuild_arch (arch )
517+ ctx .hostpython = Recipe .get_recipe ("hostpython3" , ctx ).python_exe
518+
506519 # 2) prebuild packages
507520 for recipe in recipes :
508521 info_main ('Prebuilding {} for {}' .format (recipe .name , arch .arch ))
@@ -667,7 +680,17 @@ def is_wheel_platform_independent(whl_name):
667680 return all (tag .platform == "any" for tag in tags )
668681
669682
670- def process_python_modules (ctx , modules ):
683+ def is_wheel_compatible (whl_name , arch , ctx ):
684+ name , version , build , tags = parse_wheel_filename (whl_name )
685+ supported_tags = PyProjectRecipe .get_wheel_platform_tags (arch .arch , ctx )
686+ supported_tags .append ("any" )
687+ result = all (tag .platform in supported_tags for tag in tags )
688+ if not result :
689+ warning (f"Incompatible module : { whl_name } " )
690+ return result
691+
692+
693+ def process_python_modules (ctx , modules , arch ):
671694 """Use pip --dry-run to resolve dependencies and filter for pure-Python packages
672695 """
673696 modules = list (modules )
@@ -702,6 +725,7 @@ def process_python_modules(ctx, modules):
702725
703726 # setup hostpython recipe
704727 env = environ .copy ()
728+ host_recipe = None
705729 try :
706730 host_recipe = Recipe .get_recipe ("hostpython3" , ctx )
707731 _python_path = host_recipe .get_path_to_python ()
@@ -710,14 +734,32 @@ def process_python_modules(ctx, modules):
710734 _python_path , "Modules" ) + ":" + (libdir [0 ] if libdir else "" )
711735 pip = host_recipe .pip
712736 except Exception :
713- # hostpython3 non available so we use system pip (like in tests)
737+ # hostpython3 is unavailable, so fall back to system pip
714738 pip = sh .Command ("pip" )
715739
740+ # add platform tags
741+ platforms = []
742+ tags = PyProjectRecipe .get_wheel_platform_tags (arch .arch , ctx )
743+ for tag in tags :
744+ platforms .append (f"--platform={ tag } " )
745+
746+ if host_recipe is not None :
747+ platforms .extend (["--python-version" , host_recipe .version ])
748+ else :
749+ # use the version of the currently running Python interpreter
750+ current_version = f"{ sys .version_info .major } .{ sys .version_info .minor } .{ sys .version_info .micro } "
751+ platforms .extend (["--python-version" , current_version ])
752+
753+ indices = []
754+ # add extra index urls
755+ for index in ctx .extra_index_urls :
756+ indices .extend (["--extra-index-url" , index ])
716757 try :
717758 shprint (
718759 pip , 'install' , * modules ,
719760 '--dry-run' , '--break-system-packages' , '--ignore-installed' ,
720- '--report' , path , '-q' , _env = env
761+ '--disable-pip-version-check' , '--only-binary=:all:' ,
762+ '--report' , path , '-q' , * platforms , * indices , _env = env
721763 )
722764 except Exception as e :
723765 warning (f"Auto module resolution failed: { e } " )
@@ -751,7 +793,9 @@ def process_python_modules(ctx, modules):
751793 filename = basename (module ["download_info" ]["url" ])
752794 pure_python = True
753795
754- if (filename .endswith (".whl" ) and not is_wheel_platform_independent (filename )):
796+ if (
797+ filename .endswith (".whl" ) and not is_wheel_compatible (filename , arch , ctx )
798+ ):
755799 any_not_pure_python = True
756800 pure_python = False
757801
@@ -769,7 +813,7 @@ def process_python_modules(ctx, modules):
769813 )
770814
771815 if pure_python :
772- processed_modules .append (f" { mname } == { mver } " )
816+ processed_modules .append (module [ "download_info" ][ "url" ] )
773817 info (" " )
774818
775819 if any_not_pure_python :
@@ -793,7 +837,7 @@ def run_pymodules_install(ctx, arch, modules, project_dir=None,
793837
794838 info ('*** PYTHON PACKAGE / PROJECT INSTALL STAGE FOR ARCH: {} ***' .format (arch ))
795839
796- modules = process_python_modules (ctx , modules )
840+ modules = process_python_modules (ctx , modules , arch )
797841
798842 modules = [m for m in modules if ctx .not_has_package (m , arch )]
799843
0 commit comments