Skip to content

Commit 19883c1

Browse files
committed
debugpy : Format code.
Signed-off-by: Jos Verlinde <[email protected]>
1 parent f5d2977 commit 19883c1

File tree

8 files changed

+186
-188
lines changed

8 files changed

+186
-188
lines changed

python-ecosys/debugpy/dap_monitor.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@ def __init__(self, listen_port=5679, target_host='127.0.0.1', target_port=5678):
1616
self.target_port = target_port
1717
self.client_sock = None
1818
self.server_sock = None
19-
19+
2020
def start(self):
2121
"""Start the DAP monitor proxy."""
2222
print(f"DAP Monitor starting on port {self.listen_port}")
2323
print(f"Will forward to {self.target_host}:{self.target_port}")
2424
print("Start MicroPython debugpy server first, then connect VS Code to port 5679")
25-
25+
2626
# Create listening socket
2727
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2828
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
2929
listener.bind(('127.0.0.1', self.listen_port))
3030
listener.listen(1)
31-
31+
3232
print(f"Listening for VS Code connection on port {self.listen_port}...")
33-
33+
3434
try:
3535
# Wait for VS Code to connect
3636
self.client_sock, client_addr = listener.accept()
3737
print(f"VS Code connected from {client_addr}")
38-
38+
3939
# Connect to MicroPython debugpy server
4040
self.server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4141
self.server_sock.connect((self.target_host, self.target_port))
4242
print(f"Connected to MicroPython debugpy at {self.target_host}:{self.target_port}")
43-
43+
4444
# Start forwarding threads
4545
threading.Thread(target=self.forward_client_to_server, daemon=True).start()
4646
threading.Thread(target=self.forward_server_to_client, daemon=True).start()
47-
47+
4848
print("DAP Monitor active - press Ctrl+C to stop")
4949
while not self.disconnect:
5050
time.sleep(1)
@@ -55,7 +55,7 @@ def start(self):
5555
print(f"Error: {e}")
5656
finally:
5757
self.cleanup()
58-
58+
5959
def forward_client_to_server(self):
6060
"""Forward messages from VS Code client to MicroPython server."""
6161
try:
@@ -66,7 +66,7 @@ def forward_client_to_server(self):
6666
self.send_raw_data(self.server_sock, data)
6767
except Exception as e:
6868
print(f"Client->Server forwarding error: {e}")
69-
69+
7070
def forward_server_to_client(self):
7171
"""Forward messages from MicroPython server to VS Code client."""
7272
try:
@@ -77,7 +77,7 @@ def forward_server_to_client(self):
7777
self.send_raw_data(self.client_sock, data)
7878
except Exception as e:
7979
print(f"Server->Client forwarding error: {e}")
80-
80+
8181
def receive_dap_message(self, sock, source):
8282
"""Receive and log a DAP message."""
8383
try:
@@ -88,26 +88,26 @@ def receive_dap_message(self, sock, source):
8888
if not byte:
8989
return None
9090
header += byte
91-
91+
9292
# Parse content length
9393
header_str = header.decode('utf-8')
9494
content_length = 0
9595
for line in header_str.split('\r\n'):
9696
if line.startswith('Content-Length:'):
9797
content_length = int(line.split(':', 1)[1].strip())
9898
break
99-
99+
100100
if content_length == 0:
101101
return None
102-
102+
103103
# Read content
104104
content = b""
105105
while len(content) < content_length:
106106
chunk = sock.recv(content_length - len(content))
107107
if not chunk:
108108
return None
109109
content += chunk
110-
110+
111111
# Parse and Log the message
112112
message = self.parse_dap(source, content)
113113
self.log_dap_message(source, message)
@@ -163,7 +163,7 @@ def send_raw_data(self, sock, data):
163163
sock.send(data)
164164
except Exception as e:
165165
print(f"Error sending data: {e}")
166-
166+
167167
def cleanup(self):
168168
"""Clean up sockets."""
169169
if self.client_sock:
@@ -184,4 +184,4 @@ def cleanup(self):
184184
target_host=args.target_host,
185185
target_port=args.target_port
186186
)
187-
monitor.start()
187+
monitor.start()

python-ecosys/debugpy/debugpy/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from .common.constants import DEFAULT_HOST, DEFAULT_PORT
1212

1313
__all__ = [
14-
"listen",
15-
"wait_for_client",
16-
"breakpoint",
17-
"debug_this_thread",
1814
"DEFAULT_HOST",
1915
"DEFAULT_PORT",
16+
"breakpoint",
17+
"debug_this_thread",
18+
"listen",
19+
"wait_for_client",
2020
]

python-ecosys/debugpy/debugpy/common/messaging.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66

