Skip to content

Commit

Permalink
Add make_requirement_preparer() to RequirementCommand base class (#6810)
Browse files Browse the repository at this point in the history
  • Loading branch information
nixphix authored and cjerdonek committed Aug 2, 2019
1 parent 5796d9e commit 82dbcda
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
25 changes: 25 additions & 0 deletions src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from pip._internal.index import PackageFinder
from pip._internal.models.selection_prefs import SelectionPreferences
from pip._internal.models.target_python import TargetPython
from pip._internal.operations.prepare import RequirementPreparer
from pip._internal.req.constructors import (
install_req_from_editable,
install_req_from_line,
Expand All @@ -50,6 +51,8 @@
from optparse import Values
from pip._internal.cache import WheelCache
from pip._internal.req.req_set import RequirementSet
from pip._internal.req.req_tracker import RequirementTracker
from pip._internal.utils.temp_dir import TempDirectory

__all__ = ['Command']

Expand Down Expand Up @@ -257,6 +260,28 @@ def main(self, args):

class RequirementCommand(Command):

@staticmethod
def make_requirement_preparer(
temp_directory, # type: TempDirectory
options, # type: Values
req_tracker, # type: RequirementTracker
download_dir=None, # type: str
wheel_download_dir=None, # type: str
):
# type: (...) -> RequirementPreparer
"""
Create a RequirementPreparer instance for the given parameters.
"""
return RequirementPreparer(
build_dir=temp_directory.path,
src_dir=options.src_dir,
download_dir=download_dir,
wheel_download_dir=wheel_download_dir,
progress_bar=options.progress_bar,
build_isolation=options.build_isolation,
req_tracker=req_tracker,
)

@staticmethod
def populate_requirement_set(requirement_set, # type: RequirementSet
args, # type: List[str]
Expand Down
12 changes: 4 additions & 8 deletions src/pip/_internal/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pip._internal.cli.base_command import RequirementCommand
from pip._internal.cli.cmdoptions import make_target_python
from pip._internal.legacy_resolve import Resolver
from pip._internal.operations.prepare import RequirementPreparer
from pip._internal.req import RequirementSet
from pip._internal.req.req_tracker import RequirementTracker
from pip._internal.utils.filesystem import check_path_owner
Expand Down Expand Up @@ -126,14 +125,11 @@ def run(self, options, args):
None
)

preparer = RequirementPreparer(
build_dir=directory.path,
src_dir=options.src_dir,
download_dir=options.download_dir,
wheel_download_dir=None,
progress_bar=options.progress_bar,
build_isolation=options.build_isolation,
preparer = self.make_requirement_preparer(
temp_directory=directory,
options=options,
req_tracker=req_tracker,
download_dir=options.download_dir,
)

resolver = Resolver(
Expand Down
12 changes: 3 additions & 9 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pip._internal.legacy_resolve import Resolver
from pip._internal.locations import distutils_scheme
from pip._internal.operations.check import check_install_conflicts
from pip._internal.operations.prepare import RequirementPreparer
from pip._internal.req import RequirementSet, install_given_reqs
from pip._internal.req.req_tracker import RequirementTracker
from pip._internal.utils.filesystem import check_path_owner
Expand Down Expand Up @@ -322,16 +321,11 @@ def run(self, options, args):
requirement_set, args, options, finder, session,
self.name, wheel_cache
)
preparer = RequirementPreparer(
build_dir=directory.path,
src_dir=options.src_dir,
download_dir=None,
wheel_download_dir=None,
progress_bar=options.progress_bar,
build_isolation=options.build_isolation,
preparer = self.make_requirement_preparer(
temp_directory=directory,
options=options,
req_tracker=req_tracker,
)

resolver = Resolver(
preparer=preparer,
finder=finder,
Expand Down
12 changes: 4 additions & 8 deletions src/pip/_internal/commands/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pip._internal.cli.base_command import RequirementCommand
from pip._internal.exceptions import CommandError, PreviousBuildDirError
from pip._internal.legacy_resolve import Resolver
from pip._internal.operations.prepare import RequirementPreparer
from pip._internal.req import RequirementSet
from pip._internal.req.req_tracker import RequirementTracker
from pip._internal.utils.temp_dir import TempDirectory
Expand Down Expand Up @@ -129,14 +128,11 @@ def run(self, options, args):
self.name, wheel_cache
)

preparer = RequirementPreparer(
build_dir=directory.path,
src_dir=options.src_dir,
download_dir=None,
wheel_download_dir=options.wheel_dir,
progress_bar=options.progress_bar,
build_isolation=options.build_isolation,
preparer = self.make_requirement_preparer(
temp_directory=directory,
options=options,
req_tracker=req_tracker,
wheel_download_dir=options.wheel_dir,
)

resolver = Resolver(
Expand Down

0 comments on commit 82dbcda

Please sign in to comment.