aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@gentoo.org>2023-07-30 14:19:10 +0100
committerSam James <sam@gentoo.org>2023-08-02 07:31:20 +0100
commit19c27a2471c78d5e17b14325477fee60ead791e5 (patch)
treebf6dfca45e5a9ae7b458f0c81d4ed915f1e77a02
parentMake non-Python (s)bin scripts use other scripts from the same directory (diff)
downloadportage-19c27a2471c78d5e17b14325477fee60ead791e5.tar.gz
portage-19c27a2471c78d5e17b14325477fee60ead791e5.tar.bz2
portage-19c27a2471c78d5e17b14325477fee60ead791e5.zip
Use the correct library path when launching scripts directly from a venv
It's not clear what bin_entry_point.sh was trying to do before. The regular expression didn't appear to match any likely shebang. The wrapper already runs under the desired Python, so we only need to use sys.executable, which points to the venv's python symlink. We don't need to worry about handling non-Python scripts any more either as the new Meson-based build system just installs these directly to bin rather than creating an entrypoint for them. Any Python-based Portage scripts they execute are now tried from the same directory first and will therefore use the correct environment, as above. Signed-off-by: James Le Cuirot <chewi@gentoo.org> Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--NEWS3
-rw-r--r--lib/portage/util/bin_entry_point.py18
2 files changed, 8 insertions, 13 deletions
diff --git a/NEWS b/NEWS
index 0e3541af4..53db165e8 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,9 @@ Bug fixes:
* Ensure non-Python (s)bin scripts launch other Python-based Portage scripts
using the same environment.
+* Use the correct Python library path when launching scripts directly from a
+ virtual environment.
+
portage-3.0.49 (2023-06-21)
--------------
diff --git a/lib/portage/util/bin_entry_point.py b/lib/portage/util/bin_entry_point.py
index bb012b6b7..efa8b17b7 100644
--- a/lib/portage/util/bin_entry_point.py
+++ b/lib/portage/util/bin_entry_point.py
@@ -1,9 +1,8 @@
-# Copyright 2021 Gentoo Authors
+# Copyright 2021-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = ["bin_entry_point"]
-import re
import sys
from portage.const import PORTAGE_BIN_PATH
@@ -18,17 +17,10 @@ def bin_entry_point():
"""
script_path = os.path.join(PORTAGE_BIN_PATH, os.path.basename(sys.argv[0]))
if os.access(script_path, os.X_OK):
- with open(script_path) as f:
- shebang = f.readline()
- python_match = re.search(r"/python[\d\.]*\s+([^/]*)\s+$", shebang)
- if python_match:
- sys.argv = [
- os.path.join(os.path.dirname(sys.argv[0]), "python"),
- python_match.group(1),
- script_path,
- ] + sys.argv[1:]
- os.execvp(sys.argv[0], sys.argv)
- sys.argv[0] = script_path
+ sys.argv = [
+ sys.executable,
+ script_path,
+ ] + sys.argv[1:]
os.execvp(sys.argv[0], sys.argv)
else:
print("File not found:", script_path, file=sys.stderr)