77
class JsonMessageChannel:
88
"""Handles JSON message communication over a socket using DAP format."""
9-
9+
1010
def __init__(self, sock, debug_callback=None):
1111
self.sock = sock
1212
self.seq = 0
1313
self.closed = False
1414
self._recv_buffer = b""
1515
self._debug_print = debug_callback or (lambda x: None) # Default to no-op
16-
16+
1717
def send_message(self, msg_type, command=None, **kwargs):
1818
"""Send a DAP message."""
1919
if self.closed:
2020
return
21-
21+
2222
self.seq += 1
2323
message = {
2424
"seq": self.seq,
2525
"type": msg_type,
2626
}
27-
27+
2828
if command:
2929
if msg_type == MSG_TYPE_REQUEST:
3030
message["command"] = command
@@ -42,48 +42,48 @@ def send_message(self, msg_type, command=None, **kwargs):
4242
message["event"] = command
4343
if kwargs:
4444
message["body"] = kwargs
45-
45+
4646
json_str = json.dumps(message)
4747
content = json_str.encode("utf-8")
4848
header = f"Content-Length: {len(content)}\r\n\r\n".encode("utf-8")
49-
49+
5050
try:
5151
self.sock.send(header + content)
5252
except OSError:
5353
self.closed = True
54-
54+
5555
def send_request(self, command, **kwargs):
5656
"""Send a request message."""
5757
self.send_message(MSG_TYPE_REQUEST, command, **kwargs)
58-
58+
5959
def send_response(self, command, request_seq, success=True, body=None, message=None):
6060
"""Send a response message."""
6161
kwargs = {"request_seq": request_seq, "success": success}
6262
if body is not None:
6363
kwargs["body"] = body
6464
if message is not None:
6565
kwargs["message"] = message
66-
66+
6767
self._debug_print(f"[DAP] SEND: response {command} (req_seq={request_seq}, success={success})")
6868
if body:
6969
self._debug_print(f"[DAP] body: {body}")
7070
if message:
7171
self._debug_print(f"[DAP] message: {message}")
72-
72+
7373
self.send_message(MSG_TYPE_RESPONSE, command, **kwargs)
74-
74+
7575
def send_event(self, event, **kwargs):
7676
"""Send an event message."""
7777
self._debug_print(f"[DAP] SEND: event {event}")
7878
if kwargs:
7979
self._debug_print(f"[DAP] body: {kwargs}")
8080
self.send_message(MSG_TYPE_EVENT, event, **kwargs)
81-
81+
8282
def recv_message(self):
8383
"""Receive a DAP message."""
8484
if self.closed:
8585
return None
86-
86+
8787
try:
8888
# Read headers
8989
while b"\r\n\r\n" not in self._recv_buffer:
@@ -99,21 +99,21 @@ def recv_message(self):
9999
return None # No data available
100100
self.closed = True
101101
return None
102-
102+
103103
header_end = self._recv_buffer.find(b"\r\n\r\n")
104104
header_str = self._recv_buffer[:header_end].decode("utf-8")
105105
self._recv_buffer = self._recv_buffer[header_end + 4:]
106-
106+
107107
# Parse Content-Length
108108
content_length = 0
109109
for line in header_str.split("\r\n"):
110110
if line.startswith("Content-Length:"):
111111
content_length = int(line.split(":", 1)[1].strip())
112112
break
113-
113+
114114
if content_length == 0:
115115
return None
116-
116+
117117
# Read body
118118
while len(self._recv_buffer) < content_length:
119119
try:
@@ -127,10 +127,10 @@ def recv_message(self):
127127
return None
128128
self.closed = True
129129
return None
130-
130+
131131
body = self._recv_buffer[:content_length]
132132
self._recv_buffer = self._recv_buffer[content_length:]
133-
133+
134134
# Parse JSON
135135
try:
136136
message = json.loads(body.decode("utf-8"))
@@ -139,12 +139,12 @@ def recv_message(self):
139139
except (ValueError, UnicodeDecodeError) as e:
140140
print(f"[DAP] JSON parse error: {e}")
141141
return None
142-
142+
143143
except OSError as e:
144144
print(f"[DAP] Socket error in recv_message: {e}")
145145
self.closed = True
146146
return None
147-
147+
148148
def close(self):
149149
"""Close the channel."""
150150
self.closed = True

python-ecosys/debugpy/debugpy/public_api.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,35 @@ def listen(port=DEFAULT_PORT, host=DEFAULT_HOST):
1919
(host, port) tuple of the actual listening address
2020
"""
2121
global _debug_session
22-
22+
2323
if _debug_session is not None:
2424
raise RuntimeError("Already listening for debugger")
25-
25+
2626
# Create listening socket
2727
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2828
try:
2929
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
3030
except:
3131
pass # Not supported in MicroPython
32-
32+
3333
# Use getaddrinfo for MicroPython compatibility
3434
addr_info = socket.getaddrinfo(host, port)
3535
addr = addr_info[0][-1] # Get the sockaddr
3636
listener.bind(addr)
3737
listener.listen(1)
38-
38+
3939
# getsockname not available in MicroPython, use original values
4040
print(f"Debugpy listening on {host}:{port}")
41-
41+
4242
# Wait for connection
4343
client_sock = None
4444
try:
4545
client_sock, client_addr = listener.accept()
4646
print(f"Debugger connected from {client_addr}")
47-
47+
4848
# Create debug session
4949
_debug_session = DebugSession(client_sock)
50-
50+
5151
# Handle just the initialize request, then return immediately
5252
print("[DAP] Waiting for initialize request...")
5353
init_message = _debug_session.channel.recv_message()
@@ -56,12 +56,12 @@ def listen(port=DEFAULT_PORT, host=DEFAULT_HOST):
5656
print("[DAP] Initialize request handled - returning control immediately")
5757
else:
5858
print(f"[DAP] Warning: Expected initialize, got {init_message}")
59-
59+
6060
# Set socket to non-blocking for subsequent message processing
6161
_debug_session.channel.sock.settimeout(0.001)
62-
62+
6363
print("[DAP] Debug session ready - all other messages will be handled in trace function")
64-
64+
6565
except Exception as e:
6666
print(f"[DAP] Connection error: {e}")
6767
if client_sock:
@@ -70,7 +70,7 @@ def listen(port=DEFAULT_PORT, host=DEFAULT_HOST):
7070
finally:
7171
# Only close the listener, not the client connection
7272
listener.close()
73-
73+
7474
return (host, port)
7575

7676

0 commit comments

Comments
 (0)