diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-07-12 19:00:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-12 19:00:54 -0400 |
commit | aeacd50d8e397f08e928bd412ecac698a051d11e (patch) | |
tree | e541266f1a89ce0619dbe7645ee7d964d8848945 | |
parent | 6e19fb191dc0dd82416a9e9cc0b8e4a0ab5f200c (diff) | |
parent | 859d45bf8f7254858fbfb6167fe073479e712cfd (diff) | |
download | cmd2-git-aeacd50d8e397f08e928bd412ecac698a051d11e.tar.gz |
Merge pull request #953 from dhellmann/drop-pkg-resources
replace pkg_resources with importlib.metadata
-rw-r--r-- | cmd2/__init__.py | 11 | ||||
-rw-r--r-- | docs/conf.py | 4 | ||||
-rw-r--r-- | plugins/ext_test/cmd2_ext_test/__init__.py | 18 | ||||
-rwxr-xr-x | setup.py | 1 |
4 files changed, 22 insertions, 12 deletions
diff --git a/cmd2/__init__.py b/cmd2/__init__.py index d49427f2..8c07fb80 100644 --- a/cmd2/__init__.py +++ b/cmd2/__init__.py @@ -3,10 +3,15 @@ # flake8: noqa F401 """This simply imports certain things for backwards compatibility.""" -from pkg_resources import get_distribution, DistributionNotFound try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + # For python 3.8 and later + import importlib.metadata as importlib_metadata +except ImportError: + # For everyone else + import importlib_metadata +try: + __version__ = importlib_metadata.version(__name__) +except importlib_metadata.PackageNotFoundError: # package is not installed pass diff --git a/docs/conf.py b/docs/conf.py index 6c6faf0d..8a71268a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,7 +19,7 @@ documentation root, use os.path.abspath to make it absolute, like shown here. """ # Import for custom theme from Read the Docs import sphinx_rtd_theme -from pkg_resources import get_distribution +import cmd2 # -- General configuration ----------------------------------------------------- @@ -57,7 +57,7 @@ author = 'cmd2 contributors' # built documents. # # version will look like x.y.z -version = get_distribution('cmd2').version +version = cmd2.__version__ # release will look like x.y release = '.'.join(version.split('.')[:2]) diff --git a/plugins/ext_test/cmd2_ext_test/__init__.py b/plugins/ext_test/cmd2_ext_test/__init__.py index dc52b4d9..dbbc4250 100644 --- a/plugins/ext_test/cmd2_ext_test/__init__.py +++ b/plugins/ext_test/cmd2_ext_test/__init__.py @@ -5,16 +5,20 @@ An overview of what myplugin does. """ -from pkg_resources import DistributionNotFound, get_distribution +try: + # For python 3.8 and later + import importlib.metadata as importlib_metadata +except ImportError: + # For everyone else + import importlib_metadata +try: + __version__ = importlib_metadata.version(__name__) +except importlib_metadata.PackageNotFoundError: + # package is not installed + __version__ = 'unknown' from .cmd2_ext_test import ExternalTestMixin __all__ = [ 'ExternalTestMixin' ] - - -try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: - __version__ = 'unknown' @@ -36,6 +36,7 @@ SETUP_REQUIRES = ['setuptools_scm >= 3.0'] INSTALL_REQUIRES = [ 'attrs >= 16.3.0', 'colorama >= 0.3.7', + 'importlib_metadata>=1.7.0;python_version<"3.8"', 'pyperclip >= 1.6', 'setuptools >= 34.4', 'wcwidth >= 0.1.7', |