Skip to content

Commit 908e203

Browse files
authored
Merge pull request #6859 from cjerdonek/wheel-strict-optional
Remove WheelBuilder's dependence on PipSession
2 parents 1de04eb + 022a366 commit 908e203

File tree

5 files changed

+46
-26
lines changed

5 files changed

+46
-26
lines changed

src/pip/_internal/commands/install.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
# The following comment should be removed at some point in the future.
3+
# It's included for now because without it InstallCommand.run() has a
4+
# couple errors where we have to know req.name is str rather than
5+
# Optional[str] for the InstallRequirement req.
6+
# mypy: strict-optional=False
7+
18
from __future__ import absolute_import
29

310
import errno
@@ -13,7 +20,7 @@
1320
from pip._internal.cli import cmdoptions
1421
from pip._internal.cli.cmdoptions import make_target_python
1522
from pip._internal.cli.req_command import RequirementCommand
16-
from pip._internal.cli.status_codes import ERROR
23+
from pip._internal.cli.status_codes import ERROR, SUCCESS
1724
from pip._internal.exceptions import (
1825
CommandError,
1926
InstallationError,
@@ -30,9 +37,17 @@
3037
protect_pip_from_modification_on_windows,
3138
)
3239
from pip._internal.utils.temp_dir import TempDirectory
40+
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
3341
from pip._internal.utils.virtualenv import virtualenv_no_global
3442
from pip._internal.wheel import WheelBuilder
3543

44+
if MYPY_CHECK_RUNNING:
45+
from optparse import Values
46+
from typing import Any, List
47+
48+
from pip._internal.req.req_install import InstallRequirement
49+
50+
3651
logger = logging.getLogger(__name__)
3752

3853

@@ -48,7 +63,12 @@ def is_wheel_installed():
4863
return True
4964

5065

51-
def build_wheels(builder, pep517_requirements, legacy_requirements, session):
66+
def build_wheels(
67+
builder, # type: WheelBuilder
68+
pep517_requirements, # type: List[InstallRequirement]
69+
legacy_requirements, # type: List[InstallRequirement]
70+
):
71+
# type: (...) -> List[InstallRequirement]
5272
"""
5373
Build wheels for requirements, depending on whether wheel is installed.
5474
"""
@@ -58,7 +78,7 @@ def build_wheels(builder, pep517_requirements, legacy_requirements, session):
5878
# Always build PEP 517 requirements
5979
build_failures = builder.build(
6080
pep517_requirements,
61-
session=session, autobuilding=True
81+
autobuilding=True,
6282
)
6383

6484
if should_build_legacy:
@@ -67,7 +87,7 @@ def build_wheels(builder, pep517_requirements, legacy_requirements, session):
6787
# install for those.
6888
builder.build(
6989
legacy_requirements,
70-
session=session, autobuilding=True
90+
autobuilding=True,
7191
)
7292

7393
return build_failures
@@ -242,6 +262,7 @@ def __init__(self, *args, **kw):
242262
self.parser.insert_option_group(0, cmd_opts)
243263

244264
def run(self, options, args):
265+
# type: (Values, List[Any]) -> int
245266
cmdoptions.check_install_build_global(options)
246267
upgrade_strategy = "to-satisfy-only"
247268
if options.upgrade:
@@ -362,7 +383,6 @@ def run(self, options, args):
362383
builder=wheel_builder,
363384
pep517_requirements=pep517_requirements,
364385
legacy_requirements=legacy_requirements,
365-
session=session,
366386
)
367387

368388
# If we're using PEP 517, we cannot do a direct install
@@ -425,9 +445,11 @@ def run(self, options, args):
425445
except Exception:
426446
pass
427447
items.append(item)
428-
installed = ' '.join(items)
429-
if installed:
430-
logger.info('Successfully installed %s', installed)
448+
installed_desc = ' '.join(items)
449+
if installed_desc:
450+
logger.info(
451+
'Successfully installed %s', installed_desc,
452+
)
431453
except EnvironmentError as error:
432454
show_traceback = (self.verbosity >= 1)
433455

@@ -450,7 +472,8 @@ def run(self, options, args):
450472
self._handle_target_dir(
451473
options.target_dir, target_temp_dir, options.upgrade
452474
)
453-
return requirement_set
475+
476+
return SUCCESS
454477

455478
def _handle_target_dir(self, target_dir, target_temp_dir, upgrade):
456479
ensure_dir(target_dir)

src/pip/_internal/commands/wheel.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
from pip._internal.req import RequirementSet
1212
from pip._internal.req.req_tracker import RequirementTracker
1313
from pip._internal.utils.temp_dir import TempDirectory
14+
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
1415
from pip._internal.wheel import WheelBuilder
1516

