Skip to content

Commit

Permalink
Fix #305: Add "pythonArgs" config property for interpreter arguments
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
int19h committed Aug 3, 2020
1 parent 09142fb commit 2c524fa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/debugpy/adapter/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()
Expand Down
2 changes: 2 additions & 0 deletions tests/debug/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class DebugConfig(collections.MutableMapping):
"postDebugTask": (),
"preLaunchTask": (),
"pyramid": False,
"python": (),
"pythonArgs": [],
"pythonPath": (),
"redirectOutput": False,
"rules": [],
Expand Down
15 changes: 7 additions & 8 deletions tests/debug/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions tests/debugpy/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,43 @@ 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
import debuggee
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,
]

0 comments on commit 2c524fa

Please sign in to comment.