Skip to content

Commit

Permalink
Merge pull request #29 from flying-sheep/no-pkg-resources
Browse files Browse the repository at this point in the history
Switch to packaging and importlib_metadata
  • Loading branch information
mtkennerly committed Oct 9, 2021
2 parents 7e0c312 + 71dbec5 commit 1c16f9b
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 199 deletions.
12 changes: 8 additions & 4 deletions dunamai/__init__.py
@@ -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

0 comments on commit 1c16f9b

Please sign in to comment.