Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pip's 2020 dependency resolver #1539

Merged
merged 6 commits into from Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions piptools/repositories/base.py
Expand Up @@ -3,6 +3,7 @@
from contextlib import contextmanager
from typing import Iterator, Optional, Set

from pip._internal.commands.install import InstallCommand
from pip._internal.index.package_finder import PackageFinder
from pip._internal.models.index import PyPI
from pip._internal.network.session import PipSession
Expand Down Expand Up @@ -61,3 +62,8 @@ def session(self) -> PipSession:
@abstractmethod
def finder(self) -> PackageFinder:
"""Returns a package finder to interact with simple repository API (PEP 503)"""

@property
@abstractmethod
def command(self) -> InstallCommand:
"""Return an install command."""
6 changes: 6 additions & 0 deletions piptools/repositories/local.py
Expand Up @@ -2,6 +2,7 @@
from contextlib import contextmanager
from typing import Iterator, Mapping, Optional, Set, cast

from pip._internal.commands.install import InstallCommand
from pip._internal.index.package_finder import PackageFinder
from pip._internal.models.candidate import InstallationCandidate
from pip._internal.req import InstallRequirement
Expand Down Expand Up @@ -61,6 +62,11 @@ def finder(self) -> PackageFinder:
def session(self) -> Session:
return self.repository.session

@property
def command(self) -> InstallCommand:
atugushev marked this conversation as resolved.
Show resolved Hide resolved
"""Return an install command instance."""
return self.repository.command

def clear_caches(self) -> None:
self.repository.clear_caches()

Expand Down
16 changes: 11 additions & 5 deletions piptools/repositories/pypi.py
Expand Up @@ -73,10 +73,9 @@ def __init__(self, pip_args: List[str], cache_dir: str):
# Use pip's parser for pip.conf management and defaults.
# General options (find_links, index_url, extra_index_url, trusted_host,
# and pre) are deferred to pip.
self.command: InstallCommand = create_command("install")
extra_pip_args = ["--use-deprecated", "legacy-resolver"]
self._command: InstallCommand = create_command("install")

options, _ = self.command.parse_args(pip_args + extra_pip_args)
options, _ = self.command.parse_args(pip_args)
if options.cache_dir:
options.cache_dir = normalize_path(options.cache_dir)
options.require_hashes = False
Expand All @@ -103,8 +102,7 @@ def __init__(self, pip_args: List[str], cache_dir: str):
self._cache_dir = normalize_path(str(cache_dir))
self._download_dir = os.path.join(self._cache_dir, "pkgs")

if PIP_VERSION[0] < 22:
self._setup_logging()
self._setup_logging()

def clear_caches(self) -> None:
rmtree(self._download_dir, ignore_errors=True)
Expand All @@ -121,6 +119,11 @@ def session(self) -> PipSession:
def finder(self) -> PackageFinder:
return self._finder

@property
def command(self) -> InstallCommand:
atugushev marked this conversation as resolved.
Show resolved Hide resolved
"""Return an install command instance."""
return self._command

def find_all_candidates(self, req_name: str) -> List[InstallationCandidate]:
if req_name not in self._available_candidates_cache:
candidates = self.finder.find_all_candidates(req_name)
Expand Down Expand Up @@ -464,6 +467,9 @@ def _setup_logging(self) -> None:
user_log_file=self.options.log,
)

if PIP_VERSION[0] >= 22:
return

# Sync pip's console handler stream with LogContext.stream
logger = logging.getLogger()
for handler in logger.handlers:
Expand Down