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 c66077d
Show file tree
Hide file tree
Showing 5 changed files with 24 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+.
9 changes: 7 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
import importlib_metadata
import sys

if sys.version_info >= (3, 8):
from importlib import metadata
else:
import importlib_metadata as metadata


extensions = [
Expand All @@ -24,7 +29,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
8 changes: 6 additions & 2 deletions src/pluggy/manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import inspect
import sys
from . import _tracing
from .hooks import HookImpl, _HookRelay, _HookCaller, normalize_hookimpl_opts
import warnings

import importlib_metadata
if sys.version_info >= (3, 8):
from importlib import metadata
else:
import importlib_metadata as metadata


def _warn_for_function(warning, function):
Expand Down Expand Up @@ -279,7 +283,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
10 changes: 8 additions & 2 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
``PluginManager`` unit and public API testing.
"""
import pytest
import sys
import types
import importlib_metadata

from pluggy import (
PluginManager,
PluginValidationError,
Expand All @@ -12,6 +13,11 @@
HookspecMarker,
)

if sys.version_info >= (3, 8):
from importlib import metadata
else:
import importlib_metadata as metadata


hookspec = HookspecMarker("example")
hookimpl = HookimplMarker("example")
Expand Down Expand Up @@ -466,7 +472,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 c66077d

Please sign in to comment.