Skip to content

Commit

Permalink
Merge pull request #2852 from barneygale/fix-2794
Browse files Browse the repository at this point in the history
Ignore directories in PATH that can't be opened
  • Loading branch information
gaborbernat authored Feb 27, 2025
2 parents 7365ad2 + 4567521 commit 1fc647e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/2794.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore unreadable directories in ``PATH``.
2 changes: 1 addition & 1 deletion src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def get_paths(env: Mapping[str, str]) -> Generator[Path, None, None]:
if path:
for p in map(Path, path.split(os.pathsep)):
with suppress(OSError):
if p.exists():
if next(p.iterdir(), None):
yield p


Expand Down
5 changes: 5 additions & 0 deletions tests/unit/discovery/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def test_discovery_via_path_not_found(tmp_path, monkeypatch):
def test_discovery_via_path_in_nonbrowseable_directory(tmp_path, monkeypatch):
bad_perm = tmp_path / "bad_perm"
bad_perm.mkdir(mode=0o000)
# path entry is unreadable
monkeypatch.setenv("PATH", str(bad_perm))
interpreter = get_interpreter(uuid4().hex, [])
assert interpreter is None
# path entry parent is unreadable
monkeypatch.setenv("PATH", str(bad_perm / "bin"))
interpreter = get_interpreter(uuid4().hex, [])
assert interpreter is None
Expand Down

0 comments on commit 1fc647e

Please sign in to comment.