Skip to content

Commit 3b631b1

Browse files
committed
Merge pull request kivy#525 from kived/pythonpath-fix
pythonpath and setup.py build fixes
2 parents 607efcc + 39ae052 commit 3b631b1

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

pythonforandroid/toolchain.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,9 @@ class PythonRecipe(Recipe):
21742174
call_hostpython_via_targetpython is False.
21752175
'''
21762176

2177+
setup_extra_args = []
2178+
'''List of extra arguments to pass to setup.py.'''
2179+
21772180
@property
21782181
def hostpython_location(self):
21792182
if not self.call_hostpython_via_targetpython:
@@ -2215,12 +2218,20 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
22152218
hostpython = sh.Command(self.hostpython_location)
22162219

22172220
if self.call_hostpython_via_targetpython:
2218-
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env)
2221+
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env, *self.setup_extra_args)
22192222
else:
2223+
hppath = join(dirname(self.hostpython_location), 'Lib',
2224+
'site-packages')
2225+
hpenv = env.copy()
2226+
if 'PYTHONPATH' in hpenv:
2227+
hpenv['PYTHONPATH'] = ':'.join(
2228+
[hppath] + hpenv['PYTHONPATH'].split(':'))
2229+
else:
2230+
hpenv['PYTHONPATH'] = hppath
22202231
shprint(hostpython, 'setup.py', 'install', '-O2',
22212232
'--root={}'.format(self.ctx.get_python_install_dir()),
22222233
'--install-lib=lib/python2.7/site-packages',
2223-
_env=env) # AND: Hardcoded python2.7 needs fixing
2234+
_env=hpenv, *self.setup_extra_args) # AND: Hardcoded python2.7 needs fixing
22242235

22252236
# If asked, also install in the hostpython build dir
22262237
if self.install_in_hostpython:
@@ -2246,8 +2257,15 @@ def build_compiled_components(self, arch):
22462257

22472258
env = self.get_recipe_env(arch)
22482259
with current_directory(self.get_build_dir(arch.arch)):
2249-
hostpython = sh.Command(self.ctx.hostpython)
2250-
shprint(hostpython, 'setup.py', 'build_ext', '-v')
2260+
hostpython = sh.Command(self.hostpython_location)
2261+
if self.call_hostpython_via_targetpython:
2262+
shprint(hostpython, 'setup.py', 'build_ext', '-v', *self.setup_extra_args)
2263+
else:
2264+
hppath = join(dirname(self.hostpython_location), 'Lib',
2265+
'site-packages')
2266+
hpenv = {'PYTHONPATH': hppath}
2267+
shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=hpenv, *self.setup_extra_args)
2268+
22512269
build_dir = glob.glob('build/lib.*')[0]
22522270
shprint(sh.find, build_dir, '-name', '"*.o"', '-exec',
22532271
env['STRIP'], '{}', ';', _env=env)

0 commit comments

Comments
 (0)