Skip to content

Commit 542684e

Browse files
author
Jonas Thiem
committed
Call Cython via python -m Cython rather than system-wide binary
- call Cython via `python -m Cython` to avoid picking one not matching the current python version (which can happen if just calling `Cython`) - make sure Cython is present in Dockerfile.py3 and Dockerfile.py2 - make sure python 2 is available in Dockerfile.py3 - this should fix kivy#1885
1 parent e21cd8b commit 542684e

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

Dockerfile.py2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ RUN usermod -append --groups sudo ${USER}
122122
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
123123

124124

125-
RUN pip install --upgrade cython==0.28.6
126-
127125
WORKDIR ${WORK_DIR}
128126
COPY --chown=user:user . ${WORK_DIR}
129127
RUN chown --recursive ${USER} ${ANDROID_SDK_HOME}
@@ -132,4 +130,5 @@ USER ${USER}
132130
# install python-for-android from current branch
133131
RUN virtualenv --python=python venv \
134132
&& . venv/bin/activate \
133+
&& pip install --upgrade cython==0.28.6 \
135134
&& pip install -e .

Dockerfile.py3

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ENV WORK_DIR="${HOME_DIR}" \
9494
# install system dependencies
9595
RUN ${RETRY} apt -y install -qq --no-install-recommends \
9696
python3 virtualenv python3-pip python3-venv \
97-
wget lbzip2 patch sudo \
97+
wget lbzip2 patch sudo python python-pip \
9898
&& apt -y autoremove
9999

100100
# build dependencies
@@ -122,8 +122,8 @@ RUN useradd --create-home --shell /bin/bash ${USER}
122122
RUN usermod -append --groups sudo ${USER}
123123
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
124124

125-
126-
RUN pip3 install --upgrade cython==0.28.6
125+
# install cython for python 2 (for python 3 it's inside the venv)
126+
RUN pip2 install --upgrade Cython==0.28.6
127127

128128
WORKDIR ${WORK_DIR}
129129
COPY --chown=user:user . ${WORK_DIR}
@@ -133,4 +133,5 @@ USER ${USER}
133133
# install python-for-android from current branch
134134
RUN virtualenv --python=python3 venv \
135135
&& . venv/bin/activate \
136+
&& pip3 install --upgrade Cython==0.28.6 \
136137
&& pip3 install -e .

pythonforandroid/build.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API)
2828

2929

30-
def get_cython_path():
31-
for cython_fn in ("cython", "cython3", "cython2", "cython-2.7"):
32-
cython = sh.which(cython_fn)
33-
if cython:
34-
return cython
35-
raise BuildInterruptingException('No cython binary found.')
36-
37-
3830
def get_ndk_platform_dir(ndk_dir, ndk_api, arch):
3931
ndk_platform_dir_exists = True
4032
platform_dir = arch.platform_dir
@@ -111,7 +103,6 @@ class Context(object):
111103
use_setup_py = False
112104

113105
ccache = None # whether to use ccache
114-
cython = None # the cython interpreter name
115106

116107
ndk_platform = None # the ndk platform directory
117108

@@ -374,7 +365,14 @@ def prepare_build_environment(self,
374365
if not self.ccache:
375366
info('ccache is missing, the build will not be optimized in the '
376367
'future.')
377-
self.cython = get_cython_path()
368+
try:
369+
subprocess.check_output([
370+
"python3", "-m", "cython", "--help",
371+
])
372+
except subprocess.CalledProcessError:
373+
warning('Cython for python3 missing. If you are building for '
374+
' a python 3 target (which is the default)'
375+
' then THINGS WILL BREAK.')
378376

379377
# This would need to be changed if supporting multiarch APKs
380378
arch = self.archs[0]

pythonforandroid/recipe.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,11 @@ def cythonize_file(self, env, build_dir, filename):
10241024
del cyenv['PYTHONPATH']
10251025
if 'PYTHONNOUSERSITE' in cyenv:
10261026
cyenv.pop('PYTHONNOUSERSITE')
1027-
cython_command = sh.Command(self.ctx.cython)
1028-
shprint(cython_command, filename, *self.cython_args, _env=cyenv)
1027+
python_command = sh.Command("python{}".format(
1028+
self.ctx.python_recipe.major_minor_version_string.split(".")[0]
1029+
))
1030+
shprint(python_command, "-m", "Cython.Build.Cythonize",
1031+
filename, *self.cython_args, _env=cyenv)
10291032

10301033
def cythonize_build(self, env, build_dir="."):
10311034
if not self.cythonize:

tests/test_toolchain.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ def test_create(self):
6868
) as m_get_toolchain_versions, mock.patch(
6969
'pythonforandroid.build.get_ndk_platform_dir'
7070
) as m_get_ndk_platform_dir, mock.patch(
71-
'pythonforandroid.build.get_cython_path'
72-
) as m_get_cython_path, mock.patch(
7371
'pythonforandroid.toolchain.build_recipes'
7472
) as m_build_recipes, mock.patch(
7573
'pythonforandroid.bootstraps.service_only.'
@@ -84,7 +82,6 @@ def test_create(self):
8482
mock.call('/tmp/android-sdk')]
8583
assert m_get_toolchain_versions.call_args_list == [
8684
mock.call('/tmp/android-ndk', mock.ANY)]
87-
assert m_get_cython_path.call_args_list == [mock.call()]
8885
build_order = [
8986
'hostpython3', 'libffi', 'openssl', 'sqlite3', 'python3',
9087
'genericndkbuild', 'setuptools', 'six', 'pyjnius', 'android',

0 commit comments

Comments
 (0)