From 61f934c4849d143e279f005eab77f5927882aa31 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Jan 2020 05:44:16 -0500 Subject: [PATCH 1/3] Prefer importlib.metadata for metadata loading. Fixes #271. --- docs/conf.py | 8 ++++++-- nox/__main__.py | 8 +++++--- setup.py | 1 + tests/test_main.py | 7 +++++-- 4 files changed, 17 insertions(+), 7 deletions(-) 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..40ae3f0f 100644 --- a/nox/__main__.py +++ b/nox/__main__.py @@ -21,7 +21,10 @@ import sys -import pkg_resources +try: + import importlib.metadata as metadata +except ImportError: + import importlib_metadata as metadata 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 From 2b7a4cb0af4a49ac0021247bd75bf9e3cc823aa8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Jan 2020 06:05:27 -0500 Subject: [PATCH 2/3] Suppress type errors --- nox/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nox/__main__.py b/nox/__main__.py index 40ae3f0f..15d21466 100644 --- a/nox/__main__.py +++ b/nox/__main__.py @@ -22,9 +22,9 @@ import sys try: - import importlib.metadata as metadata + import importlib.metadata as metadata # type: ignore except ImportError: - import importlib_metadata as metadata + import importlib_metadata as metadata # type: ignore from nox import _options, tasks, workflow from nox.logger import setup_logging From 32ad97e1c67f5c8aa225c38d2cfc33422b7586e3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Jan 2020 06:10:00 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(d?= =?UTF-8?q?elint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nox/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nox/__main__.py b/nox/__main__.py index 15d21466..f364882c 100644 --- a/nox/__main__.py +++ b/nox/__main__.py @@ -23,7 +23,7 @@ try: import importlib.metadata as metadata # type: ignore -except ImportError: +except ImportError: # pragma: no cover import importlib_metadata as metadata # type: ignore from nox import _options, tasks, workflow