Skip to content

Commit 33205ce

Browse files
fix: Isolate pyhf contrib commands from rest of CLI (#1186)
* Move import pyhf.contrib.utils inside the contrib CLI functions - Guard the CLI API from missing extras without triggering warnings from using other modules CLI API * Update the modules to reimport in tests
1 parent 07fc449 commit 33205ce

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/pyhf/contrib/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import click
44
from pathlib import Path
55

6-
from . import utils
7-
86
logging.basicConfig()
97
log = logging.getLogger(__name__)
108

@@ -22,6 +20,10 @@ def cli():
2220
2321
$ python -m pip install pyhf[contrib]
2422
"""
23+
from . import utils # Guard CLI from missing extra
24+
25+
# TODO: https://github.com/scikit-hep/pyhf/issues/863
26+
_ = utils # Placate pyflakes
2527

2628

2729
@cli.command()
@@ -57,6 +59,8 @@ def download(archive_url, output_directory, verbose, force, compress):
5759
:class:`~pyhf.exceptions.InvalidArchiveHost`: if the provided archive host name is not known to be valid
5860
"""
5961
try:
62+
from . import utils
63+
6064
utils.download(archive_url, output_directory, force, compress)
6165

6266
if verbose:

tests/test_scripts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def test_missing_contrib_extra(caplog):
562562
if "pyhf.contrib.utils" in sys.modules:
563563
reload(sys.modules["pyhf.contrib.utils"])
564564
else:
565-
import_module("pyhf.cli")
565+
import_module("pyhf.contrib.utils")
566566

567567
with caplog.at_level(logging.ERROR):
568568
for line in [
@@ -577,10 +577,10 @@ def test_missing_contrib_extra(caplog):
577577
def test_missing_contrib_download(caplog):
578578
with mock.patch.dict(sys.modules):
579579
sys.modules["requests"] = None
580-
if "pyhf.cli" in sys.modules:
581-
reload(sys.modules["pyhf.cli"])
580+
if "pyhf.contrib.utils" in sys.modules:
581+
reload(sys.modules["pyhf.contrib.utils"])
582582
else:
583-
import_module("pyhf.cli")
583+
import_module("pyhf.contrib.utils")
584584

585585
# Force environment for runner
586586
for module in [

0 commit comments

Comments
 (0)