-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
python module: Respect PATH when python is not given in machine file #12116
base: master
Are you sure you want to change the base?
Conversation
Arrgh. I tried to fix the failing Arch/PyPy tests by amending PATH, as they relied on the old behaviour, but this broke other Python-based tools like g-ir-scanner. Gentoo is smart as it uses its python-exec wrapper or otherwise adjusts the shebang to prevent the PATH from screwing things up like this. Unfortunately, Arch is not that smart. Maybe I'll have to fix the tests with a toolchain file instead, but I'm not sure how easy this will be yet. |
5620596
to
e0c021b
Compare
You should squash both commits into one commit: https://mesonbuild.com/Contributing.html#strategy-for-merging-pull-requests-to-trunk |
e0c021b
to
5001fdb
Compare
You need to update the documentation on how python is found: https://github.com/mesonbuild/meson/blob/master/docs/markdown/Python-module.md |
5001fdb
to
123841f
Compare
LGTM |
7f4a9a3
to
5746229
Compare
CI is killing me and I'm close to giving up. As far as I can tell, the Arch/PyPy job normally builds the boost test case against CPython because meson.build explicitly asks for |
Maybe keep old behavior instead but add option to make the function follow PATH first? This at least will avoid surprises in existing setups. I'm not sure however how it will help Gentoo's case. |
5746229
to
614e63c
Compare
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 talked about this a bit on the gentoo ticket too.
This (the find_installation code for determining which path to query as name_or_path) is some pretty old code and it's been in the back of my mind to fix it for a while. What actually happens is a bit complex:
- find_installation() with no arguments will use meson's own sys.executable
- find_installation('python3') will use whichever python3 executable is on PATH
- find_installation(get_option('python_bin')) ditto except selected by the project option -Dpython_bin=whatever
- setting the binary path for
python = 'whatever'
in a machine file overrides detection
I agree that ideally without arguments we would first look up a python3 from PATH. Also if python3 is explicitly specified but cannot be found (like on crazy FreeBSD systems where they refuse to install a python3 symlink to python3.9 or whatever is current), we should fall back to sys.executable. And the machine file lookup should prefer checking for a versioned python entry before checking for an unversioned entry.
@konsolebox An option seems like an ugly compromise. I'd rather just using a machine file under Gentoo. The only reason I'm proposing this fix is because I feel quite strongly that the existing behaviour makes no sense. The fact that Meson is written in Python is an implementation detail, never mind the Python version it is running under. Muon is a Meson implementation written in C, so what would you expect that to do here? The output of the failing boost test case was confusing me, so I reproduced the failure with PyPy locally and unearthed another bug. If I have also had to exclude the boost test case on Arch/PyPy because it simply cannot work against PyPy. It was previously using CPython, despite Meson itself running under PyPy, but the machine file has changed that. |
614e63c
to
167c72b
Compare
Arch/PyPy has started passing at last. Not sure why the Windows targets are failing now. 😕 |
I've just seen someone else's branch fail on the Windows targets in exactly the same way. Probably not my fault then? |
Known failures. |
167c72b
to
2b33c94
Compare
If `python` was pointing at Python 3 in a machine file, and that Python failed to be recognised as the requested `python2` then a subsequent request for `python3` would fail because the previous failure was cached against the resolved name/path alone.
We should only fall back to the Python interpreter running Meson itself if `python3` is not found in the PATH. A couple of tests relied on the old behaviour. Under Arch/PyPy, the PATH's `python3` does not point to PyPy. Unfortunately, other Python-based tools like g-ir-scanner are installed with a shebang of `/usr/bin/env python3` on Arch, so adjusting the PATH to point to a different Python breaks such tools. We must therefore specify `python` in a machine file instead. We also have to now exclude "test cases/frameworks/1 boost" on Arch/PyPy because it cannot work against PyPy. It was previously using CPython, despite Meson itself running under PyPy, but the machine file has changed that.
2b33c94
to
bac01a0
Compare
CI has stopped playing up. In case it wasn't clear, I have addressed @eli-schwartz's feedback above. Please merge. |
Since distutils was dropped from python 3.12, we can't rely on a standard library implementation for version comparison anymore hence the switch to packaging instead which is essentially supposed to be the replacement. This is problematic though because macOS can have several ways of managing python can result in the build calling the wrong python binary that doesn't have the actual packaging library installed. This commit was a workaround for that since it would fetch the python used to run the build (which is probably the one the user wants), but apparently upstream doesn't like this and it's subject to change*. So instead, let's solve try, and solve this a different way. This reverts commit a57bd8e. *: mesonbuild/meson#12116 (review)
Since distutils was dropped from python 3.12, we can't rely on a standard library implementation for version comparison anymore hence the switch to packaging instead which is essentially supposed to be the replacement. This is problematic though because macOS can have several ways of managing python can result in the build calling the wrong python binary that doesn't have the actual packaging library installed. This commit was a workaround for that since it would fetch the python used to run the build (which is probably the one the user wants), but apparently upstream doesn't like this and it's subject to change*. So instead, let's solve try, and solve this a different way. This reverts commit a57bd8e. *: mesonbuild/meson#12116 (review)
We should only fall back to the Python interpreter running Meson itself if
python3
is not found in the PATH.See Gentoo bug #912051.