mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Get rid of fmt() and use idiomatic format() and f"" instead.
This commit is contained in:
parent
98087352cb
commit
1965b47034
34 changed files with 221 additions and 359 deletions
|
|
@ -7,7 +7,7 @@
|
|||
import threading
|
||||
import socket
|
||||
|
||||
from debugpy.common import fmt, log, messaging, sockets
|
||||
from debugpy.common import log, messaging, sockets
|
||||
|
||||
|
||||
class BackChannel(object):
|
||||
|
|
@ -21,7 +21,7 @@ class BackChannel(object):
|
|||
self._server_socket = None
|
||||
|
||||
def __str__(self):
|
||||
return fmt("BackChannel[{0}]", self.session.id)
|
||||
return f"BackChannel[{self.session.id}]"
|
||||
|
||||
def listen(self):
|
||||
self._server_socket = sockets.create_server("127.0.0.1", 0, self.TIMEOUT)
|
||||
|
|
@ -59,7 +59,7 @@ class BackChannel(object):
|
|||
self._setup_stream()
|
||||
|
||||
accept_thread = threading.Thread(
|
||||
target=accept_worker, name=fmt("{0} listener", self)
|
||||
target=accept_worker, name=f"{self} listener"
|
||||
)
|
||||
accept_thread.daemon = True
|
||||
accept_thread.start()
|
||||
|
|
@ -118,5 +118,5 @@ class ScratchPad(object):
|
|||
"""Sets debuggee.scratchpad[key] = value inside the debugged process.
|
||||
"""
|
||||
log.info("{0} debuggee.scratchpad[{1!r}] = {2!r}", self.session, key, value)
|
||||
expr = fmt("sys.modules['debuggee'].scratchpad[{0!r}] = {1!r}", key, value)
|
||||
expr = f"sys.modules['debuggee'].scratchpad[{key!r}] = {value!r}"
|
||||
self.session.request("evaluate", {"context": "repl", "expression": expr})
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import os
|
|||
import re
|
||||
import threading
|
||||
|
||||
from debugpy.common import fmt, log
|
||||
from debugpy.common import log
|
||||
|
||||
|
||||
class CapturedOutput(object):
|
||||
|
|
@ -24,7 +24,7 @@ class CapturedOutput(object):
|
|||
self._capture(fd, stream_name)
|
||||
|
||||
def __str__(self):
|
||||
return fmt("CapturedOutput[{0}]", self.session.id)
|
||||
return f"CapturedOutput[{self.session.id}]"
|
||||
|
||||
def _worker(self, fd, name):
|
||||
chunks = self._chunks[name]
|
||||
|
|
@ -52,7 +52,7 @@ class CapturedOutput(object):
|
|||
self._chunks[name] = []
|
||||
|
||||
thread = threading.Thread(
|
||||
target=lambda: self._worker(fd, name), name=fmt("{0} {1}", self, name)
|
||||
target=lambda: self._worker(fd, name), name=f"{self} {name}"
|
||||
)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
|
@ -73,7 +73,7 @@ class CapturedOutput(object):
|
|||
result = self._chunks[which]
|
||||
except KeyError:
|
||||
raise AssertionError(
|
||||
fmt("{0} was not captured for {1}", which, self.session.debuggee_id)
|
||||
f"{which} was not captured for {self.session.debuggee_id}"
|
||||
)
|
||||
|
||||
with self._lock:
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ import pytest
|
|||
import sys
|
||||
|
||||
import debugpy
|
||||
from debugpy.common import compat, fmt, log
|
||||
from debugpy.common import compat, json, log
|
||||
from tests import net, timeline
|
||||
from tests.debug import session
|
||||
from tests.patterns import some
|
||||
|
|
@ -100,7 +100,7 @@ def _runner(f):
|
|||
def __repr__(self):
|
||||
result = type(self).__name__
|
||||
args = [str(x) for x in self._args] + [
|
||||
fmt("{0}={1}", k, v) for k, v in self._kwargs.items()
|
||||
f"{k}={v}" for k, v in self._kwargs.items()
|
||||
]
|
||||
if len(args):
|
||||
result += "(" + ", ".join(args) + ")"
|
||||
|
|
@ -118,7 +118,7 @@ def _runner(f):
|
|||
def launch(session, target, console=None, cwd=None):
|
||||
assert console in (None, "internalConsole", "integratedTerminal", "externalTerminal")
|
||||
|
||||
log.info("Launching {0} in {1} using {2!j}.", target, session, console)
|
||||
log.info("Launching {0} in {1} using {2}.", target, session, json.repr(console))
|
||||
|
||||
target.configure(session)
|
||||
config = session.config
|
||||
|
|
@ -144,8 +144,8 @@ def launch(session, target, console=None, cwd=None):
|
|||
|
||||
|
||||
def _attach_common_config(session, target, cwd):
|
||||
assert target.code is None or "debuggee.setup()" in target.code, fmt(
|
||||
"{0} must invoke debuggee.setup().", target.filename
|
||||
assert target.code is None or "debuggee.setup()" in target.code, (
|
||||
f"{target.filename} must invoke debuggee.setup()."
|
||||
)
|
||||
|
||||
target.configure(session)
|
||||
|
|
@ -239,8 +239,7 @@ debugpy.listen(({host!r}, {port!r}))
|
|||
if {wait!r}:
|
||||
debugpy.wait_for_client()
|
||||
"""
|
||||
debuggee_setup = fmt(
|
||||
debuggee_setup,
|
||||
debuggee_setup = debuggee_setup.format(
|
||||
host=host,
|
||||
port=port,
|
||||
wait=wait,
|
||||
|
|
@ -293,16 +292,13 @@ def attach_listen(session, target, method, cwd=None, log_dir=None):
|
|||
elif method == "api":
|
||||
args = []
|
||||
api_config = {k: v for k, v in config.items() if k in {"subProcess"}}
|
||||
debuggee_setup = """
|
||||
debuggee_setup = f"""
|
||||
import debugpy
|
||||
if {log_dir!r}:
|
||||
debugpy.log_to({log_dir!r})
|
||||
debugpy.configure({api_config!r})
|
||||
debugpy.connect({address!r})
|
||||
debugpy.connect({(host, port)!r})
|
||||
"""
|
||||
debuggee_setup = fmt(
|
||||
debuggee_setup, address=(host, port), log_dir=log_dir, api_config=api_config
|
||||
)
|
||||
else:
|
||||
raise ValueError
|
||||
args += target.cli(session.spawn_debuggee.env)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import sys
|
|||
import time
|
||||
|
||||
import debugpy.adapter
|
||||
from debugpy.common import compat, fmt, json, log, messaging, sockets, util
|
||||
from debugpy.common import compat, json, log, messaging, sockets, util
|
||||
from debugpy.common.compat import unicode
|
||||
import tests
|
||||
from tests import code, timeline, watchdog
|
||||
|
|
@ -203,15 +203,15 @@ class Session(object):
|
|||
self.spawn_debuggee.env = util.Env()
|
||||
|
||||
def __str__(self):
|
||||
return fmt("Session[{0}]", self.id)
|
||||
return f"Session[{self.id}]"
|
||||
|
||||
@property
|
||||
def adapter_id(self):
|
||||
return fmt("Adapter[{0}]", self.id)
|
||||
return f"Adapter[{self.id}]"
|
||||
|
||||
@property
|
||||
def debuggee_id(self):
|
||||
return fmt("Debuggee[{0}]", self.id)
|
||||
return f"Debuggee[{self.id}]"
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
|
@ -294,7 +294,7 @@ class Session(object):
|
|||
if self.log_dir is None:
|
||||
return False
|
||||
|
||||
log.info("Logs for {0} will be in {1!j}", self, self.log_dir)
|
||||
log.info("Logs for {0} will be in {1}", self, json.repr(self.log_dir))
|
||||
try:
|
||||
self.log_dir.remove()
|
||||
except Exception:
|
||||
|
|
@ -358,13 +358,13 @@ class Session(object):
|
|||
|
||||
log.info(
|
||||
"Spawning {0}:\n\n"
|
||||
"Current directory: {1!j}\n\n"
|
||||
"Command line: {2!j}\n\n"
|
||||
"Environment variables: {3!j}\n\n",
|
||||
"Current directory: {1}\n\n"
|
||||
"Command line: {2}\n\n"
|
||||
"Environment variables: {3}\n\n",
|
||||
self.debuggee_id,
|
||||
cwd,
|
||||
args,
|
||||
env,
|
||||
json.repr(cwd),
|
||||
json.repr(args),
|
||||
json.repr(env),
|
||||
)
|
||||
|
||||
popen_fds = {}
|
||||
|
|
@ -405,11 +405,11 @@ class Session(object):
|
|||
|
||||
log.info(
|
||||
"Spawning {0}:\n\n"
|
||||
"Command line: {1!j}\n\n"
|
||||
"Environment variables: {2!j}\n\n",
|
||||
"Command line: {1}\n\n"
|
||||
"Environment variables: {2}\n\n",
|
||||
self.adapter_id,
|
||||
args,
|
||||
env,
|
||||
json.repr(args),
|
||||
json.repr(env),
|
||||
)
|
||||
self.adapter = psutil.Popen(
|
||||
args,
|
||||
|
|
@ -446,7 +446,7 @@ class Session(object):
|
|||
return self.request_attach()
|
||||
else:
|
||||
raise ValueError(
|
||||
fmt('Unsupported "request":{0!j} in session.config', request)
|
||||
f'Unsupported "request":{json.repr(request)} in session.config'
|
||||
)
|
||||
|
||||
def request(self, *args, **kwargs):
|
||||
|
|
@ -485,7 +485,7 @@ class Session(object):
|
|||
self.observe(occ)
|
||||
pid = event("subProcessId", int)
|
||||
watchdog.register_spawn(
|
||||
pid, fmt("{0}-subprocess-{1}", self.debuggee_id, pid)
|
||||
pid, f"{self.debuggee_id}-subprocess-{pid}"
|
||||
)
|
||||
|
||||
def run_in_terminal(self, args, cwd, env):
|
||||
|
|
@ -662,7 +662,7 @@ class Session(object):
|
|||
else:
|
||||
marker = line
|
||||
line = get_marked_line_numbers()[marker]
|
||||
descr = fmt("{0} (@{1})", line, marker)
|
||||
descr = f"{line} (@{marker})"
|
||||
bp_log.append((line, descr))
|
||||
return {"line": line}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
import py
|
||||
import os
|
||||
|
||||
from debugpy.common import fmt, compat
|
||||
from debugpy.common import compat, json
|
||||
from tests.patterns import some
|
||||
|
||||
|
||||
|
|
@ -108,13 +108,9 @@ class Program(Target):
|
|||
|
||||
def __repr__(self):
|
||||
if self._cwd:
|
||||
return fmt(
|
||||
"program (relative) {0!j} / {1!j}",
|
||||
self._cwd,
|
||||
self._get_relative_program(),
|
||||
)
|
||||
return f"program (relative) {json.repr(self._cwd)} / {json.repr(self._get_relative_program())}"
|
||||
else:
|
||||
return fmt("program {0!j}", compat.filename(self.filename.strpath))
|
||||
return f"program {json.repr(compat.filename(self.filename.strpath))}"
|
||||
|
||||
def configure(self, session):
|
||||
if self._cwd:
|
||||
|
|
@ -147,7 +143,7 @@ class Module(Target):
|
|||
self.name = name if name is not None else self.filename.purebasename
|
||||
|
||||
def __repr__(self):
|
||||
return fmt("module {0}", self.name)
|
||||
return f"module {self.name}"
|
||||
|
||||
def configure(self, session):
|
||||
session.config["module"] = self.name
|
||||
|
|
@ -175,7 +171,7 @@ class Code(Target):
|
|||
|
||||
def __repr__(self):
|
||||
lines = self.code.split("\n")
|
||||
return fmt("code: {0!j}", lines)
|
||||
return f"code: {json.repr(lines)}"
|
||||
|
||||
def configure(self, session):
|
||||
session.config["code"] = self.code
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue