Skip to content

Commit

Permalink
Merge pull request #1539 from atugushev/new-resolver
Browse files Browse the repository at this point in the history
Add support for pip's 2020 dependency resolver
  • Loading branch information
atugushev committed Jun 29, 2022
2 parents d9b9a6c + c5e6ce2 commit bf0a669
Show file tree
Hide file tree
Showing 11 changed files with 700 additions and 85 deletions.
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:
"""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:
"""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

0 comments on commit bf0a669

Please sign in to comment.