(session, target, method, cwd=None, wait=True, log_dir=None)
| 209 | |
| 210 | @_runner |
| 211 | def attach_connect(session, target, method, cwd=None, wait=True, log_dir=None): |
| 212 | log.info( |
| 213 | "Attaching {0} to {1} by socket using {2}.", session, target, method.upper() |
| 214 | ) |
| 215 | |
| 216 | assert method in ("api", "cli") |
| 217 | |
| 218 | config = _attach_common_config(session, target, cwd) |
| 219 | config["connect"] = {} |
| 220 | config["connect"]["host"] = host = attach_connect.host |
| 221 | config["connect"]["port"] = port = attach_connect.port |
| 222 | |
| 223 | if method == "cli": |
| 224 | args = [ |
| 225 | os.path.dirname(debugpy.__file__), |
| 226 | "--listen", |
| 227 | f"{host}:{port}", |
| 228 | ] |
| 229 | if wait: |
| 230 | args += ["--wait-for-client"] |
| 231 | if log_dir is not None: |
| 232 | args += ["--log-to", log_dir] |
| 233 | if "subProcess" in config: |
| 234 | args += ["--configure-subProcess", str(config["subProcess"])] |
| 235 | debuggee_setup = None |
| 236 | elif method == "api": |
| 237 | args = [] |
| 238 | api_config = {k: v for k, v in config.items() if k in {"subProcess"}} |
| 239 | debuggee_setup = """ |
| 240 | import debugpy |
| 241 | if {log_dir!r}: |
| 242 | debugpy.log_to({log_dir!r}) |
| 243 | debugpy.configure({api_config!r}) |
| 244 | debugpy.listen(({host!r}, {port!r})) |
| 245 | if {wait!r}: |
| 246 | debugpy.wait_for_client() |
| 247 | """ |
| 248 | debuggee_setup = debuggee_setup.format( |
| 249 | host=host, |
| 250 | port=port, |
| 251 | wait=wait, |
| 252 | log_dir=log_dir, |
| 253 | api_config=api_config, |
| 254 | ) |
| 255 | else: |
| 256 | raise ValueError |
| 257 | args += target.cli(session.spawn_debuggee.env) |
| 258 | |
| 259 | try: |
| 260 | del config["subProcess"] |
| 261 | except KeyError: |
| 262 | pass |
| 263 | |
| 264 | # If adapter is connecting to the client, the server is already started, |
| 265 | # so it should be reported in the initial event. |
| 266 | session.expect_server_socket() |
| 267 | |
| 268 | session.spawn_debuggee(args, cwd=cwd, setup=debuggee_setup) |
nothing calls this directly
no test coverage detected
searching dependent graphs…