Skip to content

Commit

Permalink
fix: Use importlib.metadata instead of pkg_resources to get curre…
Browse files Browse the repository at this point in the history
…nt version
  • Loading branch information
pawamoy committed Nov 2, 2022
1 parent a31187e commit 79109d0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ classifiers = [
dependencies = [
"Jinja2>=2.10,<4",
"semver~=2.13",
"importlib-metadata; python_version < '3.8'",
]

[project.urls]
Expand Down
11 changes: 7 additions & 4 deletions src/git_changelog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
import sys
from typing import List, Optional

import pkg_resources
from jinja2.exceptions import TemplateNotFound

from git_changelog import templates
from git_changelog.build import Changelog

if sys.version_info < (3, 8):
import importlib_metadata as metadata
else:
from importlib import metadata # noqa: WPS440

STYLES = ("angular", "atom", "conventional", "basic")


Expand All @@ -41,10 +45,9 @@ def get_version() -> str:
The current `git-changelog` version.
"""
try:
distribution = pkg_resources.get_distribution("git-changelog")
except pkg_resources.DistributionNotFound:
return metadata.version("git-changelog")
except metadata.PackageNotFoundError:
return "0.0.0"
return distribution.version


def get_parser() -> argparse.ArgumentParser:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ def test_show_help(capsys):
cli.main(["-h"])
captured = capsys.readouterr()
assert "git-changelog" in captured.out


def test_get_version():
"""Get self version."""
assert cli.get_version()

0 comments on commit 79109d0

Please sign in to comment.