Skip to content

Commit

Permalink
Switch to packaging and importlib_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Oct 8, 2021
1 parent 18dfa02 commit 9a8729d
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 199 deletions.
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

0 comments on commit 9a8729d

Please sign in to comment.