Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow relative paths in the 'remotePath' for a launch.json #1803

Merged
merged 7 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/debugpy/_vendored/pydevd/pydevd_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is crazy to read 😆

"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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,25 @@ 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
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")
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
assert pydevd_file_utils.map_file_to_server("c:\\foo\\my") == server_path


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