mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 04:50:20 -06:00
Merge pull request #785 from pre-commit/better_trace
Improve not found error with script paths (`./exe`)
This commit is contained in:
@@ -42,16 +42,21 @@ def find_executable(exe, _environ=None):
|
||||
return None
|
||||
|
||||
|
||||
def normexe(orig_exe):
|
||||
if os.sep not in orig_exe:
|
||||
exe = find_executable(orig_exe)
|
||||
def normexe(orig):
|
||||
def _error(msg):
|
||||
raise ExecutableNotFoundError('Executable `{}` {}'.format(orig, msg))
|
||||
|
||||
if os.sep not in orig and (not os.altsep or os.altsep not in orig):
|
||||
exe = find_executable(orig)
|
||||
if exe is None:
|
||||
raise ExecutableNotFoundError(
|
||||
'Executable `{}` not found'.format(orig_exe),
|
||||
)
|
||||
_error('not found')
|
||||
return exe
|
||||
elif not os.access(orig, os.X_OK):
|
||||
_error('not found')
|
||||
elif os.path.isdir(orig):
|
||||
_error('is a directory')
|
||||
else:
|
||||
return orig_exe
|
||||
return orig
|
||||
|
||||
|
||||
def normalize_cmd(cmd):
|
||||
|
||||
Reference in New Issue
Block a user