Skip to content

Commit cbc03f3

Browse files
authored
Merge pull request #7275 from chrahunt/refactor/return-installedrequirement
Return InstallationResult from requirement installation
2 parents a0fd8c2 + 9dc0659 commit cbc03f3

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/pip/_internal/commands/install.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,13 @@ def run(self, options, args):
463463
)
464464
working_set = pkg_resources.WorkingSet(lib_locations)
465465

466-
reqs = sorted(installed, key=operator.attrgetter('name'))
466+
installed.sort(key=operator.attrgetter('name'))
467467
items = []
468-
for req in reqs:
469-
item = req.name
468+
for result in installed:
469+
item = result.name
470470
try:
471471
installed_version = get_installed_version(
472-
req.name, working_set=working_set
472+
result.name, working_set=working_set
473473
)
474474
if installed_version:
475475
item += '-' + installed_version

src/pip/_internal/req/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,24 @@
2323
logger = logging.getLogger(__name__)
2424

2525

26+
class InstallationResult(object):
27+
def __init__(self, name):
28+
# type: (str) -> None
29+
self.name = name
30+
31+
def __repr__(self):
32+
# type: () -> str
33+
return "InstallationResult(name={!r})".format(self.name)
34+
35+
2636
def install_given_reqs(
2737
to_install, # type: List[InstallRequirement]
2838
install_options, # type: List[str]
2939
global_options=(), # type: Sequence[str]
3040
*args, # type: Any
3141
**kwargs # type: Any
3242
):
33-
# type: (...) -> List[InstallRequirement]
43+
# type: (...) -> List[InstallationResult]
3444
"""
3545
Install everything in the given list.
3646
@@ -43,6 +53,8 @@ def install_given_reqs(
4353
', '.join([req.name for req in to_install]),
4454
)
4555

56+
installed = []
57+
4658
with indent_log():
4759
for requirement in to_install:
4860
if requirement.conflicts_with:
@@ -79,4 +91,6 @@ def install_given_reqs(
7991
uninstalled_pathset.commit()
8092
requirement.remove_temporary_source()
8193

82-
return to_install
94+
installed.append(InstallationResult(requirement.name))
95+
96+
return installed

0 commit comments

Comments
 (0)