Skip to content

Commit 6f16059

Browse files
authored
Skip $PATH entries we cannot check rather than dying with PermissionError (#2782)
1 parent f73a2f3 commit 6f16059

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

docs/changelog/2782.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
When a ``$PATH`` entry cannot be checked for existence, skip it instead of terminating - by :user:`hroncok`.

src/virtualenv/discovery/builtin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import sys
6+
from contextlib import suppress
67
from pathlib import Path
78
from typing import TYPE_CHECKING, Callable
89

@@ -166,8 +167,9 @@ def get_paths(env: Mapping[str, str]) -> Generator[Path, None, None]:
166167
path = os.defpath
167168
if path:
168169
for p in map(Path, path.split(os.pathsep)):
169-
if p.exists():
170-
yield p
170+
with suppress(OSError):
171+
if p.exists():
172+
yield p
171173

172174

173175
class LazyPathDump:

tests/unit/discovery/test_discovery.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ def test_discovery_via_path_not_found(tmp_path, monkeypatch):
5959
assert interpreter is None
6060

6161

62+
def test_discovery_via_path_in_nonbrowseable_directory(tmp_path, monkeypatch):
63+
bad_perm = tmp_path / "bad_perm"
64+
bad_perm.mkdir(mode=0o000)
65+
monkeypatch.setenv("PATH", str(bad_perm / "bin"))
66+
interpreter = get_interpreter(uuid4().hex, [])
67+
assert interpreter is None
68+
69+
6270
def test_relative_path(session_app_data, monkeypatch):
6371
sys_executable = Path(PythonInfo.current_system(app_data=session_app_data).system_executable)
6472
cwd = sys_executable.parents[1]

0 commit comments

Comments
 (0)