Skip to content

Commit 1fc647e

Browse files
authored
Merge pull request #2852 from barneygale/fix-2794
Ignore directories in PATH that can't be opened
2 parents 7365ad2 + 4567521 commit 1fc647e

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

docs/changelog/2794.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ignore unreadable directories in ``PATH``.

src/virtualenv/discovery/builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def get_paths(env: Mapping[str, str]) -> Generator[Path, None, None]:
171171
if path:
172172
for p in map(Path, path.split(os.pathsep)):
173173
with suppress(OSError):
174-
if p.exists():
174+
if next(p.iterdir(), None):
175175
yield p
176176

177177

tests/unit/discovery/test_discovery.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def test_discovery_via_path_not_found(tmp_path, monkeypatch):
6363
def test_discovery_via_path_in_nonbrowseable_directory(tmp_path, monkeypatch):
6464
bad_perm = tmp_path / "bad_perm"
6565
bad_perm.mkdir(mode=0o000)
66+
# path entry is unreadable
67+
monkeypatch.setenv("PATH", str(bad_perm))
68+
interpreter = get_interpreter(uuid4().hex, [])
69+
assert interpreter is None
70+
# path entry parent is unreadable
6671
monkeypatch.setenv("PATH", str(bad_perm / "bin"))
6772
interpreter = get_interpreter(uuid4().hex, [])
6873
assert interpreter is None

0 commit comments

Comments
 (0)