Use `shutil.which` in favor of our `can_exec`
`shutil.which` totally supports our use cases for `can_exec`, namely
it allows the given `cmd` to be already resolved, and then will only
run a check similar to our `can_exec`.
@@ -829,13 +829,8 @@ class Linter(metaclass=LinterMeta):
# Do not log, `context_sensitive_executable_path` should have
# logged already.
return None
- else:
- # If `cmd` is a method, it can try to find an executable on its own.
- if util.can_exec(which):
- path = which
else:
path = self.which(which)
-
if not path:
logger.warning(
"{} cannot locate '{}'\n"
@@ -869,20 +864,16 @@ class Linter(metaclass=LinterMeta):
wanted_executable, *rest = (
[executable] if isinstance(executable, str) else executable
)
+ resolved_executable = self.which(wanted_executable)
+ if not resolved_executable:
if os.path.isabs(wanted_executable):
- if not util.can_exec(wanted_executable):
- logger.error(
+ message = (
"You set 'executable' to {!r}. "
"However, '{}' does not exist or is not executable. "
.format(executable, wanted_executable)
)
- self.notify_failure()
- raise PermanentError()
-
else:
- resolved_executable = self.which(wanted_executable)
- if not resolved_executable:
- logger.error(
+ message = (
"You set 'executable' to {!r}. "
"However, 'which {}' returned nothing.\n"
"Try setting an absolute path to the binary. "
@@ -890,6 +881,7 @@ class Linter(metaclass=LinterMeta):
"http://www.sublimelinter.com/en/stable/troubleshooting.html"
.format(executable, wanted_executable)
)
+ logger.error(message)
self.notify_failure()
raise PermanentError()
