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

Replace importlib_metadata with importlib.metadata on Python 3.8+ #223

Merged
merged 3 commits into from Jul 3, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Expand Up @@ -32,16 +32,16 @@ jobs:
env: TOXENV=py37-pytestrelease-coverage
- python: '3.8-dev'
env: TOXENV=py38-pytestrelease-coverage
- python: '2.7'
env: TOXENV=py27-pytestmaster-coverage
- python: '2.7'
env: TOXENV=py27-pytestfeatures-coverage
- python: '3.6'
env: TOXENV=py36-pytestmaster-coverage
- python: '3.6'
env: TOXENV=py36-pytestfeatures-coverage
- python: '3.6'
env: TOXENV=benchmark
- python: '3.7'
env: TOXENV=py37-pytestmaster-coverage
- python: '3.7'
env: TOXENV=py37-pytestfeatures-coverage

- stage: deploy
python: '3.6'
Expand Down
3 changes: 1 addition & 2 deletions appveyor.yml
Expand Up @@ -7,9 +7,8 @@ environment:
- TOXENV: "py34-pytestrelease"
- TOXENV: "py35-pytestrelease"
- TOXENV: "py36-pytestrelease"
- TOXENV: "py37-pytestrelease"
- TOXENV: "pypy-pytestrelease"
- TOXENV: "py27-pytestmaster"
- TOXENV: "py27-pytestfeatures"
- TOXENV: "py36-pytestmaster"
- TOXENV: "py36-pytestfeatures"

Expand Down
2 changes: 2 additions & 0 deletions changelog/222.trivial.rst
@@ -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
@@ -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
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
@@ -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
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

Copy link
Contributor

@blueyed blueyed Aug 20, 2019

Choose a reason for hiding this comment

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

Just wondered if this could/should import/use it from src/pluggy/manager.py?
=> #230


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
4 changes: 2 additions & 2 deletions tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist=linting,docs,py{27,34,35,36,py,py3}-pytestrelease,py{27,36}-pytest{master,features}
envlist=linting,docs,py{27,34,35,36,37,38,py,py3}-pytestrelease,py{36,37}-pytest{master,features}

[testenv]
commands=
Expand Down Expand Up @@ -38,7 +38,7 @@ commands =
minversion=2.0
testpaths = testing
#--pyargs --doctest-modules --ignore=.tox
addopts=-ra
addopts=-r a
filterwarnings =
error

Expand Down