Skip to content

Commit

Permalink
Reduce context/options passed to Resolver (#6986)
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg authored Sep 7, 2019
2 parents a0a55bc + 7514a50 commit 9300fe6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
12 changes: 9 additions & 3 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import os
from functools import partial

from pip._internal.cli.base_command import Command
from pip._internal.cli.cmdoptions import make_search_scope
Expand All @@ -18,6 +19,7 @@
from pip._internal.req.constructors import (
install_req_from_editable,
install_req_from_line,
install_req_from_req_string,
)
from pip._internal.req.req_file import parse_requirements
from pip._internal.utils.misc import normalize_path
Expand Down Expand Up @@ -167,19 +169,23 @@ def make_resolver(
"""
Create a Resolver instance for the given parameters.
"""
make_install_req = partial(
install_req_from_req_string,
isolated=options.isolated_mode,
wheel_cache=wheel_cache,
use_pep517=use_pep517,
)
return Resolver(
preparer=preparer,
session=session,
finder=finder,
wheel_cache=wheel_cache,
make_install_req=make_install_req,
use_user_site=use_user_site,
ignore_dependencies=options.ignore_dependencies,
ignore_installed=ignore_installed,
ignore_requires_python=ignore_requires_python,
force_reinstall=force_reinstall,
isolated=options.isolated_mode,
upgrade_strategy=upgrade_strategy,
use_pep517=use_pep517,
py_version_info=py_version_info
)

Expand Down
24 changes: 8 additions & 16 deletions src/pip/_internal/legacy_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
HashErrors,
UnsupportedPythonVersion,
)
from pip._internal.req.constructors import install_req_from_req_string
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import (
dist_in_usersite,
Expand All @@ -41,17 +40,20 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import DefaultDict, List, Optional, Set, Tuple
from typing import Callable, DefaultDict, List, Optional, Set, Tuple
from pip._vendor import pkg_resources

from pip._internal.cache import WheelCache
from pip._internal.distributions import AbstractDistribution
from pip._internal.download import PipSession
from pip._internal.index import PackageFinder
from pip._internal.operations.prepare import RequirementPreparer
from pip._internal.req.req_install import InstallRequirement
from pip._internal.req.req_set import RequirementSet

InstallRequirementProvider = Callable[
[str, InstallRequirement], InstallRequirement
]

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -115,15 +117,13 @@ def __init__(
preparer, # type: RequirementPreparer
session, # type: PipSession
finder, # type: PackageFinder
wheel_cache, # type: Optional[WheelCache]
make_install_req, # type: InstallRequirementProvider
use_user_site, # type: bool
ignore_dependencies, # type: bool
ignore_installed, # type: bool
ignore_requires_python, # type: bool
force_reinstall, # type: bool
isolated, # type: bool
upgrade_strategy, # type: str
use_pep517=None, # type: Optional[bool]
py_version_info=None, # type: Optional[Tuple[int, ...]]
):
# type: (...) -> None
Expand All @@ -141,21 +141,16 @@ def __init__(
self.finder = finder
self.session = session

# NOTE: This would eventually be replaced with a cache that can give
# information about both sdist and wheels transparently.
self.wheel_cache = wheel_cache

# This is set in resolve
self.require_hashes = None # type: Optional[bool]

self.upgrade_strategy = upgrade_strategy
self.force_reinstall = force_reinstall
self.isolated = isolated
self.ignore_dependencies = ignore_dependencies
self.ignore_installed = ignore_installed
self.ignore_requires_python = ignore_requires_python
self.use_user_site = use_user_site
self.use_pep517 = use_pep517
self._make_install_req = make_install_req

self._discovered_dependencies = \
defaultdict(list) # type: DefaultDict[str, List]
Expand Down Expand Up @@ -381,12 +376,9 @@ def _resolve_one(
more_reqs = [] # type: List[InstallRequirement]

def add_req(subreq, extras_requested):
sub_install_req = install_req_from_req_string(
sub_install_req = self._make_install_req(
str(subreq),
req_to_install,
isolated=self.isolated,
wheel_cache=self.wheel_cache,
use_pep517=self.use_pep517
)
parent_req_name = req_to_install.name
to_scan_again, add_to_parent = requirement_set.add_requirement(
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import sys
import tempfile
from functools import partial

import pytest
from mock import patch
Expand All @@ -23,6 +24,7 @@
from pip._internal.req.constructors import (
install_req_from_editable,
install_req_from_line,
install_req_from_req_string,
parse_editable,
)
from pip._internal.req.req_file import process_line
Expand Down Expand Up @@ -61,13 +63,19 @@ def _basic_resolver(self, finder):
build_isolation=True,
req_tracker=RequirementTracker(),
)
make_install_req = partial(
install_req_from_req_string,
isolated=False,
wheel_cache=None,
use_pep517=None,
)
return Resolver(
preparer=preparer, wheel_cache=None,
preparer=preparer,
make_install_req=make_install_req,
session=PipSession(), finder=finder,
use_user_site=False, upgrade_strategy="to-satisfy-only",
ignore_dependencies=False, ignore_installed=False,
ignore_requires_python=False, force_reinstall=False,
isolated=False,
)

def test_no_reuse_existing_build_dir(self, data):
Expand Down

0 comments on commit 9300fe6

Please sign in to comment.