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".
This commit is contained in:
Pavel Minaev 2020-07-31 02:19:24 -07:00
parent 09142fb34d
commit 2c524faacd
4 changed files with 32 additions and 13 deletions

View file

@ -302,6 +302,8 @@ class Client(components.Component):
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 = ()

View file

@ -42,6 +42,8 @@ class DebugConfig(collections.MutableMapping):
"postDebugTask": (),
"preLaunchTask": (),
"pyramid": False,
"python": (),
"pythonArgs": [],
"pythonPath": (),
"redirectOutput": False,
"rules": [],

View file

@ -117,23 +117,22 @@ def _runner(f):
@_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

View file

@ -138,7 +138,10 @@ def test_sudo(pyfile, tmpdir, run, target):
@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 test_custom_python(pyfile, run, target):
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,
]