diff --git a/src/debugpy/adapter/clients.py b/src/debugpy/adapter/clients.py index 09f982143..47d0f3bde 100644 --- a/src/debugpy/adapter/clients.py +++ b/src/debugpy/adapter/clients.py @@ -302,6 +302,8 @@ def property_or_debug_option(prop_name, flag_name): python = request(python_key, json.array(unicode, vectorize=True, size=(0,))) if not len(python): python = [compat.filename(sys.executable)] + + python += request("pythonArgs", json.array(unicode, size=(0,))) request.arguments["pythonArgs"] = python[1:] program = module = code = () diff --git a/tests/debug/config.py b/tests/debug/config.py index ff5550cea..7581b8c89 100644 --- a/tests/debug/config.py +++ b/tests/debug/config.py @@ -42,6 +42,8 @@ class DebugConfig(collections.MutableMapping): "postDebugTask": (), "preLaunchTask": (), "pyramid": False, + "python": (), + "pythonArgs": [], "pythonPath": (), "redirectOutput": False, "rules": [], diff --git a/tests/debug/runners.py b/tests/debug/runners.py index c7e5e6d7b..ef75963ff 100644 --- a/tests/debug/runners.py +++ b/tests/debug/runners.py @@ -117,23 +117,22 @@ def pytest_id(self): @_runner -def launch(session, target, console="integratedTerminal", cwd=None): - assert console in ("internalConsole", "integratedTerminal", "externalTerminal") +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) target.configure(session) config = session.config config.setdefaults( - { - "console": "externalTerminal", - "internalConsoleOptions": "neverOpen", - "pythonPath": sys.executable, - } + {"console": "externalTerminal", "internalConsoleOptions": "neverOpen"} ) - config["console"] = console + if console is not None: + config["console"] = console if cwd is not None: config["cwd"] = cwd + if "python" not in config and "pythonPath" not in config: + config["python"] = sys.executable env = ( session.spawn_adapter.env diff --git a/tests/debugpy/test_run.py b/tests/debugpy/test_run.py index 36ac4cdf9..f8bb9f784 100644 --- a/tests/debugpy/test_run.py +++ b/tests/debugpy/test_run.py @@ -138,7 +138,10 @@ def code_to_debug(): @pytest.mark.parametrize("run", runners.all_launch_terminal) -def test_custom_python(pyfile, run, target): +@pytest.mark.parametrize("python_args", ["", "-v"]) +@pytest.mark.parametrize("python", ["", "custompy", "custompy -O"]) +@pytest.mark.parametrize("python_key", ["python", "pythonPath"]) +def test_custom_python(pyfile, run, target, python_key, python, python_args): @pyfile def code_to_debug(): import sys @@ -146,19 +149,32 @@ def code_to_debug(): from debuggee import backchannel debuggee.setup() - backchannel.send(sys.executable) + backchannel.send([sys.executable, sys.flags.optimize, sys.flags.verbose]) + + python = python.split() + python_args = python_args.split() + python_cmd = (python if len(python) else [sys.executable]) + python_args class Session(debug.Session): def run_in_terminal(self, args, cwd, env): - assert args[:2] == ["CUSTOMPY", "-O"] + assert args[: len(python_cmd)] == python_cmd args[0] = sys.executable return super(Session, self).run_in_terminal(args, cwd, env) with Session() as session: - session.config["pythonPath"] = ["CUSTOMPY", "-O"] + session.config.pop("python", None) + session.config.pop("pythonPath", None) + if len(python): + session.config[python_key] = python[0] if len(python) == 1 else python + if len(python_args): + session.config["pythonArgs"] = python_args backchannel = session.open_backchannel() with run(session, target(code_to_debug)): pass - assert backchannel.receive() == sys.executable + assert backchannel.receive() == [ + sys.executable, + "-O" in python_cmd, + "-v" in python_cmd, + ]