Binary builds: If a symlink to the correct kitty executable is already in PATH, dont add the binary bin dir to PATH

This commit is contained in:
Kovid Goyal 2021-10-17 06:29:01 +05:30
parent 93aee3946f
commit f302c2ae39
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -304,10 +304,14 @@ def _main() -> None:
rpath = sys._xoptions.get('bundle_exe_dir')
if rpath:
modify_path = is_macos or getattr(sys, 'frozen', False) or sys._xoptions.get('kitty_from_source') == '1'
if modify_path or not shutil.which('kitty'):
existing_paths = list(filter(None, os.environ.get('PATH', '').split(os.pathsep)))
existing_paths.insert(0, rpath)
os.environ['PATH'] = os.pathsep.join(existing_paths)
existing = shutil.which('kitty')
if modify_path or not existing:
def cpath(x: str) -> str:
return os.path.abspath(os.path.realpath(x))
if not existing or cpath(existing) != cpath(os.path.join(rpath, 'kitty')):
existing_paths = list(filter(None, os.environ.get('PATH', '').split(os.pathsep)))
existing_paths.insert(0, rpath)
os.environ['PATH'] = os.pathsep.join(existing_paths)
args = sys.argv[1:]
if is_macos and os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES', None) == '1':