From 7a02dd539e8e3ddde31fb2c1097434473199c3a4 Mon Sep 17 00:00:00 2001 From: Valentin Niess Date: Mon, 6 Apr 2020 23:57:48 +0200 Subject: [PATCH] Forward installed scripts to us/bin (& uninstall) --- python_appimage/data/sitecustomize.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/python_appimage/data/sitecustomize.py b/python_appimage/data/sitecustomize.py index 11932aa..e48fa52 100644 --- a/python_appimage/data/sitecustomize.py +++ b/python_appimage/data/sitecustomize.py @@ -32,7 +32,11 @@ clean_path() def patch_pip_install(): '''Change absolute shebangs to relative ones following a `pip` install ''' - if ('pip' in sys.modules) and ('install' in sys.argv[1:]): + if not 'pip' in sys.modules: + return + + args = sys.argv[1:] + if 'install' in args: for exe in os.listdir(sys.prefix + '/bin'): path = os.path.join(sys.prefix, 'bin', exe) @@ -73,7 +77,23 @@ def patch_pip_install(): f.write(' '.join(cmd) + '\n') f.write(body) except IOError: - pass + continue + + usr_dir = os.path.join(sys.prefix, '../../usr/bin') + usr_exe = os.path.join(usr_dir, exe) + if os.path.exists(usr_exe): + continue + relpath = os.path.relpath(path, usr_dir) + os.symlink(relpath, usr_exe) + + elif 'uninstall' in args: + usr_dir = os.path.join(sys.prefix, '../../usr/bin') + for exe in os.listdir(usr_dir): + path = os.path.join(usr_dir, exe) + if (not os.path.islink(path)) or \ + os.path.exists(os.path.realpath(path)): + continue + os.remove(path) atexit.register(patch_pip_install)