Skip to content

Commit db213c0

Browse files
committed
Add add_target_python_options() and make_target_python().
1 parent 9117ccc commit db213c0

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

src/pip/_internal/cli/base_command.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,7 @@ def _build_package_finder(
323323
self,
324324
options, # type: Values
325325
session, # type: PipSession
326-
platform=None, # type: Optional[str]
327-
py_version_info=None, # type: Optional[Tuple[int, ...]]
328-
abi=None, # type: Optional[str]
329-
implementation=None, # type: Optional[str]
326+
target_python=None, # type: Optional[TargetPython]
330327
ignore_requires_python=None, # type: Optional[bool]
331328
):
332329
# type: (...) -> PackageFinder
@@ -338,13 +335,6 @@ def _build_package_finder(
338335
"""
339336
search_scope = make_search_scope(options)
340337

341-
target_python = TargetPython(
342-
platform=platform,
343-
py_version_info=py_version_info,
344-
abi=abi,
345-
implementation=implementation,
346-
)
347-
348338
return PackageFinder.create(
349339
search_scope=search_scope,
350340
format_control=options.format_control,

src/pip/_internal/cli/cmdoptions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from pip._internal.models.format_control import FormatControl
2323
from pip._internal.models.index import PyPI
2424
from pip._internal.models.search_scope import SearchScope
25+
from pip._internal.models.target_python import TargetPython
2526
from pip._internal.utils.hashes import STRONG_HASHES
2627
from pip._internal.utils.misc import redact_password_from_url
2728
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
@@ -356,6 +357,7 @@ def find_links():
356357

357358

358359
def make_search_scope(options, suppress_no_index=False):
360+
# type: (Values, bool) -> SearchScope
359361
"""
360362
:param suppress_no_index: Whether to ignore the --no-index option
361363
when constructing the SearchScope object.
@@ -600,6 +602,26 @@ def _handle_python_version(option, opt_str, value, parser):
600602
) # type: Callable[..., Option]
601603

602604

605+
def add_target_python_options(cmd_opts):
606+
# type: (OptionGroup) -> None
607+
cmd_opts.add_option(platform())
608+
cmd_opts.add_option(python_version())
609+
cmd_opts.add_option(implementation())
610+
cmd_opts.add_option(abi())
611+
612+
613+
def make_target_python(options):
614+
# type: (Values) -> TargetPython
615+
target_python = TargetPython(
616+
platform=options.platform,
617+
py_version_info=options.python_version,
618+
abi=options.abi,
619+
implementation=options.implementation,
620+
)
621+
622+
return target_python
623+
624+
603625
def prefer_binary():
604626
# type: () -> Option
605627
return Option(

src/pip/_internal/commands/download.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pip._internal.cli import cmdoptions
77
from pip._internal.cli.base_command import RequirementCommand
8+
from pip._internal.cli.cmdoptions import make_target_python
89
from pip._internal.legacy_resolve import Resolver
910
from pip._internal.operations.prepare import RequirementPreparer
1011
from pip._internal.req import RequirementSet
@@ -69,10 +70,7 @@ def __init__(self, *args, **kw):
6970
help=("Download packages into <dir>."),
7071
)
7172

72-
cmd_opts.add_option(cmdoptions.platform())
73-
cmd_opts.add_option(cmdoptions.python_version())
74-
cmd_opts.add_option(cmdoptions.implementation())
75-
cmd_opts.add_option(cmdoptions.abi())
73+
cmdoptions.add_target_python_options(cmd_opts)
7674

7775
index_opts = cmdoptions.make_option_group(
7876
cmdoptions.index_group,
@@ -96,13 +94,11 @@ def run(self, options, args):
9694
ensure_dir(options.download_dir)
9795

9896
with self._build_session(options) as session:
97+
target_python = make_target_python(options)
9998
finder = self._build_package_finder(
10099
options=options,
101100
session=session,
102-
platform=options.platform,
103-
py_version_info=options.python_version,
104-
abi=options.abi,
105-
implementation=options.implementation,
101+
target_python=target_python,
106102
)
107103
build_delete = (not (options.no_clean or options.build_dir))
108104
if options.cache_dir and not check_path_owner(options.cache_dir):

src/pip/_internal/commands/install.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pip._internal.cache import WheelCache
1313
from pip._internal.cli import cmdoptions
1414
from pip._internal.cli.base_command import RequirementCommand
15+
from pip._internal.cli.cmdoptions import make_target_python
1516
from pip._internal.cli.status_codes import ERROR
1617
from pip._internal.exceptions import (
1718
CommandError, InstallationError, PreviousBuildDirError,
@@ -114,10 +115,7 @@ def __init__(self, *args, **kw):
114115
'<dir>. Use --upgrade to replace existing packages in <dir> '
115116
'with new versions.'
116117
)
117-
cmd_opts.add_option(cmdoptions.platform())
118-
cmd_opts.add_option(cmdoptions.python_version())
119-
cmd_opts.add_option(cmdoptions.implementation())
120-
cmd_opts.add_option(cmdoptions.abi())
118+
cmdoptions.add_target_python_options(cmd_opts)
121119

122120
cmd_opts.add_option(
123121
'--user',
@@ -285,13 +283,11 @@ def run(self, options, args):
285283
global_options = options.global_options or []
286284

287285
with self._build_session(options) as session:
286+
target_python = make_target_python(options)
288287
finder = self._build_package_finder(
289288
options=options,
290289
session=session,
291-
platform=options.platform,
292-
py_version_info=options.python_version,
293-
abi=options.abi,
294-
implementation=options.implementation,
290+
target_python=target_python,
295291
ignore_requires_python=options.ignore_requires_python,
296292
)
297293
build_delete = (not (options.no_clean or options.build_dir))

0 commit comments

Comments
 (0)