Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add very simple test for version argument and use importlib feature instead of deprecated pkg_resources for version #173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
10 changes: 8 additions & 2 deletions warcio/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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')


# ============================================================================
Expand Down
Loading