commit:     19c27a2471c78d5e17b14325477fee60ead791e5
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 30 13:19:10 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug  2 06:31:20 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=19c27a24

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 <AT> gentoo.org>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 NEWS                                |  3 +++
 lib/portage/util/bin_entry_point.py | 18 +++++-------------
 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)

Reply via email to