17+
if MYPY_CHECK_RUNNING:
18+
from optparse import Values
19+
from typing import Any, List
20+
21+
1622
logger = logging.getLogger(__name__)
1723

1824

@@ -101,6 +107,7 @@ def __init__(self, *args, **kw):
101107
self.parser.insert_option_group(0, cmd_opts)
102108

103109
def run(self, options, args):
110+
# type: (Values, List[Any]) -> None
104111
cmdoptions.check_install_build_global(options)
105112

106113
if options.build_dir:
@@ -153,7 +160,7 @@ def run(self, options, args):
153160
no_clean=options.no_clean,
154161
)
155162
build_failures = wb.build(
156-
requirement_set.requirements.values(), session=session,
163+
requirement_set.requirements.values(),
157164
)
158165
if len(build_failures) != 0:
159166
raise CommandError(

src/pip/_internal/wheel.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pip._vendor.six import StringIO
2828

2929
from pip._internal import pep425tags
30-
from pip._internal.download import unpack_url
30+
from pip._internal.download import unpack_file_url
3131
from pip._internal.exceptions import (
3232
InstallationError,
3333
InvalidWheelFilename,
@@ -57,7 +57,6 @@
5757
)
5858
from pip._vendor.packaging.requirements import Requirement
5959
from pip._internal.req.req_install import InstallRequirement
60-
from pip._internal.download import PipSession
6160
from pip._internal.index import FormatControl, PackageFinder
6261
from pip._internal.operations.prepare import (
6362
RequirementPreparer
@@ -1032,7 +1031,6 @@ def _clean_one(self, req):
10321031
def build(
10331032
self,
10341033
requirements, # type: Iterable[InstallRequirement]
1035-
session, # type: PipSession
10361034
autobuilding=False # type: bool
10371035
):
10381036
# type: (...) -> List[InstallRequirement]
@@ -1122,10 +1120,7 @@ def build(
11221120
req.link = Link(path_to_url(wheel_file))
11231121
assert req.link.is_wheel
11241122
# extract the wheel into the dir
1125-
unpack_url(
1126-
req.link, req.source_dir, None, False,
1127-
session=session,
1128-
)
1123+
unpack_file_url(link=req.link, location=req.source_dir)
11291124
else:
11301125
build_failure.append(req)
11311126

tests/unit/test_command_install.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def check_build_wheels(
99
self,
1010
pep517_requirements,
1111
legacy_requirements,
12-
session,
1312
):
1413
"""
1514
Return: (mock_calls, return_value).
@@ -25,8 +24,6 @@ def build(reqs, **kwargs):
2524
builder=builder,
2625
pep517_requirements=pep517_requirements,
2726
legacy_requirements=legacy_requirements,
28-
# A session value isn't needed.
29-
session='<session>',
3027
)
3128

3229
return (builder.build.mock_calls, build_failures)
@@ -38,13 +35,12 @@ def test_build_wheels__wheel_installed(self, is_wheel_installed):
3835
mock_calls, build_failures = self.check_build_wheels(
3936
pep517_requirements=['a', 'b'],
4037
legacy_requirements=['c', 'd'],
41-
session='<session>',
4238
)
4339

4440
# Legacy requirements were built.
4541
assert mock_calls == [
46-
call(['a', 'b'], autobuilding=True, session='<session>'),
47-
call(['c', 'd'], autobuilding=True, session='<session>'),
42+
call(['a', 'b'], autobuilding=True),
43+
call(['c', 'd'], autobuilding=True),
4844
]
4945

5046
# Legacy build failures are not included in the return value.
@@ -57,12 +53,11 @@ def test_build_wheels__wheel_not_installed(self, is_wheel_installed):
5753
mock_calls, build_failures = self.check_build_wheels(
5854
pep517_requirements=['a', 'b'],
5955
legacy_requirements=['c', 'd'],
60-
session='<session>',
6156
)
6257

6358
# Legacy requirements were not built.
6459
assert mock_calls == [
65-
call(['a', 'b'], autobuilding=True, session='<session>'),
60+
call(['a', 'b'], autobuilding=True),
6661
]
6762

6863
assert build_failures == ['a']

tests/unit/test_wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ def test_skip_building_wheels(self, caplog):
700700
finder=Mock(), preparer=Mock(), wheel_cache=None,
701701
)
702702
with caplog.at_level(logging.INFO):
703-
wb.build([wheel_req], session=Mock())
703+
wb.build([wheel_req])
704704
assert "due to already being wheel" in caplog.text
705705
assert mock_build_one.mock_calls == []
706706

0 commit comments

Comments
 (0)