Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call Cython via python -m Cython rather than system-wide binary #1937

Merged
1 commit merged into from Aug 4, 2019
Merged

Call Cython via python -m Cython rather than system-wide binary #1937

1 commit merged into from Aug 4, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jul 28, 2019

This changes calls to Cython to python -m Cython to avoid picking one not matching the current python version (which can happen if just calling Cython). This should fix #1885

@ghost ghost added the bug label Jul 28, 2019
inclement
inclement previously approved these changes Jul 28, 2019
Copy link
Member

@inclement inclement left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I never thought about doing it this way. It does seem more correct.

The main reason for never worrying about it (and in fact explicitly searching for any cython regardless of Python version) is that it almost never matters, for a long time I only had one of them installed. I vaguely remember some stronger reason to think it was okay but I don't remember what. I have the impression that cython2/cython3 are beginning to be more likely to behave differently though, we had some other issue about it, so even more reason to make the change.

@@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we still add a check here for Cython being available, or a BuildInterruptingException if not?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point! Sure, that would be possible, let me have a look at it

Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement, I've made a couple of comments

Dockerfile.py3 Outdated
@@ -107,6 +107,7 @@ RUN dpkg --add-architecture i386 \
libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 \
zip zlib1g-dev zlib1g:i386 \
&& apt -y autoremove
RUN ${RETRY} pip3 install -U Cython
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pythonforandroid/build.py Show resolved Hide resolved
pythonforandroid/recipe.py Show resolved Hide resolved
@@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this isn't a cython command, but a python command, correct?
The cython however comes later once you adds the -m cython to it few lines below

@ghost ghost changed the title [WIP] Call Cython via python -m Cython rather than system-wide binary Call Cython via python -m Cython rather than system-wide binary Jul 29, 2019
Dockerfile.py3 Outdated
@@ -133,4 +135,5 @@ USER ${USER}
# install python-for-android from current branch
RUN virtualenv --python=python3 venv \
&& . venv/bin/activate \
&& pip3 install -U Cython \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm true I may have interpreted that one error situation wrong, let me try it might work without that 👍

Copy link
Author

@ghost ghost Aug 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup system-wide is enough, apparently 😂 well-spotted!

Oops, checked wrong build result. The system-wide is actually as it looks like mostly useless (maybe also including for any other usage?) because we launch in a virtualenv with no site-packages access, and as a result there appears to be no access to any of these outside system pacakges. The new code to call Cython of this pull request calls via python3/python2 which maps back to the virtualenv python (since venv/bin/activate changes $PATH accordingly) so it really needs to be available in the virtualenv to work.

Copy link
Member

@AndreMiras AndreMiras Aug 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, thanks for investigating!
Then maybe we should ditch the system one?
Edit: just saw that you already did, thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, I just saw the build is failing for Python2.
https://travis-ci.org/kivy/python-for-android/jobs/567481453

2943  RAN: /usr/bin/python2 -m Cython.Build.Cythonize ./jnius/jnius.pyx
2944
2945  STDOUT:
2946/usr/bin/python2: No module named Cython.Build

So that's properly weird and annoying. Basically it means if we want to support the "Python2 basic" apk build in the CI, we do need the system cython on python2. While only having the venv cython3. That would look kinda inconsistent in the Dockerfile, but with some comments that should make it.
So basically we want to have:

RUN pip2 install --upgrade Cython==0.28.6

And also in the venv:

&& pip3 install --upgrade Cython==0.28.6

By the way, let's take the opportunity to make them consistent.

  • uppercase Cython because that's it's naming on pypi
  • long argument --upgrade because we love explicit
  • explicit "officially p4a tested" version 0.28.6 in all places (eventually via variable)

AndreMiras
AndreMiras previously approved these changes Aug 4, 2019
Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks @Jonast 💪
Side note:
I would not have bothered maintaining the Dockerfile.py2, at some point we should drop it I think.
Basically it's used to reproduce/address host Python2 issues, but we're dropping its support

@ghost
Copy link
Author

ghost commented Aug 4, 2019

I just realized I never tested if this actually fixes #1885, even though I believe this is the "more correct" way to call it in any case. Does anyone have a test environment for that around? Otherwise I suppose I should set myself one up real quick and actually give that a try

Dockerfile.py3 Outdated Show resolved Hide resolved
@AndreMiras
Copy link
Member

even though I believe this is the "more correct" way to call it in any case

Yes same feeling here, so we should make it into the tree in any case (after the build passes of course)

- 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 #1885
Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top thanks @Jonast 👍

@AndreMiras
Copy link
Member

Good job! Feel free to merge once the build turns ✔️

@ghost ghost merged commit c261db5 into kivy:develop Aug 4, 2019
@ghost ghost deleted the fix-cython-calls branch August 4, 2019 14:16
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: must be str, not bytes
2 participants