commit: ce86ddecf168af06926f95092f29fa19c1f3885a
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 3 10:46:02 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Mar 3 12:09:58 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ce86ddec
bin_entry_point: rewrite python shebangs for venv
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/util/bin_entry_point.py | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/lib/portage/util/bin_entry_point.py
b/lib/portage/util/bin_entry_point.py
index 7f2ee3849..ce95231eb 100644
--- a/lib/portage/util/bin_entry_point.py
+++ b/lib/portage/util/bin_entry_point.py
@@ -3,6 +3,7 @@
__all__ = ["bin_entry_point"]
+import re
import sys
from portage.const import PORTAGE_BIN_PATH
@@ -17,7 +18,16 @@ 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):
- sys.argv[0] = script_path
+ with open(script_path, "rt") as f:
+ shebang = f.readline()
+ python_match = re.search(r"/python\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)
os.execvp(sys.argv[0], sys.argv)
else:
print("File not found:", script_path, file=sys.stderr)