From ae27bf1a3ae94f64b86839d7fe4b27d7ce406750 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Thu, 14 Mar 2024 03:15:47 -0700 Subject: [PATCH] resources: search for commands sibling to the running script When Cola is installed directly into C:\Python3.12 on Windows then the correct path to git-cola-sequence-editor was not being used. Look in the same director as the current sprint when attempting to find git-cola-sequence-editor. This makes cola rely less on the physical structure of the install tree by checking for locations relative to itself. Closes: #1385 Reported-by: Stanislaw Halik Signed-off-by: David Aguilar --- CHANGES.rst | 6 ++++++ cola/resources.py | 45 ++++++++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4fcf8078..a61f7934 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,6 +22,12 @@ Usability, bells and whistles * The `cola.refreshonfocus` and `cola.inotify` configuration settings are now accessible from the `git cola config` settings dialog. +Fixes +----- +* The `git-cola-sequence-editor` Rebase Editor will now be found correctly + in more situatios on Windows. + (`#1385 `_) + .. _v4.6.1: diff --git a/cola/resources.py b/cola/resources.py index f5f555db..a246064d 100644 --- a/cola/resources.py +++ b/cola/resources.py @@ -1,5 +1,6 @@ """Functions for finding cola resources""" import os +import sys import webbrowser from . import core @@ -39,25 +40,43 @@ def prefix(*args): return os.path.join(get_prefix(), *args) +def sibling_bindir(*args): + """Return a command sibling to sys.argv[0]""" + relative_bindir = os.path.dirname(sys.argv[0]) + return os.path.join(relative_bindir, *args) + + def command(name): """Return a command from the bin/ directory""" if compat.WIN32: + # On Windows we have to support being installed via the pynsist installation + # layout and the pip-installed layout. We also have check for .exe launchers + # and prefer them when present. + sibling = sibling_bindir(name) + scripts = prefix('Scripts', name) + bindir = prefix('bin', name) # Check for "${name}.exe" on Windows. - exe_path = prefix('bin', '%s.exe' % name) - scripts_exe_path = prefix('Scripts', '%s.exe' % name) - scripts_path = prefix('Scripts', name) - path = prefix('bin', name) - - if core.exists(exe_path): - result = exe_path - elif core.exists(scripts_exe_path): - result = scripts_exe_path - elif core.exists(scripts_path): - result = scripts_path + exe = f'{name}.exe' + sibling_exe = sibling_bindir(exe) + scripts_exe = prefix('Scripts', exe) + bindir_exe = prefix('bin', exe) + if core.exists(sibling_exe): + result = sibling + elif core.exists(sibling): + result = sibling + elif core.exists(bindir_exe): + result = bindir_exe + elif core.exists(scripts_exe): + result = scripts_exe + elif core.exists(scripts): + result = scripts else: - result = path + result = bindir else: - result = prefix('bin', name) + result = sibling_bindir(name) + if not core.exists(result): + result = prefix('bin', name) + return result -- 2.11.4.GIT