1- from os .path import basename , dirname , exists , isdir , isfile , join , realpath , split
1+ from os .path import basename , dirname , exists , isdir , isfile , join , realpath , relpath , split
22import glob
33import hashlib
44import json
@@ -973,6 +973,8 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
973973 # as it occasionally matters how Python e.g. reads files
974974 env ['LANG' ] = "en_GB.UTF-8"
975975
976+ env ["PYTHONDONTWRITEBYTECODE" ] = "1"
977+
976978 # Binaries made by packages installed by pip
977979 self .patch_shebangs (self ._host_recipe .local_bin , self .real_hostpython_location )
978980 env ["PATH" ] = self ._host_recipe .local_bin + ":" + self ._host_recipe .site_bin + ":" + env ["PATH" ]
@@ -993,11 +995,17 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
993995
994996 def should_build (self , arch ):
995997 name = self .folder_name
996- if self .ctx .has_package (name , arch ):
997- info ('Python package already exists in site-packages' )
998- return False
999- info ('{} apparently isn\' t already in site-packages' .format (name ))
1000- return True
998+ host_package_dir = join (self ._host_recipe .site_dir , name )
999+ if self .install_in_hostpython and not exists (host_package_dir ):
1000+ info ('{} apparently isn\' t already in hostpython site-packages ({})' .format (name , host_package_dir ))
1001+ return True
1002+
1003+ if self .install_in_targetpython and not self .ctx .has_package (name , arch ):
1004+ info ('{} apparently isn\' t already in site-packages' .format (name ))
1005+ return True
1006+
1007+ info ('Python package already exists in target site-packages' )
1008+ return False
10011009
10021010 def build_arch (self , arch ):
10031011 '''Install the Python module by calling setup.py install with
@@ -1009,7 +1017,6 @@ def build_arch(self, arch):
10091017 def install_python_package (self , arch , name = None , env = None , is_dir = True ):
10101018 '''Automate the installation of a Python package (or a cython
10111019 package where the cython components are pre-built).'''
1012- # arch = self.filtered_archs[0] # old kivy-ios way
10131020 if name is None :
10141021 name = self .name
10151022 if env is None :
@@ -1022,7 +1029,8 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
10221029 with current_directory (self .get_build_dir (arch .arch )):
10231030
10241031 if isfile ("setup.py" ):
1025- shprint (hostpython , 'setup.py' , 'install' , '-O2' ,
1032+ if self .install_in_targetpython :
1033+ shprint (hostpython , 'setup.py' , 'install' , '-O2' ,
10261034 '--root={}' .format (self .ctx .get_python_install_dir (arch .arch )),
10271035 '--install-lib=.' ,
10281036 _env = hpenv , * self .setup_extra_args )
@@ -1035,6 +1043,7 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
10351043
10361044 def get_hostrecipe_env (self , arch = None ):
10371045 env = environ .copy ()
1046+ env ["PYTHONDONTWRITEBYTECODE" ] = "1"
10381047 _python_path = self ._host_recipe .get_path_to_python ()
10391048 libdir = glob .glob (join (_python_path , "build" , "lib*" ))
10401049 env ['PYTHONPATH' ] = self ._host_recipe .site_dir + ":" + join (
@@ -1049,8 +1058,7 @@ def install_hostpython_package(self, arch):
10491058 env = self .get_hostrecipe_env (arch )
10501059 real_hostpython = sh .Command (self .real_hostpython_location )
10511060 shprint (real_hostpython , 'setup.py' , 'install' , '-O2' ,
1052- '--root={}' .format (dirname (self .real_hostpython_location )),
1053- '--install-lib=Lib/site-packages' ,
1061+ '--install-lib={}' .format (relpath (self ._host_recipe .site_dir , self ._host_recipe .site_root )),
10541062 '--root={}' .format (self ._host_recipe .site_root ),
10551063 _env = env , * self .setup_extra_args )
10561064
@@ -1066,6 +1074,8 @@ def install_hostpython_prerequisites(self, packages=None, force_upgrade=True):
10661074 if len (packages ) == 0 :
10671075 return
10681076
1077+ debug ('Installing hostpython prerequisites: {} ({})' .format (packages , self ._host_recipe .site_dir ))
1078+
10691079 pip_options = [
10701080 "install" ,
10711081 * packages ,
0 commit comments