Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer importlib.metadata for metadata loading. #277

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions nox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

import sys

import pkg_resources
try:
import importlib.metadata as metadata # type: ignore
except ImportError: # pragma: no cover
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, when would this branch get hit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Python 3.7 or earlier.

import importlib_metadata as metadata # type: ignore

from nox import _options, tasks, workflow
from nox.logger import setup_logging
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down
7 changes: 5 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down