diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d93e86b..e15936d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -18,12 +18,11 @@ jobs: fail-fast: false matrix: py: - - "3.12.0-beta.2" + - "3.12.0-beta.4" - "3.11" - "3.10" - "3.9" - "3.8" - - "3.7" steps: - name: Install OS dependencies run: | @@ -60,7 +59,7 @@ jobs: check: name: tox env ${{ matrix.tox_env }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: diff --git a/README.md b/README.md index cf21bac..b31dab8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # pipdeptree +[![PyPI](https://img.shields.io/pypi/v/tox)](https://pypi.org/project/pipdeptree/) +[![Supported Python +versions](https://img.shields.io/pypi/pyversions/tox.svg)](https://pypi.org/project/pipdeptree/) +[![Downloads](https://pepy.tech/badge/tox/month)](https://pepy.tech/project/pipdeptree) [![check](https://github.com/tox-dev/pipdeptree/actions/workflows/check.yml/badge.svg)](https://github.com/tox-dev/pipdeptree/actions/workflows/check.yml) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/tox-dev/pipdeptree/main.svg)](https://results.pre-commit.ci/latest/github/tox-dev/pipdeptree/main) @@ -18,8 +22,6 @@ To some extent, `pipdeptree` is inspired by the `lein deps :tree` command of [Le pip install pipdeptree ``` -pipdeptree has been tested with Python versions `3.7`, `3.8`, `3.9` and `3.10`. - ## Running in virtualenvs `New in ver. 2.0.0` diff --git a/pyproject.toml b/pyproject.toml index fc071b2..bcbf954 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ maintainers = [ { name = "Bernát Gábor", email = "gaborjbernat@gmail.com" }, { name = "Vineet Naik", email = "naikvin@gmail.com" }, ] -requires-python = ">=3.7" +requires-python = ">=3.8" classifiers = [ "Development Status :: 5 - Production/Stable", "Environment :: Console", @@ -30,7 +30,6 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -69,7 +68,7 @@ line-length = 120 [tool.ruff] select = ["ALL"] line-length = 120 -target-version = "py37" +target-version = "py38" isort = {known-first-party = ["pipdeptree"], required-imports = ["from __future__ import annotations"]} ignore = [ "INP001", # no implicit namespace diff --git a/src/pipdeptree/_models.py b/src/pipdeptree/_models.py index 1234a3f..359a982 100644 --- a/src/pipdeptree/_models.py +++ b/src/pipdeptree/_models.py @@ -1,10 +1,10 @@ from __future__ import annotations -import sys from abc import ABC, abstractmethod from collections import defaultdict, deque from fnmatch import fnmatch from importlib import import_module +from importlib.metadata import PackageNotFoundError, version from inspect import ismodule from itertools import chain from typing import TYPE_CHECKING, Any, Iterator, List, Mapping, cast @@ -413,12 +413,8 @@ def guess_version(pkg_key: str, default: str = "?") -> str: :returns: version """ try: - if sys.version_info >= (3, 8): # pragma: >=3.8 cover - import importlib.metadata as importlib_metadata - else: # pragma: <3.8 cover - import importlib_metadata - return importlib_metadata.version(pkg_key) - except ImportError: + return version(pkg_key) + except PackageNotFoundError: pass # Avoid AssertionError with setuptools, see https://github.com/tox-dev/pipdeptree/issues/162 if pkg_key in {"setuptools"}: diff --git a/tests/models/guess_version_setuptools.py b/tests/models/guess_version_setuptools.py deleted file mode 100644 index dcef930..0000000 --- a/tests/models/guess_version_setuptools.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -import sys -from typing import NoReturn - -from pipdeptree._models import guess_version - -if sys.version_info >= (3, 8): - import importlib.metadata as importlib_metadata -else: - import importlib_metadata - - -def raise_import_error(name: str) -> NoReturn: - raise ImportError(name) - - -importlib_metadata.version = raise_import_error # type: ignore[assignment] -print(guess_version("setuptools"), end="") # noqa: T201 diff --git a/tests/models/test_models.py b/tests/test_models.py similarity index 95% rename from tests/models/test_models.py rename to tests/test_models.py index 8fc733b..a3f30ce 100644 --- a/tests/models/test_models.py +++ b/tests/test_models.py @@ -1,17 +1,17 @@ from __future__ import annotations -import sys +from importlib.metadata import PackageNotFoundError from itertools import chain -from pathlib import Path -from subprocess import check_output from typing import TYPE_CHECKING, Any, Callable, Iterator from unittest.mock import Mock import pytest -from pipdeptree._models import DistPackage, PackageDAG, ReqPackage, ReversedPackageDAG +from pipdeptree._models import DistPackage, PackageDAG, ReqPackage, ReversedPackageDAG, guess_version if TYPE_CHECKING: + from pytest_mock import MockerFixture + from tests.our_types import MockGraph @@ -23,10 +23,10 @@ def dag_to_dict(g: PackageDAG) -> dict[str, list[str]]: return {k.key: [v.key for v in vs] for k, vs in g._obj.items()} # noqa: SLF001 -def test_guess_version_setuptools() -> None: - script = Path(__file__).parent / "guess_version_setuptools.py" - output = check_output([sys.executable, script], text=True) - assert output == "?" +def test_guess_version_setuptools(mocker: MockerFixture) -> None: + mocker.patch("pipdeptree._models.version", side_effect=PackageNotFoundError) + result = guess_version("setuptools") + assert result == "?" def test_package_dag_get_node_as_parent(example_dag: PackageDAG) -> None: diff --git a/tox.ini b/tox.ini index 9e8485d..30328ae 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,6 @@ env_list = py310 py39 py38 - py37 type readme skip_missing_interpreters = true