Skip to content

Commit

Permalink
Skip $PATH entries we cannot check rather than dying with PermissionE…
Browse files Browse the repository at this point in the history
…rror (#2782)
  • Loading branch information
hroncok authored Oct 18, 2024
1 parent f73a2f3 commit 6f16059
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2782.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When a ``$PATH`` entry cannot be checked for existence, skip it instead of terminating - by :user:`hroncok`.
6 changes: 4 additions & 2 deletions src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import sys
from contextlib import suppress
from pathlib import Path
from typing import TYPE_CHECKING, Callable

Expand Down Expand Up @@ -166,8 +167,9 @@ def get_paths(env: Mapping[str, str]) -> Generator[Path, None, None]:
path = os.defpath
if path:
for p in map(Path, path.split(os.pathsep)):
if p.exists():
yield p
with suppress(OSError):
if p.exists():
yield p


class LazyPathDump:
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/discovery/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def test_discovery_via_path_not_found(tmp_path, monkeypatch):
assert interpreter is None


def test_discovery_via_path_in_nonbrowseable_directory(tmp_path, monkeypatch):
bad_perm = tmp_path / "bad_perm"
bad_perm.mkdir(mode=0o000)
monkeypatch.setenv("PATH", str(bad_perm / "bin"))
interpreter = get_interpreter(uuid4().hex, [])
assert interpreter is None


def test_relative_path(session_app_data, monkeypatch):
sys_executable = Path(PythonInfo.current_system(app_data=session_app_data).system_executable)
cwd = sys_executable.parents[1]
Expand Down

0 comments on commit 6f16059

Please sign in to comment.