From d1fd324ea25f271e807b676930ad928ff48c4657 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Sun, 9 Jul 2023 21:35:58 +0200 Subject: [PATCH] Add support for pip==23.2 where removed DEV_PKGS --- piptools/_compat/__init__.py | 9 ++++++++- piptools/_compat/pip_compat.py | 13 ++++++++++++- piptools/sync.py | 5 ++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/piptools/_compat/__init__.py b/piptools/_compat/__init__.py index 27d7372f8..be1397092 100644 --- a/piptools/_compat/__init__.py +++ b/piptools/_compat/__init__.py @@ -4,7 +4,14 @@ PIP_VERSION, Distribution, create_wheel_cache, + get_dev_pkgs, parse_requirements, ) -__all__ = ["PIP_VERSION", "Distribution", "parse_requirements", "create_wheel_cache"] +__all__ = [ + "PIP_VERSION", + "Distribution", + "parse_requirements", + "create_wheel_cache", + "get_dev_pkgs", +] diff --git a/piptools/_compat/pip_compat.py b/piptools/_compat/pip_compat.py index 700576455..6409fbc2a 100644 --- a/piptools/_compat/pip_compat.py +++ b/piptools/_compat/pip_compat.py @@ -2,7 +2,7 @@ import optparse from dataclasses import dataclass -from typing import TYPE_CHECKING, Iterable, Iterator +from typing import TYPE_CHECKING, Iterable, Iterator, Set, cast import pip from pip._internal.cache import WheelCache @@ -82,3 +82,14 @@ def create_wheel_cache(cache_dir: str, format_control: str | None = None) -> Whe if PIP_VERSION[:2] <= (23, 0): kwargs["format_control"] = format_control return WheelCache(**kwargs) + + +def get_dev_pkgs() -> set[str]: + if PIP_VERSION[:2] <= (23, 1): + from pip._internal.commands.freeze import DEV_PKGS + + return cast(Set[str], DEV_PKGS) + + from pip._internal.commands.freeze import _dev_pkgs + + return cast(Set[str], _dev_pkgs()) diff --git a/piptools/sync.py b/piptools/sync.py index 2dd57a976..c39015fde 100644 --- a/piptools/sync.py +++ b/piptools/sync.py @@ -8,7 +8,6 @@ from typing import Deque, Iterable, Mapping, ValuesView import click -from pip._internal.commands.freeze import DEV_PKGS from pip._internal.models.direct_url import ArchiveInfo from pip._internal.req import InstallRequirement from pip._internal.utils.compat import stdlib_pkgs @@ -17,7 +16,7 @@ direct_url_from_link, ) -from ._compat import Distribution +from ._compat import Distribution, get_dev_pkgs from .exceptions import IncompatibleRequirements from .logging import log from .utils import ( @@ -36,7 +35,7 @@ "pip-review", "pkg-resources", *stdlib_pkgs, - *DEV_PKGS, + *get_dev_pkgs(), ]