From 75bb3a751dd0022d37b0062a571cf5bfdf926e7d Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Fri, 6 Nov 2020 14:40:40 -0300 Subject: [PATCH] Fix issue where file is detected as library code when it shouldn't. Fixes #457 --- .../pydevd/_pydevd_bundle/pydevd_filtering.py | 7 ++++- .../tests_python/test_pydevd_filtering.py | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py index 07bf306d..64092a2e 100644 --- a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py +++ b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py @@ -11,6 +11,7 @@ from _pydev_imps._pydev_saved_modules import threading from pydevd_file_utils import normcase from _pydevd_bundle.pydevd_constants import USER_CODE_BASENAMES_STARTING_WITH, \ LIBRARY_CODE_BASENAMES_STARTING_WITH, IS_PYPY +from _pydevd_bundle import pydevd_constants try: xrange # noqa @@ -209,7 +210,11 @@ class FilesFiltering(object): roots = _convert_to_str_and_clear_empty(roots) new_roots = [] for root in roots: - new_roots.append(self._absolute_normalized_path(root)) + path = self._absolute_normalized_path(root) + if pydevd_constants.IS_WINDOWS: + new_roots.append(path + '\\') + else: + new_roots.append(path + '/') return new_roots def _absolute_normalized_path(self, filename): diff --git a/src/debugpy/_vendored/pydevd/tests_python/test_pydevd_filtering.py b/src/debugpy/_vendored/pydevd/tests_python/test_pydevd_filtering.py index 08969559..b9051c93 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/test_pydevd_filtering.py +++ b/src/debugpy/_vendored/pydevd/tests_python/test_pydevd_filtering.py @@ -1,6 +1,36 @@ from _pydevd_bundle.pydevd_constants import IS_WINDOWS +def test_in_project_roots_prefix_01(tmpdir): + from _pydevd_bundle.pydevd_filtering import FilesFiltering + files_filtering = FilesFiltering() + + another = str(tmpdir.join('another')) + assert not another.endswith('/') and not another.endswith('\\') + + files_filtering.set_library_roots([another]) + files_filtering.set_project_roots([]) + assert not files_filtering.in_project_roots(another + '/f.py') + assert not files_filtering.in_project_roots(another + '\\f.py') + + assert files_filtering.in_project_roots(another + 'f.py') + + +def test_in_project_roots_prefix_02(tmpdir): + from _pydevd_bundle.pydevd_filtering import FilesFiltering + files_filtering = FilesFiltering() + + another = str(tmpdir.join('another')) + assert not another.endswith('/') and not another.endswith('\\') + + files_filtering.set_library_roots([]) + files_filtering.set_project_roots([another]) + assert files_filtering.in_project_roots(another + '/f.py') + assert files_filtering.in_project_roots(another + '\\f.py') + + assert not files_filtering.in_project_roots(another + 'f.py') + + def test_in_project_roots(tmpdir): from _pydevd_bundle.pydevd_filtering import FilesFiltering files_filtering = FilesFiltering()