From 99cdda233568ddb6934873e69c52b3497e0a434e Mon Sep 17 00:00:00 2001 From: Kemal Zebari <60799661+kemzeb@users.noreply.github.com> Date: Sun, 26 Jan 2025 13:40:51 -0800 Subject: [PATCH] Drop support for python 3.8 (#444) Drops support for python 3.8 since it is EOL. The code refactoring is due to ruff's formatting rules for 3.9. --- .github/workflows/check.yaml | 1 - pyproject.toml | 4 +--- src/pipdeptree/__main__.py | 5 ++++- src/pipdeptree/_cli.py | 5 ++++- src/pipdeptree/_discovery.py | 7 +++++-- src/pipdeptree/_models/dag.py | 5 +++-- src/pipdeptree/_models/package.py | 3 ++- tests/_models/test_dag.py | 3 ++- tests/conftest.py | 4 +++- tests/our_types.py | 4 +--- tests/render/test_json_tree.py | 3 ++- tests/render/test_mermaid.py | 3 ++- tests/render/test_text.py | 3 ++- tests/test_validate.py | 3 ++- tox.toml | 1 - 15 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 6aaad88..a056425 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -26,7 +26,6 @@ jobs: - "3.11" - "3.10" - "3.9" - - "3.8" - type - dev - pkg_meta diff --git a/pyproject.toml b/pyproject.toml index 6dd3e82..c2d13bb 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.8" +requires-python = ">=3.9" 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.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -68,7 +67,6 @@ build.hooks.vcs.version-file = "src/pipdeptree/version.py" version.source = "vcs" [tool.ruff] -target-version = "py38" line-length = 120 format.preview = true format.docstring-code-line-length = 100 diff --git a/src/pipdeptree/__main__.py b/src/pipdeptree/__main__.py index fca21b9..ca9a973 100644 --- a/src/pipdeptree/__main__.py +++ b/src/pipdeptree/__main__.py @@ -3,7 +3,7 @@ from __future__ import annotations import sys -from typing import Sequence +from typing import TYPE_CHECKING from pipdeptree._cli import get_options from pipdeptree._detect_env import detect_active_interpreter @@ -13,6 +13,9 @@ from pipdeptree._render import render from pipdeptree._validate import validate from pipdeptree._warning import WarningPrinter, WarningType, get_warning_printer +if TYPE_CHECKING: + from collections.abc import Sequence + def main(args: Sequence[str] | None = None) -> int | None: """CLI - The main function called as entry point.""" diff --git a/src/pipdeptree/_cli.py b/src/pipdeptree/_cli.py index 44ebfce..9d8f207 100644 --- a/src/pipdeptree/_cli.py +++ b/src/pipdeptree/_cli.py @@ -3,12 +3,15 @@ from __future__ import annotations import enum import sys from argparse import Action, ArgumentDefaultsHelpFormatter, ArgumentParser, Namespace -from typing import Any, Sequence, cast +from typing import TYPE_CHECKING, Any, cast from pipdeptree._warning import WarningType from .version import __version__ +if TYPE_CHECKING: + from collections.abc import Sequence + class Options(Namespace): freeze: bool diff --git a/src/pipdeptree/_discovery.py b/src/pipdeptree/_discovery.py index ba23498..9c19d93 100644 --- a/src/pipdeptree/_discovery.py +++ b/src/pipdeptree/_discovery.py @@ -6,12 +6,15 @@ import subprocess # noqa: S404 import sys from importlib.metadata import Distribution, distributions from pathlib import Path -from typing import Iterable, Tuple +from typing import TYPE_CHECKING from packaging.utils import canonicalize_name from pipdeptree._warning import get_warning_printer +if TYPE_CHECKING: + from collections.abc import Iterable + def get_installed_distributions( interpreter: str = str(sys.executable), @@ -103,7 +106,7 @@ def render_invalid_metadata_text(site_dirs_with_invalid_metadata: set[str]) -> N print(site_dir, file=sys.stderr) # noqa: T201 -FirstSeenWithDistsPair = Tuple[Distribution, Distribution] +FirstSeenWithDistsPair = tuple[Distribution, Distribution] def render_duplicated_dist_metadata_text( diff --git a/src/pipdeptree/_models/dag.py b/src/pipdeptree/_models/dag.py index 2f5df60..41c1cf8 100644 --- a/src/pipdeptree/_models/dag.py +++ b/src/pipdeptree/_models/dag.py @@ -2,9 +2,10 @@ from __future__ import annotations import sys from collections import defaultdict, deque +from collections.abc import Iterator, Mapping from fnmatch import fnmatch from itertools import chain -from typing import TYPE_CHECKING, Iterator, List, Mapping +from typing import TYPE_CHECKING from packaging.utils import canonicalize_name @@ -25,7 +26,7 @@ def render_invalid_reqs_text(dist_name_to_invalid_reqs_dict: dict[str, list[str] print(f' Skipping "{invalid_req}"', file=sys.stderr) # noqa: T201 -class PackageDAG(Mapping[DistPackage, List[ReqPackage]]): +class PackageDAG(Mapping[DistPackage, list[ReqPackage]]): """ Representation of Package dependencies as directed acyclic graph using a dict as the underlying datastructure. diff --git a/src/pipdeptree/_models/package.py b/src/pipdeptree/_models/package.py index 7e49250..cc3efaf 100644 --- a/src/pipdeptree/_models/package.py +++ b/src/pipdeptree/_models/package.py @@ -4,7 +4,7 @@ from abc import ABC, abstractmethod from importlib import import_module from importlib.metadata import Distribution, PackageNotFoundError, metadata, version from inspect import ismodule -from typing import TYPE_CHECKING, Iterator +from typing import TYPE_CHECKING from packaging.requirements import InvalidRequirement, Requirement from packaging.utils import canonicalize_name @@ -12,6 +12,7 @@ from packaging.utils import canonicalize_name from pipdeptree._freeze import dist_to_frozen_repr if TYPE_CHECKING: + from collections.abc import Iterator from importlib.metadata import Distribution diff --git a/tests/_models/test_dag.py b/tests/_models/test_dag.py index eb909c1..dc22cc7 100644 --- a/tests/_models/test_dag.py +++ b/tests/_models/test_dag.py @@ -1,13 +1,14 @@ from __future__ import annotations from itertools import chain -from typing import TYPE_CHECKING, Any, Callable, Iterator +from typing import TYPE_CHECKING, Any, Callable import pytest from pipdeptree._models import DistPackage, PackageDAG, ReqPackage, ReversedPackageDAG if TYPE_CHECKING: + from collections.abc import Iterator from unittest.mock import Mock from tests.our_types import MockGraph diff --git a/tests/conftest.py b/tests/conftest.py index c2ec5d6..ed839a1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,7 @@ from __future__ import annotations import locale from pathlib import Path from random import shuffle -from typing import TYPE_CHECKING, Callable, Iterator +from typing import TYPE_CHECKING, Callable from unittest.mock import Mock import pytest @@ -11,6 +11,8 @@ import pytest from pipdeptree._models import PackageDAG if TYPE_CHECKING: + from collections.abc import Iterator + from tests.our_types import MockGraph diff --git a/tests/our_types.py b/tests/our_types.py index f7f2297..aed4156 100644 --- a/tests/our_types.py +++ b/tests/our_types.py @@ -1,8 +1,6 @@ from __future__ import annotations -from typing import Dict, List, Tuple - -MockGraph = Dict[Tuple[str, str], List[Tuple[str, List[Tuple[str, str]]]]] +MockGraph = dict[tuple[str, str], list[tuple[str, list[tuple[str, str]]]]] # pragma: no cover __all__ = [ "MockGraph", diff --git a/tests/render/test_json_tree.py b/tests/render/test_json_tree.py index 32558a1..26c2316 100644 --- a/tests/render/test_json_tree.py +++ b/tests/render/test_json_tree.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, Iterator +from typing import TYPE_CHECKING, Callable import pytest @@ -8,6 +8,7 @@ from pipdeptree._models.dag import PackageDAG from pipdeptree._render.json_tree import render_json_tree if TYPE_CHECKING: + from collections.abc import Iterator from unittest.mock import Mock from tests.our_types import MockGraph diff --git a/tests/render/test_mermaid.py b/tests/render/test_mermaid.py index ec567c9..afc6f88 100644 --- a/tests/render/test_mermaid.py +++ b/tests/render/test_mermaid.py @@ -1,12 +1,13 @@ from __future__ import annotations from textwrap import dedent, indent -from typing import TYPE_CHECKING, Callable, Iterator +from typing import TYPE_CHECKING, Callable from pipdeptree._models import PackageDAG from pipdeptree._render.mermaid import render_mermaid if TYPE_CHECKING: + from collections.abc import Iterator from unittest.mock import Mock from tests.our_types import MockGraph diff --git a/tests/render/test_text.py b/tests/render/test_text.py index 0db71a6..0a7322f 100644 --- a/tests/render/test_text.py +++ b/tests/render/test_text.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, Iterator +from typing import TYPE_CHECKING, Callable import pytest @@ -9,6 +9,7 @@ from pipdeptree._models.package import Package from pipdeptree._render.text import render_text if TYPE_CHECKING: + from collections.abc import Iterator from unittest.mock import Mock from tests.our_types import MockGraph diff --git a/tests/test_validate.py b/tests/test_validate.py index efb164b..b9f2fef 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, Iterator +from typing import TYPE_CHECKING, Callable import pytest @@ -8,6 +8,7 @@ from pipdeptree._models import PackageDAG from pipdeptree._validate import conflicting_deps, cyclic_deps, render_conflicts_text, render_cycles_text, validate if TYPE_CHECKING: + from collections.abc import Iterator from unittest.mock import Mock from tests.our_types import MockGraph diff --git a/tox.toml b/tox.toml index 47d108d..054b547 100644 --- a/tox.toml +++ b/tox.toml @@ -6,7 +6,6 @@ env_list = [ "3.11", "3.10", "3.9", - "3.8", "type", "pkg_meta", ]