diff --git a/test/test_cli.py b/test/test_cli.py index 04e05887..58edc584 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -12,6 +12,12 @@ import tempfile import os +def test_version(capsys): + with pytest.raises(SystemExit): + main(args=['--version']) + out, err = capsys.readouterr() + print(out, err) + assert len(out) > 0 def test_index(capsys): files = ['example.warc.gz', 'example.warc', 'example.arc.gz', 'example.arc'] diff --git a/warcio/cli.py b/warcio/cli.py index efdf7c50..df6369e5 100644 --- a/warcio/cli.py +++ b/warcio/cli.py @@ -5,6 +5,13 @@ from warcio.extractor import Extractor from warcio.recompressor import Recompressor + +try: + from importlib.metadata import version +except ImportError: + import pkg_resources + def version(package): + return pkg_resources.get_distribution(package).version import sys @@ -57,8 +64,7 @@ def main(args=None): # ============================================================================ def get_version(): - import pkg_resources - return '%(prog)s ' + pkg_resources.get_distribution('warcio').version + return '%(prog)s ' + version('warcio') # ============================================================================