From 671ed56483bc602876f611cf10ff9add7f4a2137 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 22 Apr 2021 02:52:50 +0200 Subject: [PATCH] feat: `pyhf patchset inspect` (#1412) * pyhf patchset inspect --- src/pyhf/cli/patchset.py | 19 +++++++++++++++++++ tests/test_scripts.py | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/pyhf/cli/patchset.py b/src/pyhf/cli/patchset.py index 00090191c4..ad54fbd256 100644 --- a/src/pyhf/cli/patchset.py +++ b/src/pyhf/cli/patchset.py @@ -123,3 +123,22 @@ def verify(background_only, patchset): patchset.verify(ws) click.echo("All good.") + + +@cli.command() +@click.argument('patchset', default='-') +def inspect(patchset): + """ + Inspect the PatchSet (e.g. list individual patches). + + Returns: + None + """ + with click.open_file(patchset, 'r') as fstream: + patchset_spec = json.load(fstream) + + patchset = PatchSet(patchset_spec) + click.secho(f'\n {len(patchset.patches)} patches found in Patchset') + click.secho('---------------------------------\n') + for p in patchset.patches: + click.echo(p.name) diff --git a/tests/test_scripts.py b/tests/test_scripts.py index eaaba365bb..40f2b24b47 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -626,6 +626,12 @@ def test_missing_contrib_download(caplog): caplog.clear() +def test_patchset_inspect(datadir, script_runner): + command = f'pyhf patchset inspect {datadir.join("example_patchset.json").strpath}' + ret = script_runner.run(*shlex.split(command)) + assert 'patch_channel1_signal_syst1' in ret.stdout + + @pytest.mark.parametrize('output_file', [False, True]) @pytest.mark.parametrize('with_metadata', [False, True]) def test_patchset_extract(datadir, tmpdir, script_runner, output_file, with_metadata):