Comprehensive Python debugger backend for IDEs with remote debugging, breakpoints, variable inspection, and performance optimizations
—
Cross-platform file path handling, normalization, and client-server path translation for remote debugging scenarios. These utilities ensure consistent file path handling across different operating systems and enable proper source file mapping between debugger client and server environments.
Functions for normalizing and canonicalizing file paths across different platforms and debugging environments.
def canonical_normalized_path(filename):
"""
Get canonical normalized absolute path for cross-platform compatibility.
Parameters:
- filename (str): File path to normalize
Returns:
str: Canonical normalized absolute path
"""
def absolute_path(filename):
"""
Convert relative path to absolute path.
Parameters:
- filename (str): File path to convert
Returns:
str: Absolute file path
"""
def normcase(s):
"""
Normalize file path case for cross-platform compatibility.
Parameters:
- s (str): Path string to normalize
Returns:
str: Normalized path string
"""Functions for extracting information from file paths and checking file existence.
def basename(filename):
"""
Extract basename from file path.
Parameters:
- filename (str): File path
Returns:
str: Base filename
"""
def exists(filename):
"""
Check if file exists.
Parameters:
- filename (str): File path to check
Returns:
bool: True if file exists, False otherwise
"""Functions for handling path translation between debugger client and server in remote debugging scenarios.
def get_client_filename_source_reference(client_filename):
"""
Get source reference identifier for client-side filename.
Parameters:
- client_filename (str): Client-side file path
Returns:
str: Source reference identifier
"""
def get_server_filename_from_source_reference(source_reference):
"""
Get server filename from source reference identifier.
Parameters:
- source_reference (str): Source reference identifier
Returns:
str: Server-side file path
"""Functions for configuring file system behavior in the debugger.
def set_resolve_symlinks(resolve_symlinks):
"""
Configure whether to resolve symbolic links in file paths.
Parameters:
- resolve_symlinks (bool): Whether to resolve symlinks
Returns:
None
"""# Debug flag for path translation operations
DEBUG_CLIENT_SERVER_TRANSLATION: bool
# Cache container for normalized paths
NORM_PATHS_CONTAINER: dictimport pydevd_file_utils
# Normalize paths for cross-platform compatibility
linux_path = "/home/user/project/src/main.py"
windows_path = "C:\\Users\\user\\project\\src\\main.py"
normalized_linux = pydevd_file_utils.canonical_normalized_path(linux_path)
normalized_windows = pydevd_file_utils.canonical_normalized_path(windows_path)
print(f"Normalized Linux: {normalized_linux}")
print(f"Normalized Windows: {normalized_windows}")
# Check file existence
if pydevd_file_utils.exists(normalized_linux):
print(f"File exists: {pydevd_file_utils.basename(normalized_linux)}")import pydevd_file_utils
# Configure symlink resolution
pydevd_file_utils.set_resolve_symlinks(True)
# Client-side path (e.g., in IDE)
client_path = "/local/workspace/myproject/app.py"
# Get source reference for remote debugging
source_ref = pydevd_file_utils.get_client_filename_source_reference(client_path)
print(f"Source reference: {source_ref}")
# On server side, get server path from reference
server_path = pydevd_file_utils.get_server_filename_from_source_reference(source_ref)
print(f"Server path: {server_path}")import pydevd_file_utils
import os
# Handle different path formats
paths = [
"relative/path/to/file.py",
"/absolute/unix/path.py",
"C:\\Windows\\path\\file.py",
"./current/dir/file.py",
"../parent/dir/file.py"
]
for path in paths:
# Normalize case (important on Windows)
normalized_case = pydevd_file_utils.normcase(path)
# Get absolute path
abs_path = pydevd_file_utils.absolute_path(path)
# Get canonical normalized path
canonical = pydevd_file_utils.canonical_normalized_path(path)
print(f"Original: {path}")
print(f"Normalized case: {normalized_case}")
print(f"Absolute: {abs_path}")
print(f"Canonical: {canonical}")
print(f"Basename: {pydevd_file_utils.basename(canonical)}")
print(f"Exists: {pydevd_file_utils.exists(canonical)}")
print("---")import pydevd_file_utils
# Enable debug mode for path translation
pydevd_file_utils.DEBUG_CLIENT_SERVER_TRANSLATION = True
# Example of debugging path mapping issues
client_file = "/workspace/project/src/module.py"
server_file = "/app/src/module.py"
# Get source reference
ref = pydevd_file_utils.get_client_filename_source_reference(client_file)
# This will show debug output if translation issues occur
mapped_server = pydevd_file_utils.get_server_filename_from_source_reference(ref)
print(f"Client: {client_file}")
print(f"Reference: {ref}")
print(f"Mapped server: {mapped_server}")
# Check cache contents
print(f"Path cache size: {len(pydevd_file_utils.NORM_PATHS_CONTAINER)}")NORM_PATHS_CONTAINERInstall with Tessl CLI
npx tessl i tessl/pypi-pydevd