Skip to content

Commit 2c524fa

Browse files
committed
Fix #305: Add "pythonArgs" config property for interpreter arguments
Expose "pythonArgs" to clients. Make "python" usable in tests in lieu of "pythonPath", and make the runners use it. Add tests for all combinations of "python"/"pythonPath" and "pythonArgs".
1 parent 09142fb commit 2c524fa

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

src/debugpy/adapter/clients.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ def property_or_debug_option(prop_name, flag_name):
302302
python = request(python_key, json.array(unicode, vectorize=True, size=(0,)))
303303
if not len(python):
304304
python = [compat.filename(sys.executable)]
305+
306+
python += request("pythonArgs", json.array(unicode, size=(0,)))
305307
request.arguments["pythonArgs"] = python[1:]
306308

307309
program = module = code = ()

tests/debug/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class DebugConfig(collections.MutableMapping):
4242
"postDebugTask": (),
4343
"preLaunchTask": (),
4444
"pyramid": False,
45+
"python": (),
46+
"pythonArgs": [],
4547
"pythonPath": (),
4648
"redirectOutput": False,
4749
"rules": [],

tests/debug/runners.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,22 @@ def pytest_id(self):
117117

118118

119119
@_runner
120-
def launch(session, target, console="integratedTerminal", cwd=None):
121-
assert console in ("internalConsole", "integratedTerminal", "externalTerminal")
120+
def launch(session, target, console=None, cwd=None):
121+
assert console in (None, "internalConsole", "integratedTerminal", "externalTerminal")
122122

123123
log.info("Launching {0} in {1} using {2!j}.", target, session, console)
124124

125125
target.configure(session)
126126
config = session.config
127127
config.setdefaults(
128-
{
129-
"console": "externalTerminal",
130-
"internalConsoleOptions": "neverOpen",
131-
"pythonPath": sys.executable,
132-
}
128+
{"console": "externalTerminal", "internalConsoleOptions": "neverOpen"}
133129
)
134-
config["console"] = console
130+
if console is not None:
131+
config["console"] = console
135132
if cwd is not None:
136133
config["cwd"] = cwd
134+
if "python" not in config and "pythonPath" not in config:
135+
config["python"] = sys.executable
137136

138137
env = (
139138
session.spawn_adapter.env

tests/debugpy/test_run.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,43 @@ def code_to_debug():
138138

139139

140140
@pytest.mark.parametrize("run", runners.all_launch_terminal)
141-
def test_custom_python(pyfile, run, target):
141+
@pytest.mark.parametrize("python_args", ["", "-v"])
142+
@pytest.mark.parametrize("python", ["", "custompy", "custompy -O"])
143+
@pytest.mark.parametrize("python_key", ["python", "pythonPath"])
144+
def test_custom_python(pyfile, run, target, python_key, python, python_args):
142145
@pyfile
143146
def code_to_debug():
144147
import sys
145148
import debuggee
146149
from debuggee import backchannel
147150

148151
debuggee.setup()
149-
backchannel.send(sys.executable)
152+
backchannel.send([sys.executable, sys.flags.optimize, sys.flags.verbose])
153+
154+
python = python.split()
155+
python_args = python_args.split()
156+
python_cmd = (python if len(python) else [sys.executable]) + python_args
150157

151158
class Session(debug.Session):
152159
def run_in_terminal(self, args, cwd, env):
153-
assert args[:2] == ["CUSTOMPY", "-O"]
160+
assert args[: len(python_cmd)] == python_cmd
154161
args[0] = sys.executable
155162
return super(Session, self).run_in_terminal(args, cwd, env)
156163

157164
with Session() as session:
158-
session.config["pythonPath"] = ["CUSTOMPY", "-O"]
165+
session.config.pop("python", None)
166+
session.config.pop("pythonPath", None)
167+
if len(python):
168+
session.config[python_key] = python[0] if len(python) == 1 else python
169+
if len(python_args):
170+
session.config["pythonArgs"] = python_args
159171

160172
backchannel = session.open_backchannel()
161173
with run(session, target(code_to_debug)):
162174
pass
163175

164-
assert backchannel.receive() == sys.executable
176+
assert backchannel.receive() == [
177+
sys.executable,
178+
"-O" in python_cmd,
179+
"-v" in python_cmd,
180+
]

0 commit comments

Comments
 (0)