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

Switch to packaging and importlib_metadata #29

Merged
merged 2 commits into from
Oct 9, 2021
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
12 changes: 8 additions & 4 deletions dunamai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__all__ = ["check_version", "get_version", "Style", "Vcs", "Version"]

import datetime as dt
import pkg_resources
import re
import shlex
import shutil
Expand Down Expand Up @@ -355,8 +354,9 @@ def __lt__(self, other: Any) -> bool:
raise TypeError(
"Cannot compare Version with type {}".format(other.__class__.__qualname__)
)
import packaging.version as pv
return (
pkg_resources.parse_version(self.base) < pkg_resources.parse_version(other.base)
pv.Version(self.base) < pv.Version(other.base)
and _blank(self.stage, "") < _blank(other.stage, "")
and _blank(self.revision, 0) < _blank(other.revision, 0)
and _blank(self.distance, 0) < _blank(other.distance, 0)
Expand Down Expand Up @@ -951,8 +951,12 @@ def get_version(
return first_ver

try:
return Version(pkg_resources.get_distribution(name).version)
except pkg_resources.DistributionNotFound:
import importlib.metadata as ilm
except ImportError:
import importlib_metadata as ilm
try:
return Version(ilm.version(name))
except ilm.PackageNotFoundError:
pass

if third_choice:
Expand Down
File renamed without changes.
Loading