-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fixes hostpython build with macOS venv #2159
Fixes hostpython build with macOS venv #2159
Conversation
pythonforandroid/build.py
Outdated
@@ -764,7 +764,7 @@ def run_pymodules_install(ctx, modules, project_dir=None, | |||
shprint(host_python, '-m', 'venv', 'venv') | |||
|
|||
# Prepare base environment and upgrade pip: | |||
base_env = copy.copy(os.environ) | |||
base_env = dict(copy.copy(os.environ)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has nothing to do with the macOS venv fix, but it suddenly started failing (develop branch included). So I included the fix in the PR but dedicated commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 but you created a separate PR right #2160? nevermind, it's fine to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I did separate it in case this PR would take longer to be reviewed/merged.
I've now merged the other one so I'll rebase and address some of the other comments you made, thanks!
9438b08
to
b8f300f
Compare
cd testapps/on_device_unit_tests/ && \ | ||
python3 setup.py apk --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \ | ||
--arch=$($@_APP_ARCH) | ||
|
||
clean: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 Glad that we can remove this!
@@ -35,6 +35,8 @@ class Hostpython3Recipe(Recipe): | |||
'''The default url to download our host python recipe. This url will | |||
change depending on the python version set in attribute :attr:`version`.''' | |||
|
|||
patches = ('patches/pyconfig_detection.patch',) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the new patch working/needed for Python 3.7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I've only verified for 3.8 to be honest. I can apply it to 3.8 only to be safe
name = 'python3' | ||
|
||
patches = [ | ||
('patches/pyconfig_detection.patch'), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to patch python3 recipe as well? I understand that the problem is with hostpython and MacOs during build stage...:thinking:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I also thought, but then I saw the build failing with the exact same issue so I decided to add it there as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, sure that macOs Users will be delighted with this.
Thanks!!! 😄
This has been fixed also upstream, apparently: https://bugs.python.org/issue40261 [I went on trying to understand what was happening] |
Very nice to see @rubendibattista ! |
Nice, so in Python 3.8.3 this should be solved 😄 ¡¡¡thanks for the info!!! |
@AndreMiras at least for you was just one day! I spent one week after giving up... I reached that situation of crazyness where I was patching |
@opacam and 3.7.8 |
However this is the change they're applying upstream: python/cpython@5765aca Care to see if it solves the problem also here? |
Maybe it will solve the problem, but I don't have a Mac to test...anyway...if you want to try, the following patch will modify hostpython/python recipes to use the branch you mentioned from CPython 😉 |
Opacam the problem with this approach is it hardcodes the version and people won't be able to use different versions. Plus I'd rather not rely on something not yet release like so. |
Running the freshly compiled python binary from another Python process (e.g. sh module or os.system()) may get wrongly detected as if it was ran directly from the venv. This happens when `pyvenv.cfg` is present (e.g. venv/pyvenv.cfg). It makes `sysconfig.is_python_build()` returns `False` instead of `True` since it's using the compiled interpreter (e.g. ./build-dir/python). https://docs.python.org/3/library/sysconfig.html#sysconfig.is_python_build https://github.com/python/cpython/blob/v3.8.2/Lib/sysconfig.py#L127 This is because the `sys._home` attribute is used during the detection. The issue was first seen in macOS venv which generates the `pyvenv.cfg`. To compare both behaviours, try the following within and without a venv: ```python import os os.system("./build-dir/python -E -c 'import sysconfig; print(sysconfig._sys_home)'") ``` One would return `/usr/local/bin` and the other `None` Refs: - kivy/kivy-ios#401 - kivy#2063
b8f300f
to
38ba1ad
Compare
@@ -35,6 +36,10 @@ class Hostpython3Recipe(Recipe): | |||
'''The default url to download our host python recipe. This url will | |||
change depending on the python version set in attribute :attr:`version`.''' | |||
|
|||
patches = ( | |||
('patches/pyconfig_detection.patch', is_version_lt("3.8.3")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now applying to anything lower than 3.8.3. Since this issue was also impacting some recent version of the 3.7 branch I thought it would be easier to go that way than being ultra ranging inside MINOR and PATCH with a complex expression (given MAJOR.MINOR.PATCH)
@AndreMiras the patch on In any case I could test this. I'll do it ASAP |
OK the patch got rejected, it doesn't seem to apply properly I haven't investigated much, but i think my solution is good enough until 3.8.3 is released. |
@rubendibattista which patch on |
@AndreMiras Ok, let's go with your initial PR. I'll try to see if I can adapt the upstream patch to current versions of Python. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
I found out why the upstream patch didn't apply. It was for the 3.7 branch 😅 |
🔝 |
🔖 v2020.06.02 * Adds missing requests sub dependencies (kivy#2221) * Bumps to Gradle 6.4.1 (kivy#2222) * Bumps to Cython==0.29.19 (kivy#2220) * Updates install and troubleshooting docs (kivy#2219) * Bumps to Ubuntu 20.04 (kivy#2218) * Attempt to improve the issue template (kivy#2217) * Add `opencv_extras` recipe (kivy#2209) * Split logic for build modes & debug symbols (kivy#2213) * Troubleshoot SSL error (kivy#2205) * Remove superfluous recipes fixes (kivy#2202) * Add tests for hostpython3 recipe (kivy#2196) * Fix for 'cannot find setuptools module' (kivy#2195) * Rename `Hostpython3Recipe` class to camel case (kivy#2194) * Fix `test_should_build` (kivy#2193) * Add initial tests for python3 recipe (kivy#2192) * PythonActivityUtil helper for unpacking data (kivy#2189) * Fixes flake8 errors post update (kivy#2191) * Share PythonUtil.java between bootstraps (kivy#2188) * Java code linting using PMD 6.23.0 (kivy#2187) * Deletes deprecated renpy Python{Activity,Service}.java (kivy#2186) * Removes java concurrency/ folder (kivy#2185) * Reuse common AssetExtract.java (kivy#2182) * Use common Hardware.java (kivy#2183) * Moves kamranzafar/ java directory to common/ (kivy#2184) * Updates release documentation (kivy#2177) * Fixes service only unittest loading (kivy#2181) * Narrows some context manager scopes (kivy#2179) * Downgrades to SDL2 2.0.9 (kivy#2180) * Bump to SDL2 2.0.10 & extract .java from SDL2 tarball (kivy#2113) * Adds pygame recipe (kivy#2164) * Adds macOS install instructions (2165) * Removed python2 support mention from README (kivy#2162) * Adding more assets (kivy#2132) * Get --add-source working for dirs in Gradle builds (kivy#2156) * Fixes python build with macOS venv (kivy#2159)
Borrowed from p4a: kivy/python-for-android#2159 Also refs upstream issue: https://bugs.python.org/issue40261 Note that the fix used upstream cannot really be used directly here because the actual system Python is impacted. Adds venv build to CI to check for regressions.
Running the freshly compiled host python binary from another Python
process (e.g. sh module or os.system()) may get wrongly detected as
if it was ran directly from the venv.
This happens when
pyvenv.cfg
is present (e.g. venv/pyvenv.cfg).It makes
sysconfig.is_python_build()
returnsFalse
instead ofTrue
since it's using the compiled interpreter (e.g. ./build-dir/python).
https://docs.python.org/3/library/sysconfig.html#sysconfig.is_python_build
https://github.com/python/cpython/blob/v3.8.2/Lib/sysconfig.py#L127
This is because the
sys._home
attribute is used during the detection.The issue was first seen in macOS venv which generates the
pyvenv.cfg
.To compare both behaviours, try the following within and without a venv:
One would return
/usr/local/bin
and the otherNone
Refs: