Use importlib.metadata from stdlib on Python 3.8
This commit is contained in:
parent
9376c2ee82
commit
df813420f6
129
5539.patch
Normal file
129
5539.patch
Normal file
@ -0,0 +1,129 @@
|
||||
From c54cbd63c8bc5db6626d26c0f3339a552a6b1a90 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
|
||||
Date: Wed, 3 Jul 2019 01:46:44 +0200
|
||||
Subject: [PATCH] Replace importlib_metadata with importlib.metadata on
|
||||
Python 3.8+
|
||||
|
||||
Fixes https://github.com/pytest-dev/pytest/issues/5537
|
||||
---
|
||||
changelog/5537.bugfix.rst | 2 ++
|
||||
setup.py | 2 +-
|
||||
src/_pytest/compat.py | 6 ++++++
|
||||
src/_pytest/config/__init__.py | 2 +-
|
||||
testing/acceptance_test.py | 2 +-
|
||||
testing/test_assertion.py | 3 ++-
|
||||
testing/test_config.py | 3 +--
|
||||
testing/test_entry_points.py | 2 +-
|
||||
8 files changed, 15 insertions(+), 7 deletions(-)
|
||||
create mode 100644 changelog/5537.bugfix.rst
|
||||
|
||||
diff --git a/setup.py b/setup.py
|
||||
index 18d3220..491a6f5 100644
|
||||
--- a/setup.py
|
||||
+++ b/setup.py
|
||||
@@ -15,7 +15,7 @@ INSTALL_REQUIRES = [
|
||||
'pathlib2>=2.2.0;python_version<"3.6"',
|
||||
'colorama;sys_platform=="win32"',
|
||||
"pluggy>=0.12,<1.0",
|
||||
- "importlib-metadata>=0.12",
|
||||
+ 'importlib-metadata>=0.12;python_version<"3.8"',
|
||||
"wcwidth",
|
||||
]
|
||||
|
||||
diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py
|
||||
index df661bf..4366391 100644
|
||||
--- a/src/_pytest/compat.py
|
||||
+++ b/src/_pytest/compat.py
|
||||
@@ -61,6 +61,12 @@ else:
|
||||
return None
|
||||
|
||||
|
||||
+if sys.version_info >= (3, 8):
|
||||
+ from importlib import metadata as importlib_metadata # noqa
|
||||
+else:
|
||||
+ import importlib_metadata # noqa
|
||||
+
|
||||
+
|
||||
def _format_args(func):
|
||||
return str(signature(func))
|
||||
|
||||
diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py
|
||||
index 6d44bf3..b35faff 100644
|
||||
--- a/src/_pytest/config/__init__.py
|
||||
+++ b/src/_pytest/config/__init__.py
|
||||
@@ -13,7 +13,6 @@ import sys
|
||||
import types
|
||||
import warnings
|
||||
|
||||
-import importlib_metadata
|
||||
import py
|
||||
import six
|
||||
from packaging.version import Version
|
||||
@@ -31,6 +30,7 @@ from .findpaths import exists
|
||||
from _pytest import deprecated
|
||||
from _pytest._code import ExceptionInfo
|
||||
from _pytest._code import filter_traceback
|
||||
+from _pytest.compat import importlib_metadata
|
||||
from _pytest.compat import lru_cache
|
||||
from _pytest.compat import safe_str
|
||||
from _pytest.outcomes import fail
|
||||
diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py
|
||||
index 7016cf1..2e1a3fa 100644
|
||||
--- a/testing/acceptance_test.py
|
||||
+++ b/testing/acceptance_test.py
|
||||
@@ -9,11 +9,11 @@ import textwrap
|
||||
import types
|
||||
|
||||
import attr
|
||||
-import importlib_metadata
|
||||
import py
|
||||
import six
|
||||
|
||||
import pytest
|
||||
+from _pytest.compat import importlib_metadata
|
||||
from _pytest.main import EXIT_NOTESTSCOLLECTED
|
||||
from _pytest.main import EXIT_USAGEERROR
|
||||
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
||||
diff --git a/testing/test_assertion.py b/testing/test_assertion.py
|
||||
index 2085ffd..61b990a 100644
|
||||
--- a/testing/test_assertion.py
|
||||
+++ b/testing/test_assertion.py
|
||||
@@ -179,7 +179,8 @@ class TestImportHookInstallation(object):
|
||||
return check
|
||||
""",
|
||||
"mainwrapper.py": """\
|
||||
- import pytest, importlib_metadata
|
||||
+ import pytest
|
||||
+ from _pytest.compat import importlib_metadata
|
||||
|
||||
class DummyEntryPoint(object):
|
||||
name = 'spam'
|
||||
diff --git a/testing/test_config.py b/testing/test_config.py
|
||||
index 0678a0d..60cdbaf 100644
|
||||
--- a/testing/test_config.py
|
||||
+++ b/testing/test_config.py
|
||||
@@ -6,10 +6,9 @@ from __future__ import print_function
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
-import importlib_metadata
|
||||
-
|
||||
import _pytest._code
|
||||
import pytest
|
||||
+from _pytest.compat import importlib_metadata
|
||||
from _pytest.config import _iter_rewritable_modules
|
||||
from _pytest.config.exceptions import UsageError
|
||||
from _pytest.config.findpaths import determine_setup
|
||||
diff --git a/testing/test_entry_points.py b/testing/test_entry_points.py
|
||||
index ad64d00..95ebc41 100644
|
||||
--- a/testing/test_entry_points.py
|
||||
+++ b/testing/test_entry_points.py
|
||||
@@ -3,7 +3,7 @@ from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
-import importlib_metadata
|
||||
+from _pytest.compat import importlib_metadata
|
||||
|
||||
|
||||
def test_pytest_entry_points_are_identical():
|
@ -6,6 +6,10 @@ License: MIT
|
||||
URL: https://pytest.org
|
||||
Source0: %{pypi_source}
|
||||
|
||||
# Use importlib.metadata from stdlib on Python 3.8
|
||||
# Rebased from https://github.com/pytest-dev/pytest/pull/5539
|
||||
Patch0: 5539.patch
|
||||
|
||||
# The test in this specfile use pytest-timeout
|
||||
# When building pytest for the first time with new Python version
|
||||
# that is not possible as it depends on pytest
|
||||
@ -41,7 +45,6 @@ BuildRequires: python3-atomicwrites
|
||||
BuildRequires: python3-attrs
|
||||
BuildRequires: python3-devel
|
||||
BuildRequires: python3-hypothesis
|
||||
BuildRequires: python3-importlib-metadata
|
||||
BuildRequires: python3-more-itertools
|
||||
BuildRequires: python3-pluggy >= 0.12
|
||||
BuildRequires: python3-py >= 1.5.0
|
||||
@ -49,6 +52,7 @@ BuildRequires: python3-setuptools
|
||||
BuildRequires: python3-setuptools_scm
|
||||
BuildRequires: python3-six
|
||||
BuildRequires: python3-wcwidth
|
||||
BuildRequires: (python3-importlib-metadata if python3 < 3.8)
|
||||
|
||||
%if %{with timeout}
|
||||
BuildRequires: python3-pytest-timeout
|
||||
|
Loading…
Reference in New Issue
Block a user