Skip to content

Commit d266361

Browse files
authored
Allow relative paths in the 'remotePath' for a launch.json (#1803)
* Allow relative paths and add more logging for path issues * Revert "Allow relative paths and add more logging for path issues" This reverts commit a3956e4. * Allow relative paths and add more logging for path issues * Add case test * Missed some spots * Invalid variable name * Func doesn't return tuple
1 parent 02723de commit d266361

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/debugpy/_vendored/pydevd/pydevd_file_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,12 @@ def _fix_path(path, sep, add_end_sep=False):
653653

654654
if sep != "/":
655655
path = path.replace("/", sep)
656+
657+
if path.startswith("."):
658+
# We need the full path if this relative because all comparisons below
659+
# check if the path is substring of another
660+
path = os.path.realpath(path)
661+
656662
return path
657663

658664

@@ -747,6 +753,16 @@ def setup_client_server_paths(paths):
747753
initial_paths_with_end_sep.append((path0, path1))
748754
paths_from_eclipse_to_python_with_end_sep.append((_normcase_from_client(path0), normcase(path1)))
749755

756+
if DEBUG_CLIENT_SERVER_TRANSLATION:
757+
pydev_log.critical(
758+
"pydev debugger: paths_from_eclipse_to_python %s",
759+
", ".join(
760+
[
761+
'"%s=>%s"' % (x[0], x[1])
762+
for x in paths_from_eclipse_to_python
763+
]
764+
),
765+
)
750766
# Fix things so that we always match the versions with a slash in the end first.
751767
initial_paths = initial_paths_with_end_sep + initial_paths
752768
paths_from_eclipse_to_python = paths_from_eclipse_to_python_with_end_sep + paths_from_eclipse_to_python

src/debugpy/_vendored/pydevd/tests_python/test_convert_utilities.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,25 @@ def test_source_reference(tmpdir):
150150
# Client on windows and server on unix
151151
pydevd_file_utils.set_ide_os("WINDOWS")
152152

153-
pydevd_file_utils.setup_client_server_paths([("c:\\foo", "/bar")])
153+
pydevd_file_utils.setup_client_server_paths([("C:\\foo", "/bar")])
154154

155-
assert pydevd_file_utils.map_file_to_client("/bar/my") == ("c:\\foo\\my", True)
156-
assert pydevd_file_utils.get_client_filename_source_reference("c:\\foo\\my") == 0
155+
assert pydevd_file_utils.map_file_to_client("/bar/my") == ("C:\\foo\\my", True)
156+
assert pydevd_file_utils.get_client_filename_source_reference("C:\\foo\\my") == 0
157157

158158
assert pydevd_file_utils.map_file_to_client("/another/my") == ("\\another\\my", False)
159159
source_reference = pydevd_file_utils.get_client_filename_source_reference("\\another\\my")
160160
assert source_reference != 0
161161
assert pydevd_file_utils.get_server_filename_from_source_reference(source_reference) == "/another/my"
162162

163+
# Allow relative paths in the server path
164+
pydevd_file_utils.setup_client_server_paths([("C:\\foo", "./bar")])
165+
root = os.getcwd()
166+
server_path = os.path.join(root, "bar/my")
167+
168+
assert pydevd_file_utils.map_file_to_client(server_path) == ("C:\\foo\\my", True)
169+
assert pydevd_file_utils.get_client_filename_source_reference("C:\\foo\\my") == 0
170+
assert pydevd_file_utils.map_file_to_server("c:\\foo\\my") == server_path
171+
163172

164173
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only test.")
165174
def test_translate_only_drive():

0 commit comments

Comments
 (0)