mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Basic behaviour of the list command.
This commit is contained in:
parent
0267e8a684
commit
5a02b6674e
2 changed files with 46 additions and 13 deletions
|
@ -80,32 +80,26 @@ class ListCommand(Command):
|
|||
def run(self, options, args):
|
||||
if options.outdated:
|
||||
self.run_outdated(options, args)
|
||||
else:
|
||||
self.run_listing(options, args)
|
||||
|
||||
def run_outdated(self, options, args):
|
||||
local_only = options.local
|
||||
index_urls = [options.index_url] + options.extra_index_urls
|
||||
if options.no_index:
|
||||
logger.notify('Ignoring indexes: %s' % ','.join(index_urls))
|
||||
index_urls = []
|
||||
|
||||
installations = {}
|
||||
dependency_links = []
|
||||
|
||||
for dist in pkg_resources.working_set:
|
||||
if dist.has_metadata('dependency_links.txt'):
|
||||
dependency_links.extend(
|
||||
dist.get_metadata_lines('dependency_links.txt'),
|
||||
)
|
||||
|
||||
for dist in get_installed_distributions(local_only=local_only):
|
||||
req = InstallRequirement.from_line(dist.key, None)
|
||||
req.check_if_exists()
|
||||
installations[req.name] = req
|
||||
|
||||
finder = self._build_package_finder(options, index_urls)
|
||||
finder.add_dependency_links(dependency_links)
|
||||
|
||||
for req in installations.values():
|
||||
for req in self.find_installed_packages(options):
|
||||
try:
|
||||
link = finder.find_requirement(req, True)
|
||||
|
||||
|
@ -124,5 +118,17 @@ class ListCommand(Command):
|
|||
if remote_version > req.installed_version:
|
||||
logger.notify('%s (CURRENT: %s LATEST: %s)' % (req.name, req.installed_version, remote_version))
|
||||
|
||||
def find_installed_packages(self, options):
|
||||
local_only = options.local
|
||||
for dist in get_installed_distributions(local_only=local_only):
|
||||
req = InstallRequirement.from_line(dist.key, None)
|
||||
req.check_if_exists()
|
||||
yield req
|
||||
|
||||
def run_listing(self, options, args):
|
||||
installed_packages = self.find_installed_packages(options)
|
||||
for req in installed_packages:
|
||||
logger.notify('%s (%s)' % (req.name, req.installed_version))
|
||||
|
||||
|
||||
ListCommand()
|
||||
|
|
|
@ -2,7 +2,7 @@ import re
|
|||
import sys
|
||||
import textwrap
|
||||
from doctest import OutputChecker, ELLIPSIS
|
||||
from test_pip import reset_env, run_pip, write_file
|
||||
from test_pip import pyversion, reset_env, run_pip, write_file
|
||||
|
||||
|
||||
distribute_re = re.compile(r'^distribute==[0-9.]+ \(CURRENT: [0-9.]+ LATEST: [0-9.]+\)\n', re.MULTILINE)
|
||||
|
@ -32,9 +32,36 @@ def _check_output(result, expected):
|
|||
assert checker.check_output(expected, actual, ELLIPSIS), banner('EXPECTED')+expected+banner('ACTUAL')+actual+banner(6*'=')
|
||||
|
||||
|
||||
def test_list_command():
|
||||
"""
|
||||
Test default behavior of list command.
|
||||
|
||||
"""
|
||||
reset_env()
|
||||
run_pip('install', 'INITools==0.2', 'simplejson==2.0.0')
|
||||
result = run_pip('list')
|
||||
expected = textwrap.dedent("""\
|
||||
Script result: pip list
|
||||
-- stdout: --------------------
|
||||
""")
|
||||
if pyversion < (3,):
|
||||
expected += textwrap.dedent("""\
|
||||
wsgiref (...)
|
||||
initools (0.2)
|
||||
simplejson (2.0.0)
|
||||
""")
|
||||
else:
|
||||
expected += textwrap.dedent("""\
|
||||
initools (0.2)
|
||||
simplejson (2.0.0)
|
||||
""")
|
||||
_check_output(result, textwrap.dedent(expected))
|
||||
|
||||
|
||||
def test_outdated_default():
|
||||
"""
|
||||
Test default behavor of --outdated option in the list command
|
||||
Test the behavior of --outdated option in the list command
|
||||
|
||||
"""
|
||||
|
||||
env = reset_env()
|
||||
|
@ -53,7 +80,7 @@ def test_outdated_default():
|
|||
expected = textwrap.dedent("""\
|
||||
Script result: pip list --outdated
|
||||
-- stdout: --------------------
|
||||
simplejson (CURRENT: 2.0.0 LATEST: %s)
|
||||
initools (CURRENT: 0.2 LATEST: %s)
|
||||
""" % (simplejson_ver, initools_ver))
|
||||
simplejson (CURRENT: 2.0.0 LATEST: %s)
|
||||
""" % (initools_ver, simplejson_ver))
|
||||
_check_output(result, expected)
|
||||
|
|
Loading…
Reference in a new issue