This commit is contained in:
Kovid Goyal 2021-12-09 11:51:10 +05:30
parent f41584c83b
commit 77b15bf73f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -627,9 +627,14 @@ def system_paths_on_macos() -> Tuple[str, ...]:
def which(name: str, only_system: bool = False) -> Optional[str]: def which(name: str, only_system: bool = False) -> Optional[str]:
import shutil
if os.sep in name: if os.sep in name:
return name return name
import shutil
from .fast_data_types import get_options
opts: Optional[Options] = None
with suppress(RuntimeError):
opts = get_options()
paths = [] paths = []
ep = os.environ.get('PATH') ep = os.environ.get('PATH')
if ep: if ep:
@ -651,12 +656,7 @@ def which(name: str, only_system: bool = False) -> Optional[str]:
if ans: if ans:
return ans return ans
tried_paths |= set(system_paths) tried_paths |= set(system_paths)
if only_system: if only_system or opts is None:
return None
from .fast_data_types import get_options
try:
opts = get_options()
except RuntimeError:
return None return None
shell_env = read_shell_environment(opts) shell_env = read_shell_environment(opts)
for xenv in (shell_env, opts.env): for xenv in (shell_env, opts.env):