From c8fbbba497c4d8b2700604637cab26793e1421c5 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Mon, 21 Sep 2020 08:22:55 +0100 Subject: [PATCH] Also support --python= arg format Signed-off-by: Bernat Gabor --- pipdeptree.py | 9 ++++++--- tests/test_pipdeptree.py | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pipdeptree.py b/pipdeptree.py index f2f6a09..540ca7a 100644 --- a/pipdeptree.py +++ b/pipdeptree.py @@ -791,9 +791,12 @@ def handle_non_host_target(args): " non-host python", file=sys.stderr) raise SystemExit(1) argv = sys.argv[1:] # remove current python executable - py_at = argv.index('--python') # plus the new python target - del argv[py_at] - del argv[py_at] + for py_at, value in enumerate(argv): + if value == "--python": + del argv[py_at] + del argv[py_at] + elif value.startswith("--python"): + del argv[py_at] # feed the file as argument, instead of file # to avoid adding the file path to sys.path, that can affect result file_path = inspect.getsourcefile(sys.modules[__name__]) diff --git a/tests/test_pipdeptree.py b/tests/test_pipdeptree.py index b78bda0..610a6f5 100644 --- a/tests/test_pipdeptree.py +++ b/tests/test_pipdeptree.py @@ -523,9 +523,11 @@ def test_parser_svg(): assert not args.json -def test_custom_interpreter(tmp_path, monkeypatch, capfd): +@pytest.mark.parametrize('args_joined', [True, False]) +def test_custom_interpreter(tmp_path, monkeypatch, capfd, args_joined): result = virtualenv.cli_run([str(tmp_path), '--activators', '']) - cmd = [sys.executable, '--python', str(result.creator.exe)] + cmd = [sys.executable] + cmd += ['--python={}'.format(result.creator.exe)] if args_joined else ['--python', str(result.creator.exe)] monkeypatch.setattr(sys, 'argv', cmd) p.main() out, _ = capfd.readouterr()