Skip to content

Commit 66a1444

Browse files
authored
Update to pytest >= 7.0.0 and use importlib_metadata to get versions (#177)
* Update pytest dependency to > 7.0.0 pyproject.toml: Update the pytest dependency to >= 7.0.0, which obsoletes the use of pytest-pythonpath. setup.cfg: Change the python_paths pytest configuration option to pythonpath, as that is what is used with pytest >= 7.0.0." * Update poetry lock file poetry.lock: Update poetry lock file after updating pytest version requirement and removing pytest-pythonpath. * Add importlib_metadata for python < 3.10 pyproject.toml: Using importlib_metadata it is possible to derive versions of packages. To make use of it with python < 3.10 the package importlib_metadata has to be added (conditionally). * Update poetry lock after adding importlib_metadata poetry.lock: Update poetry lock after adding importlib_metadata conditionally. * Do not warn about unused ignores with mypy setup.cfg: Disable the warning for unused ignores in mypy as there seems to be an issue between versions of mypy about what is considered an "unused ignore". * Use importlib_metadata to derive package versions coverage_conditional_plugin/__init__.py: Use importlib_metadata to derive package versions, instead of relying on pkg_resources (which implicitly dragged in setuptools). * Disable WPS440 and WPS433 for plugin setup.cfg: Disable WPS440 and WPS433 for plugin as they are requirements for the conditional import of importlib_metadata.
1 parent 98945af commit 66a1444

File tree

4 files changed

+31
-50
lines changed

4 files changed

+31
-50
lines changed

coverage_conditional_plugin/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
from importlib import import_module
55
from typing import ClassVar, Dict, Iterable, Optional, Tuple, Union
66

7-
import pkg_resources
7+
try: # pragma: no cover
8+
from importlib.metadata import version as metadata_version
9+
except ImportError: # pragma: no cover
10+
from importlib_metadata import version as metadata_version # type: ignore
811
from coverage import CoveragePlugin
912
from coverage.config import CoverageConfig
1013
from packaging import version
@@ -129,9 +132,7 @@ def _package_version(
129132
130133
Returns parsed varsion to be easily worked with.
131134
"""
132-
return version.parse(
133-
pkg_resources.get_distribution(package).version,
134-
).release
135+
return version.parse(metadata_version(package)).release
135136

136137

137138
def coverage_init(reg, options) -> None:

poetry.lock

Lines changed: 16 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ python = "^3.7"
3737

3838
coverage = ">=5,<7"
3939
packaging = ">=20.4"
40+
importlib_metadata = { version = "*", python = "<3.10" }
4041

4142
[tool.poetry.group.test.dependencies]
4243
mypy = "^0.971"
@@ -48,10 +49,9 @@ nitpick = "^0.29"
4849

4950
safety = "^2.1"
5051

51-
pytest = "^6.2"
52+
pytest = "^7.0"
5253
pytest-cov = "^3.0"
5354
pytest-randomly = "^3.10"
54-
pytest-pythonpath = "^0.7"
5555

5656

5757
[build-system]

setup.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ extend-exclude =
3131

3232
# Ignoring some errors in some files:
3333
per-file-ignores =
34+
# we need nested import and block variable overlap for conditional
35+
# importlib_metadata import
36+
coverage_conditional_plugin/__init__.py: WPS433, WPS440
3437
# Disable `test_project` complexity checks:
3538
test_project/example.py: WPS202
3639
# Enable `assert` keyword and magic numbers for tests:
@@ -53,7 +56,7 @@ norecursedirs = *.egg .eggs dist build docs .tox .git __pycache__
5356

5457
# PYTHONPATH configuration:
5558
# https://github.com/bigsassy/pytest-pythonpath
56-
python_paths = ./test_project
59+
pythonpath = ./test_project
5760

5861
# Strict `@xfail` by default:
5962
xfail_strict = true
@@ -91,3 +94,7 @@ warn_unused_ignores = true
9194
warn_redundant_casts = true
9295
warn_unused_configs = true
9396
warn_unreachable = true
97+
98+
[mypy-coverage_conditional_plugin]
99+
# We allow unused `ignore` comments, because we cannot sync it between versions:
100+
warn_unused_ignores = false

0 commit comments

Comments
 (0)