Skip to content

Commit 41b4675

Browse files
committed
argpase: colorize the --help output with rich-argparse
1 parent 7fa57dd commit 41b4675

File tree

9 files changed

+32
-11
lines changed

9 files changed

+32
-11
lines changed

.github/workflows/ci-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ jobs:
157157
chmod a-w .
158158
159159
- name: run tests
160-
run: APPTAINER_TMPDIR=${RUNNER_TEMP} make test
160+
run: APPTAINER_TMPDIR=${RUNNER_TEMP} make test PYTEST_EXTRA=-vvv
161161

162162

163163
conformance_tests:

cwltool/argparser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from collections.abc import MutableMapping, MutableSequence, Sequence
77
from typing import Any, Callable, Optional, Union, cast
88

9+
import rich.markup
10+
from rich_argparse import RichHelpFormatter
11+
912
from .loghandler import _logger
1013
from .process import Process, shortname
1114
from .resolver import ga4gh_tool_registries
@@ -15,8 +18,9 @@
1518

1619
def arg_parser() -> argparse.ArgumentParser:
1720
parser = argparse.ArgumentParser(
21+
formatter_class=RichHelpFormatter,
1822
description="Reference executor for Common Workflow Language standards. "
19-
"Not for production use."
23+
"Not for production use.",
2024
)
2125
parser.add_argument("--basedir", type=str)
2226
parser.add_argument(
@@ -855,6 +859,7 @@ def add_argument(
855859
urljoin: Callable[[str, str], str] = urllib.parse.urljoin,
856860
base_uri: str = "",
857861
) -> None:
862+
description = rich.markup.escape(description)
858863
if len(name) == 1:
859864
flag = "-"
860865
else:

cwltool/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import coloredlogs
2323
import requests
2424
import ruamel.yaml
25+
from rich_argparse import RichHelpFormatter
2526
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2627
from ruamel.yaml.main import YAML
2728
from schema_salad.exceptions import ValidationException
@@ -413,7 +414,10 @@ def init_job_order(
413414
namemap: dict[str, str] = {}
414415
records: list[str] = []
415416
toolparser = generate_parser(
416-
argparse.ArgumentParser(prog=args.workflow),
417+
argparse.ArgumentParser(
418+
prog=args.workflow,
419+
formatter_class=RichHelpFormatter,
420+
),
417421
process,
418422
namemap,
419423
records,

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ requires = [
1111
"cwl-utils>=0.32",
1212
"toml",
1313
"argcomplete>=1.12.0",
14+
"rich-argparse"
1415
]
1516
build-backend = "setuptools.build_meta"
1617

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ argcomplete>=1.12.0
1212
pyparsing!=3.0.2 # breaks --print-dot (pydot) https://github.com/pyparsing/pyparsing/issues/319
1313
cwl-utils>=0.32
1414
spython>=0.3.0
15+
rich-argparse

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"pyparsing != 3.0.2", # breaks --print-dot (pydot) https://github.com/pyparsing/pyparsing/issues/319
136136
"cwl-utils >= 0.32",
137137
"spython >= 0.3.0",
138+
"rich-argparse",
138139
],
139140
extras_require={
140141
"deps": [

tests/test_environment.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from abc import ABC, abstractmethod
55
from collections.abc import Mapping
66
from pathlib import Path
7-
from typing import Any, Callable, Union
7+
from typing import Callable, Union
88

99
import pytest
1010

@@ -198,7 +198,7 @@ def BIND(v: str, env: Env) -> bool:
198198

199199

200200
@CRT_PARAMS
201-
def test_basic(crt_params: CheckHolder, tmp_path: Path, monkeypatch: Any) -> None:
201+
def test_basic(crt_params: CheckHolder, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
202202
"""Test that basic env vars (only) show up."""
203203
tmp_prefix = str(tmp_path / "canary")
204204
extra_env = {
@@ -218,7 +218,9 @@ def test_basic(crt_params: CheckHolder, tmp_path: Path, monkeypatch: Any) -> Non
218218

219219

220220
@CRT_PARAMS
221-
def test_preserve_single(crt_params: CheckHolder, tmp_path: Path, monkeypatch: Any) -> None:
221+
def test_preserve_single(
222+
crt_params: CheckHolder, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
223+
) -> None:
222224
"""Test that preserving a single env var works."""
223225
tmp_prefix = str(tmp_path / "canary")
224226
extra_env = {
@@ -242,7 +244,9 @@ def test_preserve_single(crt_params: CheckHolder, tmp_path: Path, monkeypatch: A
242244

243245

244246
@CRT_PARAMS
245-
def test_preserve_all(crt_params: CheckHolder, tmp_path: Path, monkeypatch: Any) -> None:
247+
def test_preserve_all(
248+
crt_params: CheckHolder, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
249+
) -> None:
246250
"""Test that preserving all works."""
247251
tmp_prefix = str(tmp_path / "canary")
248252
extra_env = {

tests/test_misc_cli.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tests for various command line options."""
22

3+
import pytest
4+
35
from cwltool.utils import versionstring
46

57
from .util import get_data, get_main_output, needs_docker
@@ -26,9 +28,13 @@ def test_empty_cmdling() -> None:
2628
assert "CWL document required, no input file was provided" in stderr
2729

2830

29-
def test_tool_help() -> None:
31+
def test_tool_help(monkeypatch: pytest.MonkeyPatch) -> None:
3032
"""Test --tool-help."""
31-
return_code, stdout, stderr = get_main_output(["--tool-help", get_data("tests/echo.cwl")])
33+
return_code, stdout, stderr = get_main_output(
34+
["--tool-help", get_data("tests/echo.cwl")],
35+
extra_env={"NO_COLOR": "1"},
36+
monkeypatch=monkeypatch,
37+
)
3238
assert return_code == 0
3339
assert "job_order Job input json file" in stdout
3440

tests/test_singularity.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import shutil
44
from pathlib import Path
5-
from typing import Any
65

76
import pytest
87

@@ -19,7 +18,7 @@
1918

2019

2120
@needs_singularity_2_6
22-
def test_singularity_pullfolder(tmp_path: Path, monkeypatch: Any) -> None:
21+
def test_singularity_pullfolder(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
2322
"""Test singularity respects SINGULARITY_PULLFOLDER."""
2423
workdir = tmp_path / "working_dir_new"
2524
workdir.mkdir()

0 commit comments

Comments
 (0)