Skip to content

Commit c5c508f

Browse files
committed
fix PYTHONPATH hacks
1 parent 2f107b1 commit c5c508f

3 files changed

Lines changed: 13 additions & 24 deletions

File tree

pythonforandroid/build.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,6 @@ def process_python_modules(ctx, modules, arch):
728728
host_recipe = None
729729
try:
730730
host_recipe = Recipe.get_recipe("hostpython3", ctx)
731-
_python_path = host_recipe.get_path_to_python()
732-
libdir = glob.glob(join(_python_path, "build", "lib*"))
733-
env['PYTHONPATH'] = host_recipe.site_dir + ":" + join(
734-
_python_path, "Modules") + ":" + (libdir[0] if libdir else "")
735731
pip = host_recipe.pip
736732
except Exception:
737733
# hostpython3 is unavailable, so fall back to system pip

pythonforandroid/recipe.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,10 +1031,8 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
10311031

10321032
def get_hostrecipe_env(self, arch=None):
10331033
env = environ.copy()
1034-
_python_path = self._host_recipe.get_path_to_python()
1035-
libdir = glob.glob(join(_python_path, "build", "lib*"))
1036-
env['PYTHONPATH'] = self._host_recipe.site_dir + ":" + join(
1037-
_python_path, "Modules") + ":" + (libdir[0] if libdir else "")
1034+
env['PYTHONPATH'] = ''
1035+
env['HOME'] = '/tmp'
10381036
return env
10391037

10401038
@property
@@ -1063,14 +1061,9 @@ def install_hostpython_prerequisites(self, packages=None, force_upgrade=True):
10631061
pip_options = [
10641062
"install",
10651063
*packages,
1066-
"--target", self._host_recipe.site_dir, "--python-version",
1067-
self.ctx.python_recipe.version,
1068-
# Don't use sources, instead wheels
1069-
"--only-binary=:all:",
10701064
]
10711065
if force_upgrade:
10721066
pip_options.append("--upgrade")
1073-
# Use system's pip
10741067
pip_env = self.get_hostrecipe_env()
10751068
shprint(self._host_recipe.pip, *pip_options, _env=pip_env)
10761069

@@ -1397,8 +1390,6 @@ def build_arch(self, arch):
13971390
# make build dir separately
13981391
sub_build_dir = join(build_dir, "p4a_android_build")
13991392
ensure_dir(sub_build_dir)
1400-
# copy hostpython to built python to ensure correct selection of libs and includes
1401-
shprint(sh.cp, self.real_hostpython_location, self.ctx.python_recipe.python_exe)
14021393

14031394
build_args = [
14041395
"-m",
@@ -1411,7 +1402,7 @@ def build_arch(self, arch):
14111402
built_wheels = []
14121403
with current_directory(build_dir):
14131404
shprint(
1414-
sh.Command(self.ctx.python_recipe.python_exe), *build_args, _env=env
1405+
sh.Command(self.real_hostpython_location), *build_args, _env=env
14151406
)
14161407
built_wheels = [realpath(whl) for whl in glob.glob("dist/*.whl")]
14171408
self.install_wheel(arch, built_wheels)
@@ -1523,8 +1514,6 @@ class RustCompiledComponentsRecipe(PyProjectRecipe):
15231514
"x86": "i686-linux-android",
15241515
}
15251516

1526-
call_hostpython_via_targetpython = False
1527-
15281517
def get_recipe_env(self, arch, **kwargs):
15291518
env = super().get_recipe_env(arch, **kwargs)
15301519

pythonforandroid/recipes/hostpython3/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _exe_name(self):
6969
@property
7070
def python_exe(self):
7171
'''Returns the full path of the hostpython executable.'''
72-
return join(self.get_path_to_python(), self._exe_name)
72+
return join(self.local_bin, self._exe_name)
7373

7474
def get_recipe_env(self, arch=None):
7575
env = os.environ.copy()
@@ -112,9 +112,13 @@ def site_root(self):
112112
def site_bin(self):
113113
return join(self.site_root, self.site_dir, "bin")
114114

115+
@property
116+
def local_dir(self):
117+
return join(self.site_root, "usr/local/")
118+
115119
@property
116120
def local_bin(self):
117-
return join(self.site_root, "usr/local/bin/")
121+
return join(self.local_dir, "bin")
118122

119123
@property
120124
def site_dir(self):
@@ -164,7 +168,8 @@ def build_arch(self, arch):
164168
build_configured = False
165169
with current_directory(build_dir):
166170
if not Path('config.status').exists():
167-
shprint(sh.Command(join(recipe_build_dir, 'configure')), _env=env)
171+
shprint(sh.Command(join(recipe_build_dir, 'configure')),
172+
'--prefix', self.local_dir, _env=env)
168173
build_configured = True
169174

170175
with current_directory(recipe_build_dir):
@@ -184,7 +189,7 @@ def build_arch(self, arch):
184189
)
185190

186191
shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir, _env=env)
187-
192+
shprint(sh.make, 'install', _env=env)
188193
# make a copy of the python executable giving it the name we want,
189194
# because we got different python's executable names depending on
190195
# the fs being case-insensitive (Mac OS X, Cygwin...) or
@@ -200,9 +205,8 @@ def build_arch(self, arch):
200205
self.ctx.hostpython = self.python_exe
201206

202207
if build_configured:
203-
204208
shprint(
205-
sh.Command(self.python_exe), "-m", "ensurepip", "--root", self.site_root, "-U",
209+
sh.Command(self.python_exe), "-m", "ensurepip", "-U",
206210
_env={"HOME": "/tmp", "PATH": self.local_bin}
207211
)
208212
self.fix_pip_shebangs()

0 commit comments

Comments
 (0)