1515)
1616from pythonforandroid .prerequisites import OpenSSLPrerequisite
1717
18- HOSTPYTHON_VERSION_UNSET_MESSAGE = (
19- 'The hostpython recipe must have set version'
20- )
18+ HOSTPYTHON_VERSION_UNSET_MESSAGE = "The hostpython recipe must have set version"
2119
22- SETUP_DIST_NOT_FIND_MESSAGE = (
23- 'Could not find Setup.dist or Setup in Python build'
24- )
20+ SETUP_DIST_NOT_FIND_MESSAGE = "Could not find Setup.dist or Setup in Python build"
2521
2622
2723class HostPython3Recipe (Recipe ):
28- '''
24+ """
2925 The hostpython3's recipe.
3026
3127 .. versionchanged:: 2019.10.06.post0
@@ -34,17 +30,17 @@ class HostPython3Recipe(Recipe):
3430 .. versionchanged:: 0.6.0
3531 Refactored into the new class
3632 :class:`~pythonforandroid.python.HostPythonRecipe`
37- '''
33+ """
3834
39- version = ' 3.14.2'
35+ version = " 3.14.2"
4036
41- url = ' https://github.com/python/cpython/archive/refs/tags/v{version}.tar.gz'
42- ''' The default url to download our host python recipe. This url will
43- change depending on the python version set in attribute :attr:`version`.'''
37+ url = " https://github.com/python/cpython/archive/refs/tags/v{version}.tar.gz"
38+ """ The default url to download our host python recipe. This url will
39+ change depending on the python version set in attribute :attr:`version`."""
4440
45- build_subdir = ' native-build'
46- ''' Specify the sub build directory for the hostpython3 recipe. Defaults
47- to ``native-build``.'''
41+ build_subdir = " native-build"
42+ """ Specify the sub build directory for the hostpython3 recipe. Defaults
43+ to ``native-build``."""
4844
4945 patches = ["fix_ensurepip.patch" ]
5046
@@ -59,17 +55,17 @@ def download(self):
5955
6056 @property
6157 def _exe_name (self ):
62- '''
58+ """
6359 Returns the name of the python executable depending on the version.
64- '''
60+ """
6561 if not self .version :
6662 raise BuildInterruptingException (HOSTPYTHON_VERSION_UNSET_MESSAGE )
67- return f' python{ self . version . split ( "." )[ 0 ] } '
63+ return " python"
6864
6965 @property
7066 def python_exe (self ):
71- ''' Returns the full path of the hostpython executable.'''
72- return join (self .get_path_to_python () , self ._exe_name )
67+ """ Returns the full path of the hostpython executable."""
68+ return join (self .local_bin , self ._exe_name )
7369
7470 def get_recipe_env (self , arch = None ):
7571 env = os .environ .copy ()
@@ -91,14 +87,14 @@ def should_build(self, arch):
9187
9288 def get_build_container_dir (self , arch = None ):
9389 choices = self .check_recipe_choices ()
94- dir_name = '-' .join ([self .name ] + choices )
95- return join (self .ctx .build_dir , ' other_builds' , dir_name , ' desktop' )
90+ dir_name = "-" .join ([self .name ] + choices )
91+ return join (self .ctx .build_dir , " other_builds" , dir_name , " desktop" )
9692
9793 def get_build_dir (self , arch = None ):
98- '''
94+ """
9995 .. note:: Unlike other recipes, the hostpython build dir doesn't
10096 depend on the target arch
101- '''
97+ """
10298 return join (self .get_build_container_dir (), self .name )
10399
104100 def get_path_to_python (self ):
@@ -112,16 +108,20 @@ def site_root(self):
112108 def site_bin (self ):
113109 return join (self .site_root , self .site_dir , "bin" )
114110
111+ @property
112+ def local_dir (self ):
113+ return join (self .site_root , "usr/local/" )
114+
115115 @property
116116 def local_bin (self ):
117- return join (self .site_root , "usr/local/ bin/ " )
117+ return join (self .local_dir , "bin" )
118118
119119 @property
120120 def site_dir (self ):
121121 p_version = Version (self .version )
122122 return join (
123123 self .site_root ,
124- f"usr/local/lib/python{ p_version .major } .{ p_version .minor } /site-packages/"
124+ f"usr/local/lib/python{ p_version .major } .{ p_version .minor } /site-packages/" ,
125125 )
126126
127127 @property
@@ -163,34 +163,40 @@ def build_arch(self, arch):
163163 # Configure the build
164164 build_configured = False
165165 with current_directory (build_dir ):
166- if not Path ('config.status' ).exists ():
167- shprint (sh .Command (join (recipe_build_dir , 'configure' )), _env = env )
166+ if not Path ("config.status" ).exists ():
167+ shprint (
168+ sh .Command (join (recipe_build_dir , "configure" )),
169+ "--prefix" ,
170+ self .local_dir ,
171+ _env = env ,
172+ )
168173 build_configured = True
169174
170175 with current_directory (recipe_build_dir ):
171176 # Create the Setup file. This copying from Setup.dist is
172177 # the normal and expected procedure before Python 3.8, but
173178 # after this the file with default options is already named "Setup"
174- setup_dist_location = join (' Modules' , ' Setup.dist' )
179+ setup_dist_location = join (" Modules" , " Setup.dist" )
175180 if Path (setup_dist_location ).exists ():
176- shprint (sh .cp , setup_dist_location ,
177- join (build_dir , 'Modules' , 'Setup' ))
181+ shprint (sh .cp , setup_dist_location , join (build_dir , "Modules" , "Setup" ))
178182 else :
179183 # Check the expected file does exist
180- setup_location = join (' Modules' , ' Setup' )
184+ setup_location = join (" Modules" , " Setup" )
181185 if not Path (setup_location ).exists ():
182- raise BuildInterruptingException (
183- SETUP_DIST_NOT_FIND_MESSAGE
184- )
186+ raise BuildInterruptingException (SETUP_DIST_NOT_FIND_MESSAGE )
185187
186- shprint (sh .make , '-j' , str (cpu_count ()), '-C' , build_dir , _env = env )
188+ shprint (sh .make , "-j" , str (cpu_count ()), "-C" , build_dir , _env = env )
187189
190+ with current_directory (build_dir ):
191+ shprint (sh .make , "install" , _env = env )
192+
193+ with current_directory (recipe_build_dir ):
188194 # make a copy of the python executable giving it the name we want,
189195 # because we got different python's executable names depending on
190196 # the fs being case-insensitive (Mac OS X, Cygwin...) or
191197 # case-sensitive (linux)...so this way we will have an unique name
192198 # for our hostpython, regarding the used fs
193- for exe_name in [' python.exe' , ' python' ]:
199+ for exe_name in [" python.exe" , " python" ]:
194200 exe = join (self .get_path_to_python (), exe_name )
195201 if Path (exe ).is_file ():
196202 shprint (sh .cp , exe , self .python_exe )
@@ -200,10 +206,12 @@ def build_arch(self, arch):
200206 self .ctx .hostpython = self .python_exe
201207
202208 if build_configured :
203-
204209 shprint (
205- sh .Command (self .python_exe ), "-m" , "ensurepip" , "--root" , self .site_root , "-U" ,
206- _env = {"HOME" : "/tmp" , "PATH" : self .local_bin }
210+ sh .Command (self .python_exe ),
211+ "-m" ,
212+ "ensurepip" ,
213+ "-U" ,
214+ _env = {"HOME" : "/tmp" , "PATH" : self .local_bin },
207215 )
208216 self .fix_pip_shebangs ()
209217
0 commit comments