Skip to content

Commit 2a748ed

Browse files
committed
Only force prog=cwltool for the cwl-runner alias (#1535)
Per review feedback: an unconditional prog="cwltool" would leak into downstream tools that reuse cwltool.argparser.arg_parser() as their base parser (e.g. Calrissian), changing their --help/usage program name. Scope the override to the actual invocation name: set prog="cwltool" only when invoked as the generic "cwl-runner" alias, otherwise leave it None so argparse's basename default is preserved. Toil and Arvados are unaffected either way (they build their own parsers). Added a test asserting a downstream invocation name is preserved.
1 parent 9a588df commit 2a748ed

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

cwltool/argparser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ def arg_parser() -> argparse.ArgumentParser:
8989
)
9090

9191
parser = argparse.ArgumentParser(
92-
prog="cwltool",
92+
# Force the program name to "cwltool" only when invoked through the
93+
# generic ``cwl-runner`` alias (see #1535). Leaving it as ``None`` for
94+
# any other invocation preserves argparse's basename default, so
95+
# downstream tools that reuse this parser (e.g. Calrissian) keep their
96+
# own program name.
97+
prog="cwltool" if os.path.basename(sys.argv[0]) == "cwl-runner" else None,
9398
formatter_class=RichHelpFormatter,
9499
description="Reference executor for Common Workflow Language standards. "
95100
"Not for production use.",

tests/test_toolargparse.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,24 @@ def test_argparser_without_doc() -> None:
280280

281281

282282
def test_argparser_prog_is_cwltool(monkeypatch: pytest.MonkeyPatch) -> None:
283-
"""The program name is reported as ``cwltool`` even when invoked as ``cwl-runner``.
283+
"""The program name is reported as ``cwltool`` when invoked as ``cwl-runner``.
284284
285285
Regression test for https://github.com/common-workflow-language/cwltool/issues/1535
286286
"""
287-
monkeypatch.setattr(sys, "argv", ["cwl-runner", "--help"])
287+
monkeypatch.setattr(sys, "argv", ["/usr/local/bin/cwl-runner", "--help"])
288288
assert arg_parser().prog == "cwltool"
289289

290290

291+
def test_argparser_prog_preserves_downstream_name(monkeypatch: pytest.MonkeyPatch) -> None:
292+
"""Reusers of ``arg_parser()`` keep their own program name (not forced to ``cwltool``).
293+
294+
Downstream tools such as Calrissian call :func:`arg_parser` directly and rely on
295+
argparse's basename default; the ``cwl-runner`` override must not leak into them.
296+
"""
297+
monkeypatch.setattr(sys, "argv", ["/usr/local/bin/calrissian", "--help"])
298+
assert arg_parser().prog == "calrissian"
299+
300+
291301
@pytest.mark.parametrize(
292302
"job_order,expected_values",
293303
[

0 commit comments

Comments
 (0)