Skip to content

Commit 8590f2f

Browse files
committed
Permission error handling
1 parent 6123a1b commit 8590f2f

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/pythonfinder/finders/system_finder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def __init__(
5757
venv = os.environ.get("VIRTUAL_ENV")
5858
if venv:
5959
bin_dir = "Scripts" if os.name == "nt" else "bin"
60-
venv_path = Path(venv).resolve() / bin_dir
60+
try:
61+
venv_path = Path(venv).resolve() / bin_dir
62+
except (PermissionError, OSError):
63+
# resolve() can raise PermissionError on Windows for restricted
64+
# system directories; fall back to a non-resolving join.
65+
venv_path = Path(venv) / bin_dir
6166

6267
# For Windows tests with Unix-style paths
6368
if os.name == "nt" and str(venv).startswith("/"):

src/pythonfinder/utils/path_utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,14 @@ def exists_and_is_accessible(path: Path) -> bool:
238238
"""
239239
try:
240240
return path.exists()
241-
except PermissionError as pe:
242-
if pe.errno == errno.EACCES: # Permission denied
243-
return False
244-
else:
245-
raise
241+
except PermissionError:
242+
# Treat any permission-denied error (including Windows WinError 5) as
243+
# inaccessible rather than crashing.
244+
return False
245+
except OSError:
246+
# Catch other OS-level errors (e.g. Windows ERROR_ACCESS_DENIED variants
247+
# that may surface as OSError rather than PermissionError).
248+
return False
246249

247250

248251
def is_in_path(path: str | Path, parent_path: str | Path) -> bool:

0 commit comments

Comments
 (0)