From eac9a7ae911fbe47b53f86366dba2d46abddf537 Mon Sep 17 00:00:00 2001 From: Valentin Niess Date: Tue, 7 Apr 2020 22:18:45 +0200 Subject: [PATCH] Improve sync of usr/bin and opt/pythonX.Y/bin --- python_appimage/data/sitecustomize.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/python_appimage/data/sitecustomize.py b/python_appimage/data/sitecustomize.py index e48fa52..182944f 100644 --- a/python_appimage/data/sitecustomize.py +++ b/python_appimage/data/sitecustomize.py @@ -29,6 +29,11 @@ def clean_path(): clean_path() +_bin_at_start = os.listdir(sys.prefix + '/bin') +'''Initial content of the bin/ directory +''' + + def patch_pip_install(): '''Change absolute shebangs to relative ones following a `pip` install ''' @@ -38,6 +43,9 @@ def patch_pip_install(): args = sys.argv[1:] if 'install' in args: for exe in os.listdir(sys.prefix + '/bin'): + if exe in _bin_at_start: + continue + path = os.path.join(sys.prefix, 'bin', exe) if (not os.path.isfile(path)) or (not os.access(path, os.X_OK)) or \ @@ -45,6 +53,12 @@ def patch_pip_install(): exe.endswith('.pyc') or exe.endswith('.pyo'): continue + usr_dir = os.path.join(sys.prefix, '../../usr/bin') + usr_exe = os.path.join(usr_dir, exe) + if not os.path.exists(usr_exe): + relpath = os.path.relpath(path, usr_dir) + os.symlink(relpath, usr_exe) + try: with open(path, 'r') as f: header = f.read(2) @@ -79,13 +93,6 @@ def patch_pip_install(): except IOError: 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):