From a3956e4753fc779a9dcfbb3c0bd3e04273dc5213 Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Thu, 9 Jan 2025 13:18:44 -0800 Subject: [PATCH 1/7] Allow relative paths and add more logging for path issues --- .../_vendored/pydevd/pydevd_file_utils.py | 16 ++++++++++++++++ .../tests_python/test_convert_utilities.py | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py index b9fbe4d26..390f903ce 100644 --- a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py +++ b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py @@ -653,6 +653,12 @@ def _fix_path(path, sep, add_end_sep=False): if sep != "/": path = path.replace("/", sep) + + if path.startswith("."): + # We need the full path if this relative because all comparisons below + # check if the path is substring of another + path = os.path.realpath(path) + return path @@ -747,6 +753,16 @@ def setup_client_server_paths(paths): initial_paths_with_end_sep.append((path0, path1)) paths_from_eclipse_to_python_with_end_sep.append((_normcase_from_client(path0), normcase(path1))) + if DEBUG_CLIENT_SERVER_TRANSLATION: + pydev_log.critical( + "pydev debugger: paths_from_eclipse_to_python %s", + ", ".join( + [ + '"%s=>%s"' % (x[0], x[1]) + for x in paths_from_eclipse_to_python + ] + ), + ) # Fix things so that we always match the versions with a slash in the end first. initial_paths = initial_paths_with_end_sep + initial_paths paths_from_eclipse_to_python = paths_from_eclipse_to_python_with_end_sep + paths_from_eclipse_to_python diff --git a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py index 4dbac3b3d..8932f5c87 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py +++ b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py @@ -150,7 +150,7 @@ def test_source_reference(tmpdir): # Client on windows and server on unix pydevd_file_utils.set_ide_os("WINDOWS") - pydevd_file_utils.setup_client_server_paths([("c:\\foo", "/bar")]) + pydevd_file_utils.setup_client_server_paths([("C:\\foo", "/bar")]) assert pydevd_file_utils.map_file_to_client("/bar/my") == ("c:\\foo\\my", True) assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0 @@ -160,6 +160,14 @@ def test_source_reference(tmpdir): assert source_reference != 0 assert pydevd_file_utils.get_server_filename_from_source_reference(source_reference) == "/another/my" + # Allow relative paths in the server path + pydevd_file_utils.setup_client_server_paths([("C:\\foo", "./bar")]) + root = os.getcwd() + server_path = os.path.join(root, "bar/my") + + assert pydevd_file_utils.map_file_to_client(server_path) == ("c:\\foo\\my", True) + assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0 + @pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test.") def test_translate_only_drive(): From 8a4818032b0b570dba7a70f0f6e725898facbfb2 Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Thu, 9 Jan 2025 13:21:13 -0800 Subject: [PATCH 2/7] Revert "Allow relative paths and add more logging for path issues" This reverts commit a3956e4753fc779a9dcfbb3c0bd3e04273dc5213. --- .../_vendored/pydevd/pydevd_file_utils.py | 16 ---------------- .../tests_python/test_convert_utilities.py | 10 +--------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py index 390f903ce..b9fbe4d26 100644 --- a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py +++ b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py @@ -653,12 +653,6 @@ def _fix_path(path, sep, add_end_sep=False): if sep != "/": path = path.replace("/", sep) - - if path.startswith("."): - # We need the full path if this relative because all comparisons below - # check if the path is substring of another - path = os.path.realpath(path) - return path @@ -753,16 +747,6 @@ def setup_client_server_paths(paths): initial_paths_with_end_sep.append((path0, path1)) paths_from_eclipse_to_python_with_end_sep.append((_normcase_from_client(path0), normcase(path1))) - if DEBUG_CLIENT_SERVER_TRANSLATION: - pydev_log.critical( - "pydev debugger: paths_from_eclipse_to_python %s", - ", ".join( - [ - '"%s=>%s"' % (x[0], x[1]) - for x in paths_from_eclipse_to_python - ] - ), - ) # Fix things so that we always match the versions with a slash in the end first. initial_paths = initial_paths_with_end_sep + initial_paths paths_from_eclipse_to_python = paths_from_eclipse_to_python_with_end_sep + paths_from_eclipse_to_python diff --git a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py index 8932f5c87..4dbac3b3d 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py +++ b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py @@ -150,7 +150,7 @@ def test_source_reference(tmpdir): # Client on windows and server on unix pydevd_file_utils.set_ide_os("WINDOWS") - pydevd_file_utils.setup_client_server_paths([("C:\\foo", "/bar")]) + pydevd_file_utils.setup_client_server_paths([("c:\\foo", "/bar")]) assert pydevd_file_utils.map_file_to_client("/bar/my") == ("c:\\foo\\my", True) assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0 @@ -160,14 +160,6 @@ def test_source_reference(tmpdir): assert source_reference != 0 assert pydevd_file_utils.get_server_filename_from_source_reference(source_reference) == "/another/my" - # Allow relative paths in the server path - pydevd_file_utils.setup_client_server_paths([("C:\\foo", "./bar")]) - root = os.getcwd() - server_path = os.path.join(root, "bar/my") - - assert pydevd_file_utils.map_file_to_client(server_path) == ("c:\\foo\\my", True) - assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0 - @pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test.") def test_translate_only_drive(): From f5ed8da9c28b81fd1a9131d8cc6a7e1d2884e7e2 Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Thu, 9 Jan 2025 13:18:44 -0800 Subject: [PATCH 3/7] Allow relative paths and add more logging for path issues --- .../_vendored/pydevd/pydevd_file_utils.py | 16 ++++++++++++++++ .../tests_python/test_convert_utilities.py | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py index b9fbe4d26..390f903ce 100644 --- a/src/debugpy/_vendored/pydevd/pydevd_file_utils.py +++ b/src/debugpy/_vendored/pydevd/pydevd_file_utils.py @@ -653,6 +653,12 @@ def _fix_path(path, sep, add_end_sep=False): if sep != "/": path = path.replace("/", sep) + + if path.startswith("."): + # We need the full path if this relative because all comparisons below + # check if the path is substring of another + path = os.path.realpath(path) + return path @@ -747,6 +753,16 @@ def setup_client_server_paths(paths): initial_paths_with_end_sep.append((path0, path1)) paths_from_eclipse_to_python_with_end_sep.append((_normcase_from_client(path0), normcase(path1))) + if DEBUG_CLIENT_SERVER_TRANSLATION: + pydev_log.critical( + "pydev debugger: paths_from_eclipse_to_python %s", + ", ".join( + [ + '"%s=>%s"' % (x[0], x[1]) + for x in paths_from_eclipse_to_python + ] + ), + ) # Fix things so that we always match the versions with a slash in the end first. initial_paths = initial_paths_with_end_sep + initial_paths paths_from_eclipse_to_python = paths_from_eclipse_to_python_with_end_sep + paths_from_eclipse_to_python diff --git a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py index 4dbac3b3d..8932f5c87 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py +++ b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py @@ -150,7 +150,7 @@ def test_source_reference(tmpdir): # Client on windows and server on unix pydevd_file_utils.set_ide_os("WINDOWS") - pydevd_file_utils.setup_client_server_paths([("c:\\foo", "/bar")]) + pydevd_file_utils.setup_client_server_paths([("C:\\foo", "/bar")]) assert pydevd_file_utils.map_file_to_client("/bar/my") == ("c:\\foo\\my", True) assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0 @@ -160,6 +160,14 @@ def test_source_reference(tmpdir): assert source_reference != 0 assert pydevd_file_utils.get_server_filename_from_source_reference(source_reference) == "/another/my" + # Allow relative paths in the server path + pydevd_file_utils.setup_client_server_paths([("C:\\foo", "./bar")]) + root = os.getcwd() + server_path = os.path.join(root, "bar/my") + + assert pydevd_file_utils.map_file_to_client(server_path) == ("c:\\foo\\my", True) + assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0 + @pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test.") def test_translate_only_drive(): From a6a8d08efb3819e088b4a21996f13b3303bfd830 Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Thu, 9 Jan 2025 13:44:31 -0800 Subject: [PATCH 4/7] Add case test --- .../_vendored/pydevd/tests_python/test_convert_utilities.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py index 8932f5c87..663685119 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py +++ b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py @@ -165,8 +165,9 @@ def test_source_reference(tmpdir): root = os.getcwd() server_path = os.path.join(root, "bar/my") - assert pydevd_file_utils.map_file_to_client(server_path) == ("c:\\foo\\my", True) - assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0 + assert pydevd_file_utils.map_file_to_client(server_path) == ("C:\\foo\\my", True) + assert pydevd_file_utils.get_client_filename_source_reference("C:\\foo\\my") == 0 + assert pydevd_file_utils.map_file_to_server("c:\\foo\\my") == (serverPath, True) @pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test.") From fedd2a58df47f76006be33524f6c323ef61eb1b1 Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Thu, 9 Jan 2025 13:45:48 -0800 Subject: [PATCH 5/7] Missed some spots --- .../_vendored/pydevd/tests_python/test_convert_utilities.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py index 663685119..c9c32e6e7 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py +++ b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py @@ -152,8 +152,8 @@ def test_source_reference(tmpdir): pydevd_file_utils.setup_client_server_paths([("C:\\foo", "/bar")]) - assert pydevd_file_utils.map_file_to_client("/bar/my") == ("c:\\foo\\my", True) - assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0 + assert pydevd_file_utils.map_file_to_client("/bar/my") == ("C:\\foo\\my", True) + assert pydevd_file_utils.get_client_filename_source_reference("C:\\foo\\my") == 0 assert pydevd_file_utils.map_file_to_client("/another/my") == ("\\another\\my", False) source_reference = pydevd_file_utils.get_client_filename_source_reference("\\another\\my") From 6887ff188c4f87862eb4a67e18d3a28a108db9b9 Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Thu, 9 Jan 2025 13:46:23 -0800 Subject: [PATCH 6/7] Invalid variable name --- .../_vendored/pydevd/tests_python/test_convert_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py index c9c32e6e7..3c5202019 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py +++ b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py @@ -167,7 +167,7 @@ def test_source_reference(tmpdir): assert pydevd_file_utils.map_file_to_client(server_path) == ("C:\\foo\\my", True) assert pydevd_file_utils.get_client_filename_source_reference("C:\\foo\\my") == 0 - assert pydevd_file_utils.map_file_to_server("c:\\foo\\my") == (serverPath, True) + assert pydevd_file_utils.map_file_to_server("c:\\foo\\my") == (server_path, True) @pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test.") From 5da690ed4cf7336d698db6f84e55beaa9cec26e9 Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Thu, 9 Jan 2025 13:47:04 -0800 Subject: [PATCH 7/7] Func doesn't return tuple --- .../_vendored/pydevd/tests_python/test_convert_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py index 3c5202019..fd640ab84 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py +++ b/src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py @@ -167,7 +167,7 @@ def test_source_reference(tmpdir): assert pydevd_file_utils.map_file_to_client(server_path) == ("C:\\foo\\my", True) assert pydevd_file_utils.get_client_filename_source_reference("C:\\foo\\my") == 0 - assert pydevd_file_utils.map_file_to_server("c:\\foo\\my") == (server_path, True) + assert pydevd_file_utils.map_file_to_server("c:\\foo\\my") == server_path @pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test.")