@@ -946,12 +946,14 @@ def folder_name(self):
946946
947947 def get_recipe_env (self , arch = None , with_flags_in_cc = True ):
948948 env = super ().get_recipe_env (arch , with_flags_in_cc )
949- env ['PYTHONNOUSERSITE' ] = '1'
950949 # Set the LANG, this isn't usually important but is a better default
951950 # as it occasionally matters how Python e.g. reads files
952951 env ['LANG' ] = "en_GB.UTF-8"
953952 # Binaries made by packages installed by pip
954953 env ["PATH" ] = self ._host_recipe .site_bin + ":" + env ["PATH" ]
954+
955+ host_env = self .get_hostrecipe_env ()
956+ env ['PYTHONPATH' ] = host_env ["PYTHONPATH" ]
955957
956958 if not self .call_hostpython_via_targetpython :
957959 env ['CFLAGS' ] += ' -I{}' .format (
@@ -961,24 +963,11 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
961963 self .ctx .python_recipe .link_root (arch .arch ),
962964 self .ctx .python_recipe .link_version ,
963965 )
964-
965- hppath = []
966- hppath .append (join (dirname (self .hostpython_location ), 'Lib' ))
967- hppath .append (join (hppath [0 ], 'site-packages' ))
968- builddir = join (dirname (self .hostpython_location ), 'build' )
969- if exists (builddir ):
970- hppath += [join (builddir , d ) for d in listdir (builddir )
971- if isdir (join (builddir , d ))]
972- if len (hppath ) > 0 :
973- if 'PYTHONPATH' in env :
974- env ['PYTHONPATH' ] = ':' .join (hppath + [env ['PYTHONPATH' ]])
975- else :
976- env ['PYTHONPATH' ] = ':' .join (hppath )
977966 return env
978967
979968 def should_build (self , arch ):
980969 name = self .folder_name
981- if self .ctx .has_package (name , arch ):
970+ if self .ctx .has_package (name , arch ) or name in listdir ( self . _host_recipe . site_dir ) :
982971 info ('Python package already exists in site-packages' )
983972 return False
984973 info ('{} apparently isn\' t already in site-packages' .format (name ))
@@ -1005,22 +994,28 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
1005994 hostpython = sh .Command (self .hostpython_location )
1006995 hpenv = env .copy ()
1007996 with current_directory (self .get_build_dir (arch .arch )):
1008- shprint (hostpython , 'setup.py' , 'install' , '-O2' ,
1009- '--root={}' .format (self .ctx .get_python_install_dir (arch .arch )),
1010- '--install-lib=.' ,
1011- _env = hpenv , * self .setup_extra_args )
997+ if isfile ("setup.py" ):
998+ shprint (hostpython , 'setup.py' , 'install' , '-O2' ,
1012999
1013- # If asked, also install in the hostpython build dir
1014- if self . install_in_hostpython :
1015- self .install_hostpython_package ( arch )
1000+ '--root={}' . format ( self . ctx . get_python_install_dir ( arch . arch )),
1001+ '--install-lib=.' ,
1002+ _env = hpenv , * self .setup_extra_args )
10161003
1017- def get_hostrecipe_env (self , arch ):
1004+ # If asked, also install in the hostpython build dir
1005+ if self .install_in_hostpython :
1006+ self .install_hostpython_package (arch )
1007+ else :
1008+ warning ("`PythonRecipe.install_python_package` called without `setup.py` file!" )
1009+
1010+ def get_hostrecipe_env (self ):
10181011 env = environ .copy ()
1019- env ['PYTHONPATH' ] = self ._host_recipe .site_dir
1012+ _python_path = self ._host_recipe .get_path_to_python ()
1013+ env ['PYTHONPATH' ] = self ._host_recipe .site_dir + ":" + join (
1014+ _python_path , "Modules" ) + ":" + glob .glob (join (_python_path , "build" , "lib*" ))[0 ]
10201015 return env
10211016
10221017 def install_hostpython_package (self , arch ):
1023- env = self .get_hostrecipe_env (arch )
1018+ env = self .get_hostrecipe_env ()
10241019 real_hostpython = sh .Command (self .real_hostpython_location )
10251020 shprint (real_hostpython , 'setup.py' , 'install' , '-O2' ,
10261021 '--root={}' .format (self ._host_recipe .site_root ),
@@ -1031,7 +1026,7 @@ def python_major_minor_version(self):
10311026 parsed_version = packaging .version .parse (self .ctx .python_recipe .version )
10321027 return f"{ parsed_version .major } .{ parsed_version .minor } "
10331028
1034- def install_hostpython_prerequisites (self , packages = None , force_upgrade = True ):
1029+ def install_hostpython_prerequisites (self , packages = None , force_upgrade = True , arch = None ):
10351030 if not packages :
10361031 packages = self .hostpython_prerequisites
10371032
@@ -1049,7 +1044,7 @@ def install_hostpython_prerequisites(self, packages=None, force_upgrade=True):
10491044 if force_upgrade :
10501045 pip_options .append ("--upgrade" )
10511046 # Use system's pip
1052- shprint (sh .Command (), * pip_options )
1047+ shprint (sh .Command (self . real_hostpython_location ), "-m" , "pip" , * pip_options , _env = self . get_hostrecipe_env () )
10531048
10541049 def restore_hostpython_prerequisites (self , packages ):
10551050 _packages = []
@@ -1088,13 +1083,12 @@ def build_compiled_components(self, arch):
10881083 env ['STRIP' ], '{}' , ';' , _env = env )
10891084
10901085 def install_hostpython_package (self , arch ):
1091- env = self .get_hostrecipe_env (arch )
1086+ env = self .get_hostrecipe_env ()
10921087 self .rebuild_compiled_components (arch , env )
10931088 super ().install_hostpython_package (arch )
10941089
10951090 def rebuild_compiled_components (self , arch , env ):
10961091 info ('Rebuilding compiled components in {}' .format (self .name ))
1097-
10981092 hostpython = sh .Command (self .real_hostpython_location )
10991093 shprint (hostpython , 'setup.py' , 'clean' , '--all' , _env = env )
11001094 shprint (hostpython , 'setup.py' , self .build_cmd , '-v' , _env = env ,
@@ -1128,7 +1122,7 @@ def build_cython_components(self, arch):
11281122
11291123 with current_directory (self .get_build_dir (arch .arch )):
11301124 hostpython = sh .Command (self .ctx .hostpython )
1131- shprint (hostpython , '-c' , 'import sys; print(sys.path)' , _env = env )
1125+ shprint (hostpython , '-c' , 'import sys; print(sys.path, sys.exec_prefix, sys.prefix )' , _env = env )
11321126 debug ('cwd is {}' .format (realpath (curdir )))
11331127 info ('Trying first build of {} to get cython files: this is '
11341128 'expected to fail' .format (self .name ))
0 commit comments