Skip to content

Commit ffa2694

Browse files
committed
Psyko-rebased branch feature/freeze-subset-recursively on top of develop.
2 parents a2ab21d + d84fb4a commit ffa2694

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

pip/commands/freeze.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from pip.compat import stdlib_pkgs
1111
from pip.req import InstallRequirement
1212
from pip.basecommand import Command
13-
from pip.utils import get_installed_distributions
13+
from pip.utils import get_installed_distributions, get_recursive_dependencies
1414
from pip._vendor import pkg_resources
1515

16+
1617
# packages to exclude from freeze output
1718
freeze_excludes = stdlib_pkgs + ['setuptools', 'pip', 'distribute']
1819

@@ -28,7 +29,7 @@ class FreezeCommand(Command):
2829
"""
2930
name = 'freeze'
3031
usage = """
31-
%prog [options]"""
32+
%prog [options] [PACKAGE PACKAGE...]"""
3233
summary = 'Output installed packages in requirements format.'
3334
log_stream = "ext://sys.stderr"
3435

@@ -95,6 +96,13 @@ def run(self, options, args):
9596
for link in find_links:
9697
f.write('-f %s\n' % link)
9798
installations = {}
99+
100+
only_dists = []
101+
if args:
102+
only_dists = args
103+
only_dists.extend(get_recursive_dependencies(*only_dists))
104+
only_dists = [name.lower() for name in only_dists]
105+
98106
for dist in get_installed_distributions(local_only=local_only,
99107
skip=freeze_excludes,
100108
user_only=user_only):

pip/commands/show.py

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55

66
from pip.basecommand import Command
7+
from pip.utils import get_recursive_dependencies
78
from pip._vendor import pkg_resources
89

910

@@ -85,6 +86,8 @@ def print_results(distributions, list_all_files):
8586
logger.info("Version: %s" % dist['version'])
8687
logger.info("Location: %s" % dist['location'])
8788
logger.info("Requires: %s" % ', '.join(dist['requires']))
89+
logger.info("Requires recursive: %s" % ', '.join(
90+
get_recursive_dependencies(dist['name'])))
8891
if list_all_files:
8992
logger.info("Files:")
9093
if dist['files'] is not None:

pip/utils/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,25 @@ def get_installed_distributions(local_only=True,
424424
]
425425

426426

427+
def get_recursive_dependencies(*names):
428+
"""Return set of dependencies of dists in ``names``, recursively."""
429+
dependencies = set()
430+
installed = dict(
431+
[(p.project_name.lower(), p) for p in pkg_resources.working_set])
432+
query_names = [name.lower() for name in names]
433+
for pkg in query_names:
434+
try:
435+
dist = installed[pkg]
436+
except KeyError:
437+
pass # pkg is not installed.
438+
else:
439+
for dep in dist.requires():
440+
name = dep.project_name
441+
dependencies.add(name)
442+
dependencies.update(get_recursive_dependencies(name))
443+
return dependencies
444+
445+
427446
def egg_link_path(dist):
428447
"""
429448
Return the path for the .egg-link file if it exists, otherwise, None.

tests/functional/test_show.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ def test_show(script):
99
"""
1010
result = script.pip('show', 'pip')
1111
lines = result.stdout.split('\n')
12-
assert len(lines) == 6
12+
assert len(lines) == 7
1313
assert lines[0] == '---', lines[0]
1414
assert lines[1] == 'Name: pip', lines[1]
1515
assert lines[2] == 'Version: %s' % __version__, lines[2]
1616
assert lines[3].startswith('Location: '), lines[3]
1717
assert lines[4] == 'Requires: '
18+
assert lines[5] == 'Requires recursive: '
1819

1920

2021
def test_show_with_files_not_found(script, data):
@@ -26,14 +27,15 @@ def test_show_with_files_not_found(script, data):
2627
script.pip('install', '-e', editable)
2728
result = script.pip('show', '-f', 'SetupPyUTF8')
2829
lines = result.stdout.split('\n')
29-
assert len(lines) == 8
30+
assert len(lines) == 9
3031
assert lines[0] == '---', lines[0]
3132
assert lines[1] == 'Name: SetupPyUTF8', lines[1]
3233
assert lines[2] == 'Version: 0.0.0', lines[2]
3334
assert lines[3].startswith('Location: '), lines[3]
3435
assert lines[4] == 'Requires: ', lines[4]
35-
assert lines[5] == 'Files:', lines[5]
36-
assert lines[6] == 'Cannot locate installed-files.txt', lines[6]
36+
assert lines[5] == 'Requires recursive: ', lines[5]
37+
assert lines[6] == 'Files:', lines[6]
38+
assert lines[7] == 'Cannot locate installed-files.txt', lines[7]
3739

3840

3941
def test_show_with_files_from_wheel(script, data):

0 commit comments

Comments
 (0)