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

BLD: Use the correct Python interpreter when running tempita.py #24971

Merged
merged 1 commit into from Oct 21, 2023

Conversation

charris
Copy link
Member

@charris charris commented Oct 21, 2023

Backport of #24970.

When a program located by find_program is executable directly, meson will execute it. If it is a script, its shebang (#!) line will control which interpreter is used. tempita.py specifies a standard shebang line of #!/usr/bin/env python3, so that python3 can be located by PATH lookup.

In cases where python3 as found in the PATH is not correct, such as on systems that have multiple copies of python3 installed when building numpy for one that is not the python3 found by searching PATH, this interpreter will be wrong. When the python3 found by this mechanism doesn't have Cython available, it will cause the numpy build to fail.

With the executable bit removed from tempita.py, meson will scan the script when attempting to execute it, locating the shebang line and substituting the appropriate sys.executable. See numpy/meson programs.py:179.

When a program located by find_program is executable directly, meson
will execute it. If it is a script, its shebang (#!) line will control
which interpreter is used. tempita.py specifies a standard shebang line
of #!/usr/bin/env python3, so that python3 can be located by PATH
lookup.

In cases where python3 as found in the PATH is not correct, such as on
systems that have multiple copies of python3 installed when building
numpy for one that is not the python3 found by searching PATH, this
interpreter will be wrong. When the python3 found by this mechanism
doesn't have Cython available, it will cause the numpy build to fail.

With the executable bit removed from tempita.py, meson will scan the
script when attempting to execute it, locating the shebang line and
substituting the appropriate sys.executable. See
https://github.com/numpy/meson/blob/22df45a31981874310a78dde0df59a6a7c5ebb29/mesonbuild/programs.py#L179.
@charris charris added 08 - Backport Used to tag backport PRs 36 - Build Build related PR labels Oct 21, 2023
@charris charris added this to the 1.26.2 release milestone Oct 21, 2023
@lazka
Copy link
Contributor

lazka commented Oct 21, 2023

Wouldn't it be more clear to explicitly use the target Python like

use_ilp64 = run_command(py,
?

@rgommers
Copy link
Member

Wouldn't it be more clear to explicitly use the target Python like

That's a problem for cross-compiling; the shebang is the recommended approach by Meson. I'd like to get rid of the remaining run_command(py, ... invocations.

@rgommers
Copy link
Member

This is a backport PR, so I'll merge this. Happy to continue the conversation around run_command of course.

@rgommers rgommers merged commit aca4819 into numpy:maintenance/1.26.x Oct 21, 2023
84 of 87 checks passed
@charris charris deleted the backport-24970 branch October 21, 2023 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
08 - Backport Used to tag backport PRs 36 - Build Build related PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants