diff options
author | Zac Medico <zmedico@gentoo.org> | 2021-03-03 02:46:02 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2021-03-03 04:09:58 -0800 |
commit | ce86ddecf168af06926f95092f29fa19c1f3885a (patch) | |
tree | 3e5c275d299f46b4952af2c021c398fa11ae027e /lib | |
parent | setup.py: prefix repos.conf paths for venv (diff) | |
download | portage-ce86ddecf168af06926f95092f29fa19c1f3885a.tar.gz portage-ce86ddecf168af06926f95092f29fa19c1f3885a.tar.bz2 portage-ce86ddecf168af06926f95092f29fa19c1f3885a.zip |
bin_entry_point: rewrite python shebangs for venv
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/portage/util/bin_entry_point.py | 12 |
1 files changed, 11 insertions, 1 deletions
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) |