diff --git a/docs/conf.py b/docs/conf.py index c758c912..a7029aaf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,9 +13,13 @@ # serve to show the default. import os -import pkg_resources import sys +try: + import importlib.metadata as metadata +except ImportError: + import importlib_metadata as metadata + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -63,7 +67,7 @@ # built documents. # # The short X.Y version. -version = pkg_resources.get_distribution('nox').version +version = metadata.version('nox') # The full version, including alpha/beta/rc tags. release = version diff --git a/nox/__main__.py b/nox/__main__.py index 57100598..f364882c 100644 --- a/nox/__main__.py +++ b/nox/__main__.py @@ -21,7 +21,10 @@ import sys -import pkg_resources +try: + import importlib.metadata as metadata # type: ignore +except ImportError: # pragma: no cover + import importlib_metadata as metadata # type: ignore from nox import _options, tasks, workflow from nox.logger import setup_logging @@ -35,8 +38,7 @@ def main(): return if args.version: - dist = pkg_resources.get_distribution("nox") - print(dist.version, file=sys.stderr) + print(metadata.version("nox"), file=sys.stderr) return setup_logging(color=args.color, verbose=args.verbose) diff --git a/setup.py b/setup.py index 5875cd58..c39ab6f6 100644 --- a/setup.py +++ b/setup.py @@ -54,6 +54,7 @@ "colorlog>=2.6.1,<5.0.0", "py>=1.4.0,<2.0.0", "virtualenv>=14.0.0", + "importlib_metadata; python_version < '3.8'", ], extras_require={"tox_to_nox": ["jinja2", "tox"]}, entry_points={ diff --git a/tests/test_main.py b/tests/test_main.py index 48df1591..11464da7 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -16,7 +16,10 @@ import sys from unittest import mock -import pkg_resources +try: + import importlib.metadata as metadata +except ImportError: + import importlib_metadata as metadata import contexter import nox @@ -27,7 +30,7 @@ import pytest RESOURCES = os.path.join(os.path.dirname(__file__), "resources") -VERSION = pkg_resources.get_distribution("nox").version +VERSION = metadata.version("nox") # This is needed because CI systems will mess up these tests due to the