Skip to content

Commit

Permalink
Replace importlib_metadata with importlib.metadata on Python 3.8+
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Jul 2, 2019
1 parent 57b2a6d commit a0162b1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelog/222.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Replace ``importlib_metadata`` backport with ``importlib.metadata`` from the
standard library on Python 3.8+.
7 changes: 5 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import importlib_metadata
try:
from importlib import metadata
except ImportError:
import importlib_metadata as metadata


extensions = [
Expand All @@ -24,7 +27,7 @@
copyright = u"2016, Holger Krekel"
author = "Holger Krekel"

release = importlib_metadata.version(project)
release = metadata.version(project)
# The short X.Y version.
version = u".".join(release.split(".")[:2])

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def main():
author_email="holger@merlinux.eu",
url="https://github.com/pytest-dev/pluggy",
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
install_requires=["importlib-metadata>=0.12"],
install_requires=['importlib-metadata>=0.12;python_version<"3.8"'],
extras_require={"dev": ["pre-commit", "tox"]},
classifiers=classifiers,
packages=["pluggy"],
Expand Down
7 changes: 5 additions & 2 deletions src/pluggy/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from .hooks import HookImpl, _HookRelay, _HookCaller, normalize_hookimpl_opts
import warnings

import importlib_metadata
try:
from importlib import metadata
except ImportError:
import importlib_metadata as metadata


def _warn_for_function(warning, function):
Expand Down Expand Up @@ -279,7 +282,7 @@ def load_setuptools_entrypoints(self, group, name=None):
:return: return the number of loaded plugins by this call.
"""
count = 0
for dist in importlib_metadata.distributions():
for dist in metadata.distributions():
for ep in dist.entry_points:
if (
ep.group != group
Expand Down
9 changes: 7 additions & 2 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"""
import pytest
import types
import importlib_metadata

try:
from importlib import metadata
except ImportError:
import importlib_metadata as metadata

from pluggy import (
PluginManager,
PluginValidationError,
Expand Down Expand Up @@ -466,7 +471,7 @@ class Distribution(object):
def my_distributions():
return (dist,)

monkeypatch.setattr(importlib_metadata, "distributions", my_distributions)
monkeypatch.setattr(metadata, "distributions", my_distributions)
num = pm.load_setuptools_entrypoints("hello")
assert num == 1
plugin = pm.get_plugin("myname")
Expand Down

0 comments on commit a0162b1

Please sign in to comment.