mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
fix locate_file (#5600)
* fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
5ccba55738
commit
6b126ddd80
3 changed files with 20 additions and 2 deletions
|
@ -2,7 +2,12 @@ import os
|
||||||
|
|
||||||
from xonsh.environ import Env
|
from xonsh.environ import Env
|
||||||
from xonsh.platform import ON_WINDOWS
|
from xonsh.platform import ON_WINDOWS
|
||||||
from xonsh.procs.executables import get_paths, get_possible_names, locate_executable
|
from xonsh.procs.executables import (
|
||||||
|
get_paths,
|
||||||
|
get_possible_names,
|
||||||
|
locate_executable,
|
||||||
|
locate_file,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_get_possible_names():
|
def test_get_possible_names():
|
||||||
|
@ -44,3 +49,14 @@ def test_locate_executable(tmpdir, xession):
|
||||||
assert locate_executable("file1") is None
|
assert locate_executable("file1") is None
|
||||||
assert locate_executable("file4") is None
|
assert locate_executable("file4") is None
|
||||||
assert locate_executable("file2") is None
|
assert locate_executable("file2") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_locate_file(tmpdir, xession):
|
||||||
|
bindir1 = tmpdir.mkdir("bindir1")
|
||||||
|
bindir2 = tmpdir.mkdir("bindir2")
|
||||||
|
bindir3 = tmpdir.mkdir("bindir3")
|
||||||
|
file = bindir2 / "findme"
|
||||||
|
file.write_text("", encoding="utf8")
|
||||||
|
with xession.env.swap(PATH=[str(bindir1), str(bindir2), str(bindir3)]):
|
||||||
|
f = locate_file("findme")
|
||||||
|
assert str(f) == str(file)
|
||||||
|
|
|
@ -96,7 +96,9 @@ def locate_file(name, env=None, check_executable=False, use_pathext=False):
|
||||||
filepath = Path(path) / possible_name
|
filepath = Path(path) / possible_name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if check_executable and not is_executable(filepath):
|
if not filepath.is_file() or (
|
||||||
|
check_executable and not is_executable(filepath)
|
||||||
|
):
|
||||||
continue
|
continue
|
||||||
return str(filepath)
|
return str(filepath)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
|
|
Loading…
Add table
Reference in a new issue