From e7bcae3ed8266003a639c76663a44c025b36561d Mon Sep 17 00:00:00 2001 From: Tim Rid <6593626+timrid@users.noreply.github.com> Date: Tue, 12 Aug 2025 20:29:23 +0200 Subject: [PATCH 1/2] check if os.file is available before using it --- .../_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py | 3 ++- src/debugpy/_vendored/pydevd/pydevd_file_utils.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py index c0cf39542..0f35b8caf 100644 --- a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py +++ b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py @@ -155,7 +155,8 @@ def _get_default_library_roots(cls): # Make sure we always get at least the standard library location (based on the `os` and # `threading` modules -- it's a bit weird that it may be different on the ci, but it happens). - roots.append(os.path.dirname(os.__file__)) + if hasattr(os, "__file__"): + roots.append(os.path.dirname(os.__file__)) roots.append(os.path.dirname(threading.__file__)) if IS_PYPY: # On PyPy 3.6 (7.3.1) it wrongly says that sysconfig.get_path('stdlib') is diff --git a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py index 390f903ce..ab13b2bc9 100644 --- a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py +++ b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py @@ -88,7 +88,11 @@ def _get_library_dir(): break if library_dir is None or not os_path_exists(library_dir): - library_dir = os.path.dirname(os.__file__) + if hasattr(os, "__file__"): + library_dir = os.path.dirname(os.__file__) + + if library_dir is None: + library_dir = "" # not possible to detect library_dir return library_dir From e9785ca87c434f59743b46cd23ad9e2ef6bca983 Mon Sep 17 00:00:00 2001 From: Tim Rid <6593626+timrid@users.noreply.github.com> Date: Tue, 12 Aug 2025 21:47:49 +0200 Subject: [PATCH 2/2] use threading.__file__ als last fallback --- src/debugpy/_vendored/pydevd/pydevd_file_utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py index ab13b2bc9..7ca383444 100644 --- a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py +++ b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py @@ -89,10 +89,13 @@ def _get_library_dir(): if library_dir is None or not os_path_exists(library_dir): if hasattr(os, "__file__"): + # "os" is a frozen import an thus "os.__file__" is not always set. + # See https://github.com/python/cpython/pull/28656 library_dir = os.path.dirname(os.__file__) - - if library_dir is None: - library_dir = "" # not possible to detect library_dir + else: + # "threading" is not a frozen import an thus "threading.__file__" is always set. + import threading + library_dir = os.path.dirname(threading.__file__) return library_dir