From 013980d8398b1010c0e3414e5d1f06030fa557d2 Mon Sep 17 00:00:00 2001 From: Calvin Walton Date: Mon, 25 Mar 2024 15:17:59 -0400 Subject: [PATCH] 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. --- gio/gdbus-2.0/codegen/gdbus-codegen.in | 2 +- gio/gdbus-2.0/codegen/meson.build | 2 +- glib/gtester-report.in | 2 +- glib/meson.build | 2 +- gobject/glib-genmarshal.in | 2 +- gobject/glib-mkenums.in | 2 +- gobject/meson.build | 2 +- meson.build | 2 -- 8 files changed, 7 insertions(+), 9 deletions(-) diff --git a/gio/gdbus-2.0/codegen/gdbus-codegen.in b/gio/gdbus-2.0/codegen/gdbus-codegen.in index 67d367543..8f9f3108c 100755 --- a/gio/gdbus-2.0/codegen/gdbus-codegen.in +++ b/gio/gdbus-2.0/codegen/gdbus-codegen.in @@ -1,4 +1,4 @@ -#!/usr/bin/env @PYTHON@ +#!@PYTHON@ # GDBus - GLib D-Bus Library # diff --git a/gio/gdbus-2.0/codegen/meson.build b/gio/gdbus-2.0/codegen/meson.build index 6d19cd4ba..a8dfd6287 100644 --- a/gio/gdbus-2.0/codegen/meson.build +++ b/gio/gdbus-2.0/codegen/meson.build @@ -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 diff --git a/glib/gtester-report.in b/glib/gtester-report.in index b8291d2b4..0745d53d0 100644 --- a/glib/gtester-report.in +++ b/glib/gtester-report.in @@ -1,4 +1,4 @@ -#! /usr/bin/env @PYTHON@ +#!@PYTHON@ # GLib Testing Framework Utility -*- Mode: python; -*- # Copyright (C) 2007 Imendio AB # Authors: Tim Janik diff --git a/glib/meson.build b/glib/meson.build index d2efebadc..24cbb664d 100644 --- a/glib/meson.build +++ b/glib/meson.build @@ -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', diff --git a/gobject/glib-genmarshal.in b/gobject/glib-genmarshal.in index aa5af43bd..0578b741f 100755 --- a/gobject/glib-genmarshal.in +++ b/gobject/glib-genmarshal.in @@ -1,4 +1,4 @@ -#!/usr/bin/env @PYTHON@ +#!@PYTHON@ # pylint: disable=too-many-lines, missing-docstring, invalid-name diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in index e10b910f0..7e794e96d 100755 --- a/gobject/glib-mkenums.in +++ b/gobject/glib-mkenums.in @@ -1,4 +1,4 @@ -#!/usr/bin/env @PYTHON@ +#!@PYTHON@ # If the code below looks horrible and unpythonic, do not panic. # diff --git a/gobject/meson.build b/gobject/meson.build index 2129aaf8a..78b732bf3 100644 --- a/gobject/meson.build +++ b/gobject/meson.build @@ -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( diff --git a/meson.build b/meson.build index c741a0c32..5328adc3a 100644 --- a/meson.build +++ b/meson.build @@ -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 ' -python_name = 'python3' python_version = python.language_version() python_version_req = '>=3.7'