Skip to content

Commit

Permalink
Call Cython via python -m Cython rather than system-wide binary
Browse files Browse the repository at this point in the history
- call Cython via `python -m Cython` to avoid picking one not matching
  the current python version (which can happen if just calling `Cython`)
- this should fix #1885
  • Loading branch information
Jonas Thiem committed Jul 28, 2019
1 parent 308df31 commit 0d35f86
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
10 changes: 0 additions & 10 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API)


def get_cython_path():
for cython_fn in ("cython", "cython3", "cython2", "cython-2.7"):
cython = sh.which(cython_fn)
if cython:
return cython
raise BuildInterruptingException('No cython binary found.')


def get_ndk_platform_dir(ndk_dir, ndk_api, arch):
ndk_platform_dir_exists = True
platform_dir = arch.platform_dir
Expand Down Expand Up @@ -111,7 +103,6 @@ class Context(object):
use_setup_py = False

ccache = None # whether to use ccache
cython = None # the cython interpreter name

ndk_platform = None # the ndk platform directory

Expand Down Expand Up @@ -374,7 +365,6 @@ def prepare_build_environment(self,
if not self.ccache:
info('ccache is missing, the build will not be optimized in the '
'future.')
self.cython = get_cython_path()

# This would need to be changed if supporting multiarch APKs
arch = self.archs[0]
Expand Down
8 changes: 6 additions & 2 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,12 @@ def cythonize_file(self, env, build_dir, filename):
del cyenv['PYTHONPATH']
if 'PYTHONNOUSERSITE' in cyenv:
cyenv.pop('PYTHONNOUSERSITE')
cython_command = sh.Command(self.ctx.cython)
shprint(cython_command, filename, *self.cython_args, _env=cyenv)
cython_command = sh.Command(
"python" +
self.ctx.python_recipe.major_minor_version_string.split(".")[0]
)
shprint(cython_command, "-m", "Cython",
filename, *self.cython_args, _env=cyenv)

def cythonize_build(self, env, build_dir="."):
if not self.cythonize:
Expand Down
3 changes: 0 additions & 3 deletions tests/test_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def test_create(self):
) as m_get_toolchain_versions, mock.patch(
'pythonforandroid.build.get_ndk_platform_dir'
) as m_get_ndk_platform_dir, mock.patch(
'pythonforandroid.build.get_cython_path'
) as m_get_cython_path, mock.patch(
'pythonforandroid.toolchain.build_recipes'
) as m_build_recipes, mock.patch(
'pythonforandroid.bootstraps.service_only.'
Expand All @@ -84,7 +82,6 @@ def test_create(self):
mock.call('/tmp/android-sdk')]
assert m_get_toolchain_versions.call_args_list == [
mock.call('/tmp/android-ndk', mock.ANY)]
assert m_get_cython_path.call_args_list == [mock.call()]
build_order = [
'hostpython3', 'libffi', 'openssl', 'sqlite3', 'python3',
'genericndkbuild', 'setuptools', 'six', 'pyjnius', 'android',
Expand Down

0 comments on commit 0d35f86

Please sign in to comment.