Skip to content

Commit

Permalink
Add support for pip==22.1 (#1607)
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev authored Apr 4, 2022
1 parent 8540782 commit ef8b856
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ jobs:
- os: Ubuntu
python-version: 3.11-dev
pip-version: latest

- os: Ubuntu
python-version: 3.7
pip-version: main
env:
PY_COLORS: 1
TOXENV: pip${{ matrix.pip-version }}-coverage
Expand Down
18 changes: 18 additions & 0 deletions piptools/_compat/pip_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
PIP_VERSION = tuple(map(int, parse_version(pip.__version__).base_version.split(".")))


__all__ = [
"get_build_tracker",
"update_env_context_manager",
]


def parse_requirements(
filename: str,
session: PipSession,
Expand All @@ -24,3 +30,15 @@ def parse_requirements(
filename, session, finder=finder, options=options, constraint=constraint
):
yield install_req_from_parsed_requirement(parsed_req, isolated=isolated)


if PIP_VERSION[:2] <= (22, 0):
from pip._internal.req.req_tracker import (
get_requirement_tracker as get_build_tracker,
)
from pip._internal.req.req_tracker import update_env_context_manager
else:
from pip._internal.operations.build.build_tracker import (
get_build_tracker,
update_env_context_manager,
)
11 changes: 8 additions & 3 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from pip._internal.models.wheel import Wheel
from pip._internal.network.session import PipSession
from pip._internal.req import InstallRequirement, RequirementSet
from pip._internal.req.req_tracker import get_requirement_tracker
from pip._internal.utils.hashes import FAVORITE_HASH
from pip._internal.utils.logging import indent_log, setup_logging
from pip._internal.utils.misc import normalize_path
Expand All @@ -41,6 +40,7 @@
from pip._vendor.requests import RequestException, Session

from .._compat import PIP_VERSION
from .._compat.pip_compat import get_build_tracker
from ..exceptions import NoCandidateFound
from ..logging import log
from ..utils import (
Expand Down Expand Up @@ -169,18 +169,23 @@ def resolve_reqs(
ireq: InstallRequirement,
wheel_cache: WheelCache,
) -> Set[InstallationCandidate]:
with get_requirement_tracker() as req_tracker, TempDirectory(
with get_build_tracker() as build_tracker, TempDirectory(
kind="resolver"
) as temp_dir, indent_log():
preparer_kwargs = {
"temp_build_dir": temp_dir,
"options": self.options,
"req_tracker": req_tracker,
"session": self.session,
"finder": self.finder,
"use_user_site": False,
"download_dir": download_dir,
}

if PIP_VERSION[:2] <= (22, 0):
preparer_kwargs["req_tracker"] = build_tracker
else:
preparer_kwargs["build_tracker"] = build_tracker

preparer = self.command.make_requirement_preparer(**preparer_kwargs)

reqset = RequirementSet()
Expand Down
2 changes: 1 addition & 1 deletion piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import click
from pip._internal.req import InstallRequirement
from pip._internal.req.constructors import install_req_from_line
from pip._internal.req.req_tracker import update_env_context_manager

from piptools.cache import DependencyCache
from piptools.repositories.base import BaseRepository

from ._compat.pip_compat import update_env_context_manager
from .logging import log
from .utils import (
UNSAFE_PACKAGES,
Expand Down

0 comments on commit ef8b856

Please sign in to comment.