From e3496f56e4ae63d9557534cacb303a50c807a71e Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Thu, 15 Aug 2024 17:15:16 +0200 Subject: [PATCH 1/3] Add very simple test for version argument --- test/test_cli.py | 6 ++++++ 1 file changed, 6 insertions(+) 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'] From a94c0131e731a326c98243d6601280a19796d81d Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Thu, 15 Aug 2024 17:39:51 +0200 Subject: [PATCH 2/3] Use importlib feature instead of deprecated pkg_resources for version --- warcio/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/warcio/cli.py b/warcio/cli.py index efdf7c50..c3bf94e5 100644 --- a/warcio/cli.py +++ b/warcio/cli.py @@ -5,6 +5,7 @@ from warcio.extractor import Extractor from warcio.recompressor import Recompressor +from importlib.metadata import version import sys @@ -57,8 +58,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') # ============================================================================ From 2cdd2c3e99e0cd3bd5034d98fb77f30eb51a0a96 Mon Sep 17 00:00:00 2001 From: Natanael Arndt Date: Mon, 19 Aug 2024 12:33:26 +0200 Subject: [PATCH 3/3] Add python 3.7 compatibility for package metadata version --- warcio/cli.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/warcio/cli.py b/warcio/cli.py index c3bf94e5..df6369e5 100644 --- a/warcio/cli.py +++ b/warcio/cli.py @@ -5,7 +5,13 @@ from warcio.extractor import Extractor from warcio.recompressor import Recompressor -from importlib.metadata import version + +try: + from importlib.metadata import version +except ImportError: + import pkg_resources + def version(package): + return pkg_resources.get_distribution(package).version import sys