Skip to content

Commit

Permalink
feat: use importlib instead of deprecated pkg_resources for version
Browse files Browse the repository at this point in the history
* Add very simple test for version argument
* Add python 3.7 compatibility for package metadata version
  • Loading branch information
white-gecko authored Aug 20, 2024
1 parent 52dd0ab commit 29da916
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit 29da916

Please sign in to comment.