Use the python found by meson as the interpreter for installed scripts

The python interpreter found by `/usr/bin/env python3` is not
necessarily the same installation as the one that's found by meson's
`pymod.find_installation('python')`. This means that even though meson
is checking that the python installation it found includes the
'packaging' module, the scripts might not have access to that module
when run.

For distribution packaging, it's usually desirable to have python script
interpreters be fully specified paths, rather than use `/usr/bin/env`,
to ensure the scripts run using the expected python installation (i.e.
the one where the python 'packaging' dependency is installed).

The easiest way to fix this is to set the script interpreter to the
`full_path()` of the python interpreter found by meson. The specific
python interpreter that will be used can be selected through the use of
a meson machine file by overriding the "python" program. Many
distributions already have this set up using meson packaging helpers.
This commit is contained in:
Calvin Walton 2024-03-25 15:17:59 -04:00
parent 0888d8d5f2
commit 013980d839
8 changed files with 7 additions and 9 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env @PYTHON@
#!@PYTHON@
# GDBus - GLib D-Bus Library
#

View File

@ -14,7 +14,7 @@ gdbus_codegen_conf = configuration_data()
gdbus_codegen_conf.set('VERSION', glib_version)
gdbus_codegen_conf.set('MAJOR_VERSION', major_version)
gdbus_codegen_conf.set('MINOR_VERSION', minor_version)
gdbus_codegen_conf.set('PYTHON', python_name)
gdbus_codegen_conf.set('PYTHON', python.full_path())
gdbus_codegen_conf.set('DATADIR', glib_datadir)
# Install gdbus-codegen executable

View File

@ -1,4 +1,4 @@
#! /usr/bin/env @PYTHON@
#!@PYTHON@
# GLib Testing Framework Utility -*- Mode: python; -*-
# Copyright (C) 2007 Imendio AB
# Authors: Tim Janik

View File

@ -501,7 +501,7 @@ endif
report_conf = configuration_data()
report_conf.set('GLIB_VERSION', glib_version)
report_conf.set('PYTHON', python_name)
report_conf.set('PYTHON', python.full_path())
configure_file(
input: 'gtester-report.in',
output: 'gtester-report',

View File

@ -1,4 +1,4 @@
#!/usr/bin/env @PYTHON@
#!@PYTHON@
# pylint: disable=too-many-lines, missing-docstring, invalid-name

View File

@ -1,4 +1,4 @@
#!/usr/bin/env @PYTHON@
#!@PYTHON@
# If the code below looks horrible and unpythonic, do not panic.
#

View File

@ -87,7 +87,7 @@ python_tools = [
python_tools_conf = configuration_data()
python_tools_conf.set('VERSION', glib_version)
python_tools_conf.set('PYTHON', python_name)
python_tools_conf.set('PYTHON', python.full_path())
foreach tool: python_tools
tool_bin = configure_file(

View File

@ -2433,8 +2433,6 @@ endif
glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
python = import('python').find_installation(modules: ['packaging'])
# used for '#!/usr/bin/env <name>'
python_name = 'python3'
python_version = python.language_version()
python_version_req = '>=3.7'