提交 1ca4e5e1 编写于 作者: X Xavier Fernandez

Merge pull request #3686 from xavfernandez/list_format

Add --format option to pip list
......@@ -66,13 +66,29 @@ Examples
retry 0.8.1 0.9.1 wheel
setuptools 20.6.7 21.0.0 wheel
#. Do not use column formatting.
#. Use legacy formatting
::
$ pip list --no-columns
DEPRECATION: The --no-columns option will be removed in the future.
$ pip list --format=legacy
colorama (0.3.7)
docopt (0.6.2)
idlex (1.13)
jedi (0.9.0)
#. Use json formatting
::
$ pip list --format=json
[{'name': 'colorama', 'version': '0.3.7'}, {'name': 'docopt', 'version': '0.6.2'}, ...
#. Use freeze formatting
::
$ pip list --format=freeze
colorama==0.3.7
docopt==0.6.2
idlex==1.13
jedi==0.9.0
......@@ -317,7 +317,7 @@ class RequirementCommand(Command):
"""
index_urls = [options.index_url] + options.extra_index_urls
if options.no_index:
logger.info('Ignoring indexes: %s', ','.join(index_urls))
logger.debug('Ignoring indexes: %s', ','.join(index_urls))
index_urls = []
return PackageFinder(
......
from __future__ import absolute_import
import json
import logging
import warnings
try:
......@@ -7,6 +8,8 @@ try:
except ImportError:
from itertools import izip_longest as zip_longest
from pip._vendor import six
from pip.basecommand import Command
from pip.exceptions import CommandError
from pip.index import PackageFinder
......@@ -15,7 +18,6 @@ from pip.utils import (
from pip.utils.deprecation import RemovedInPip10Warning
from pip.cmdoptions import make_option_group, index_group
logger = logging.getLogger(__name__)
......@@ -72,21 +74,21 @@ class ListCommand(Command):
"pip only finds stable versions."),
)
# TODO: When we switch the default, set default=True here.
cmd_opts.add_option(
'--columns',
action='store_true',
dest='columns',
# default=True,
help="Align package names and versions into vertical columns.",
'--format',
action='store',
dest='list_format',
choices=('legacy', 'columns', 'freeze', 'json'),
help="Select the output format among: legacy (default), columns, "
"freeze or json.",
)
cmd_opts.add_option(
'--no-columns',
action='store_false',
dest='columns',
help=("Do not align package names and versions into "
"vertical columns (old-style formatting)"),
'--columns',
action='store_const',
const='columns',
dest='list_format',
help="Align package names and versions into vertical columns.",
)
index_opts = make_option_group(index_group, self.parser)
......@@ -132,11 +134,11 @@ class ListCommand(Command):
RemovedInPip10Warning,
)
# TODO: When we switch the default, remove
# ``and options.columns is not None``
if not options.columns and options.columns is not None:
if options.list_format is None:
warnings.warn(
"The --no-columns option will be removed in the future.",
"The default format will switch to columns in the future. "
"You can use --format=legacy (or define a list_format "
"in your pip.conf) to disable this warning.",
RemovedInPip10Warning,
)
......@@ -144,43 +146,37 @@ class ListCommand(Command):
raise CommandError(
"Options --outdated and --uptodate cannot be combined.")
packages = get_installed_distributions(
local_only=options.local,
user_only=options.user,
editables_only=options.editable,
)
if options.outdated:
self.run_outdated(options)
packages = self.get_outdated(packages, options)
elif options.uptodate:
self.run_uptodate(options)
else:
self.run_listing(options)
def run_outdated(self, options):
latest_pkgs = []
for dist, latest_version, typ in sorted(
self.find_packages_latest_versions(options),
key=lambda p: p[0].project_name.lower()):
if latest_version > dist.parsed_version:
latest_pkgs.append((dist, latest_version, typ))
if (hasattr(options, "columns") and
options.columns and
len(latest_pkgs) > 0):
data, header = format_for_columns(latest_pkgs, options)
self.output_package_listing_columns(data, header)
else:
for dist, latest_version, typ in latest_pkgs:
logger.info(
'%s - Latest: %s [%s]',
self.output_package(dist), latest_version, typ,
)
def find_packages_latest_versions(self, options):
packages = self.get_uptodate(packages, options)
self.output_package_listing(packages, options)
def get_outdated(self, packages, options):
return [
dist for dist in self.iter_packages_latest_infos(packages, options)
if dist.latest_version > dist.parsed_version
]
def get_uptodate(self, packages, options):
return [
dist for dist in self.iter_packages_latest_infos(packages, options)
if dist.latest_version == dist.parsed_version
]
def iter_packages_latest_infos(self, packages, options):
index_urls = [options.index_url] + options.extra_index_urls
if options.no_index:
logger.info('Ignoring indexes: %s', ','.join(index_urls))
logger.debug('Ignoring indexes: %s', ','.join(index_urls))
index_urls = []
dependency_links = []
for dist in get_installed_distributions(
local_only=options.local,
user_only=options.user,
editables_only=options.editable):
for dist in packages:
if dist.has_metadata('dependency_links.txt'):
dependency_links.extend(
dist.get_metadata_lines('dependency_links.txt'),
......@@ -190,12 +186,7 @@ class ListCommand(Command):
finder = self._build_package_finder(options, index_urls, session)
finder.add_dependency_links(dependency_links)
installed_packages = get_installed_distributions(
local_only=options.local,
user_only=options.user,
editables_only=options.editable,
)
for dist in installed_packages:
for dist in packages:
typ = 'unknown'
all_candidates = finder.find_all_candidates(dist.key)
if not options.pre:
......@@ -212,17 +203,12 @@ class ListCommand(Command):
typ = 'wheel'
else:
typ = 'sdist'
yield dist, remote_version, typ
# This is dirty but makes the rest of the code much cleaner
dist.latest_version = remote_version
dist.latest_filetype = typ
yield dist
def run_listing(self, options):
installed_packages = get_installed_distributions(
local_only=options.local,
user_only=options.user,
editables_only=options.editable,
)
self.output_package_listing(installed_packages, options)
def output_package(self, dist):
def output_legacy(self, dist):
if dist_is_editable(dist):
return '%s (%s, %s)' % (
dist.project_name,
......@@ -232,19 +218,32 @@ class ListCommand(Command):
else:
return '%s (%s)' % (dist.project_name, dist.version)
def output_package_listing(self, installed_packages, options=None):
installed_packages = sorted(
installed_packages,
def output_legacy_latest(self, dist):
return '%s - Latest: %s [%s]' % (
self.output_legacy(dist),
dist.latest_version,
dist.latest_filetype,
)
def output_package_listing(self, packages, options):
packages = sorted(
packages,
key=lambda dist: dist.project_name.lower(),
)
if (hasattr(options, "columns") and
options.columns and
len(installed_packages) > 0):
data, header = format_for_columns(installed_packages, options)
if options.list_format == 'columns' and packages:
data, header = format_for_columns(packages, options)
self.output_package_listing_columns(data, header)
else:
for dist in installed_packages:
logger.info(self.output_package(dist))
elif options.list_format == 'freeze':
for dist in packages:
logger.info("%s==%s", dist.project_name, dist.version)
elif options.list_format == 'json':
logger.info(format_for_json(packages, options))
else: # legacy
for dist in packages:
if options.outdated:
logger.info(self.output_legacy_latest(dist))
else:
logger.info(self.output_legacy(dist))
def output_package_listing_columns(self, data, header):
# insert the header first: we need to know the size of column names
......@@ -260,13 +259,6 @@ class ListCommand(Command):
for val in pkg_strings:
logger.info(val)
def run_uptodate(self, options):
uptodate = []
for dist, version, typ in self.find_packages_latest_versions(options):
if dist.parsed_version == version:
uptodate.append(dist)
self.output_package_listing(uptodate, options)
def tabulate(vals):
# From pfmoore on GitHub:
......@@ -291,31 +283,25 @@ def format_for_columns(pkgs, options):
Convert the package data into something usable
by output_package_listing_columns.
"""
header = ["Package", "Version"]
running_outdated = False
running_outdated = options.outdated
# Adjust the header for the `pip list --outdated` case.
if isinstance(pkgs[0], (list, tuple)):
running_outdated = True
if running_outdated:
header = ["Package", "Version", "Latest", "Type"]
else:
header = ["Package", "Version"]
data = []
if any(dist_is_editable(x[0])
if running_outdated
else dist_is_editable(x)
for x in pkgs):
if any(dist_is_editable(x) for x in pkgs):
header.append("Location")
for proj in pkgs:
# if we're working on the 'outdated' list, separate out the
# latest_version and type
if running_outdated:
proj, latest_version, typ = proj
row = [proj.project_name, proj.version]
if running_outdated:
row.append(latest_version)
row.append(typ)
row.append(proj.latest_version)
row.append(proj.latest_filetype)
if dist_is_editable(proj):
row.append(proj.location)
......@@ -323,3 +309,17 @@ def format_for_columns(pkgs, options):
data.append(row)
return data, header
def format_for_json(packages, options):
data = []
for dist in packages:
info = {
'name': dist.project_name,
'version': six.text_type(dist.version),
}
if options.outdated:
info['latest_version'] = six.text_type(dist.latest_version)
info['latest_filetype'] = dist.latest_filetype
data.append(info)
return json.dumps(data)
......@@ -151,7 +151,7 @@ class WheelCommand(RequirementCommand):
index_urls = [options.index_url] + options.extra_index_urls
if options.no_index:
logger.info('Ignoring indexes: %s', ','.join(index_urls))
logger.debug('Ignoring indexes: %s', ','.join(index_urls))
index_urls = []
if options.build_dir:
......
......@@ -804,8 +804,8 @@ def test_install_upgrade_editable_depending_on_other_editable(script):
version='0.1')
"""))
script.pip('install', '--editable', pkga_path)
result = script.pip('list')
assert "pkga" in result.stdout
result = script.pip('list', '--format=freeze')
assert "pkga==0.1" in result.stdout
script.scratch_path.join("pkgb").mkdir()
pkgb_path = script.scratch_path / 'pkgb'
......@@ -815,9 +815,9 @@ def test_install_upgrade_editable_depending_on_other_editable(script):
version='0.1',
install_requires=['pkga'])
"""))
script.pip('install', '--upgrade', '--editable', pkgb_path)
result = script.pip('list')
assert "pkgb" in result.stdout
script.pip('install', '--upgrade', '--editable', pkgb_path, '--no-index')
result = script.pip('list', '--format=freeze')
assert "pkgb==0.1" in result.stdout
def test_install_subprocess_output_handling(script, data):
......
......@@ -361,7 +361,7 @@ class TestUpgradeDistributeToSetuptools(object):
"Found existing installation: distribute 0.6.34" in result.stdout
)
result = self.script.run(
self.ve_bin / 'pip', 'list',
self.ve_bin / 'pip', 'list', '--format=legacy',
expect_stderr=True if sys.version_info[:2] == (2, 6) else False,
)
assert "setuptools (0.9.8)" in result.stdout
......
import json
import os
import pytest
WARN_NOCOL = ("DEPRECATION: The --no-columns option will be "
"removed in the future.")
WARN_FORMAT = ("DEPRECATION: The default format will switch to columns in the "
"future. You can use --format=legacy (or define a list_format "
"in your pip.conf) to disable this warning.")
def test_list_command(script, data):
"""
Test default behavior of list command.
Test default behavior of list command without format specifier.
A warning is expected.
"""
script.pip(
'install', '-f', data.find_links, '--no-index', 'simple==1.0',
'simple2==3.0',
)
result = script.pip('list')
result = script.pip('list', expect_stderr=True)
assert WARN_FORMAT in result.stderr, str(result)
assert 'simple (1.0)' in result.stdout, str(result)
assert 'simple2 (3.0)' in result.stdout, str(result)
......@@ -35,51 +39,34 @@ def test_columns_flag(script, data):
assert 'simple2 3.0' in result.stdout, str(result)
def test_nocolumns_flag(script, data):
def test_legacy_format(script, data):
"""
Test that --no-columns raises the deprecation warning and still outputs
the old-style formatting.
Test that legacy format
"""
script.pip(
'install', '-f', data.find_links, '--no-index', 'simple==1.0',
'simple2==3.0',
)
result = script.pip('list', '--no-columns', expect_stderr=True)
assert WARN_NOCOL in result.stderr, str(result)
result = script.pip('list', '--format=legacy')
assert 'simple (1.0)' in result.stdout, str(result)
assert 'simple2 (3.0)' in result.stdout, str(result)
def test_columns_nocolumns(script, data):
def test_format_priority(script, data):
"""
Test that --no-columns has priority in --columns --no-columns.
Test that latest format has priority over previous ones.
"""
script.pip(
'install', '-f', data.find_links, '--no-index', 'simple==1.0',
'simple2==3.0',
)
result = script.pip(
'list', '--columns', '--no-columns',
expect_error=True,
)
assert WARN_NOCOL in result.stderr, str(result)
result = script.pip('list', '--format=columns', '--format=legacy')
assert 'simple (1.0)' in result.stdout, str(result)
assert 'simple2 (3.0)' in result.stdout, str(result)
assert 'simple 1.0' not in result.stdout, str(result)
assert 'simple2 3.0' not in result.stdout, str(result)
def test_nocolumns_columns(script, data):
"""
Test that --columns has priority in --no-columns --columns.
"""
script.pip(
'install', '-f', data.find_links, '--no-index', 'simple==1.0',
'simple2==3.0',
)
result = script.pip(
'list', '--no-columns', '--columns',
)
result = script.pip('list', '--format=legacy', '--columns')
assert 'Package' in result.stdout, str(result)
assert 'Version' in result.stdout, str(result)
assert 'simple (1.0)' not in result.stdout, str(result)
......@@ -94,7 +81,7 @@ def test_local_flag(script, data):
"""
script.pip('install', '-f', data.find_links, '--no-index', 'simple==1.0')
result = script.pip('list', '--local')
result = script.pip('list', '--local', '--format=legacy')
assert 'simple (1.0)' in result.stdout
......@@ -111,14 +98,13 @@ def test_local_columns_flag(script, data):
assert 'simple 1.0' in result.stdout, str(result)
def test_local_nocolumns_flag(script, data):
def test_local_legacy_flag(script, data):
"""
Test the behavior of --local --no-columns flags in the list
Test the behavior of --local --format=legacy flags in the list
command.
"""
script.pip('install', '-f', data.find_links, '--no-index', 'simple==1.0')
result = script.pip('list', '--local', '--no-columns', expect_stderr=True)
assert WARN_NOCOL in result.stderr, str(result)
result = script.pip('list', '--local', '--format=legacy')
assert 'simple (1.0)' in result.stdout
......@@ -131,7 +117,7 @@ def test_user_flag(script, data, virtualenv):
script.pip('install', '-f', data.find_links, '--no-index', 'simple==1.0')
script.pip('install', '-f', data.find_links, '--no-index',
'--user', 'simple2==2.0')
result = script.pip('list', '--user')
result = script.pip('list', '--user', '--format=legacy')
assert 'simple (1.0)' not in result.stdout
assert 'simple2 (2.0)' in result.stdout
......@@ -152,7 +138,7 @@ def test_user_columns_flag(script, data, virtualenv):
assert 'simple2 2.0' in result.stdout, str(result)
def test_user_nocolumns_flag(script, data, virtualenv):
def test_user_legacy(script, data, virtualenv):
"""
Test the behavior of --user flag in the list command
......@@ -161,8 +147,7 @@ def test_user_nocolumns_flag(script, data, virtualenv):
script.pip('install', '-f', data.find_links, '--no-index', 'simple==1.0')
script.pip('install', '-f', data.find_links, '--no-index',
'--user', 'simple2==2.0')
result = script.pip('list', '--user', '--no-columns', expect_stderr=True)
assert WARN_NOCOL in result.stderr, str(result)
result = script.pip('list', '--user', '--format=legacy')
assert 'simple (1.0)' not in result.stdout
assert 'simple2 (2.0)' in result.stdout, str(result)
......@@ -183,7 +168,7 @@ def test_uptodate_flag(script, data):
)
result = script.pip(
'list', '-f', data.find_links, '--no-index', '--uptodate',
expect_stderr=True,
'--format=legacy',
)
assert 'simple (1.0)' not in result.stdout # 3.0 is latest
assert 'pip-test-package (0.1.1,' in result.stdout # editables included
......@@ -217,9 +202,9 @@ def test_uptodate_columns_flag(script, data):
@pytest.mark.network
def test_uptodate_nocolumns_flag(script, data):
def test_uptodate_legacy_flag(script, data):
"""
Test the behavior of --uptodate --no-columns flag in the list command
Test the behavior of --uptodate --format=legacy flag in the list command
"""
script.pip(
......@@ -232,9 +217,8 @@ def test_uptodate_nocolumns_flag(script, data):
)
result = script.pip(
'list', '-f', data.find_links, '--no-index', '--uptodate',
'--no-columns', expect_stderr=True,
'--format=legacy',
)
assert WARN_NOCOL in result.stderr, str(result)
assert 'simple (1.0)' not in result.stdout # 3.0 is latest
assert 'pip-test-package (0.1.1,' in result.stdout # editables included
assert 'simple2 (3.0)' in result.stdout, str(result)
......@@ -257,7 +241,7 @@ def test_outdated_flag(script, data):
)
result = script.pip(
'list', '-f', data.find_links, '--no-index', '--outdated',
expect_stderr=True,
'--format=legacy',
)
assert 'simple (1.0) - Latest: 3.0 [sdist]' in result.stdout
assert 'simplewheel (1.0) - Latest: 2.0 [wheel]' in result.stdout
......@@ -301,9 +285,9 @@ def test_outdated_columns_flag(script, data):
@pytest.mark.network
def test_outdated_nocolumns_flag(script, data):
def test_outdated_legacy(script, data):
"""
Test the behavior of --outdated --no-columns flag in the list command
Test the behavior of --outdated --format=legacy flag in the list command
"""
script.pip(
......@@ -317,9 +301,8 @@ def test_outdated_nocolumns_flag(script, data):
)
result = script.pip(
'list', '-f', data.find_links, '--no-index', '--outdated',
'--no-columns', expect_stderr=True,
'--format=legacy',
)
assert WARN_NOCOL in result.stderr, str(result)
assert 'simple (1.0) - Latest: 3.0 [sdist]' in result.stdout
assert 'simplewheel (1.0) - Latest: 2.0 [wheel]' in result.stdout
assert 'pip-test-package (0.1, ' in result.stdout
......@@ -337,7 +320,7 @@ def test_editables_flag(script, data):
'install', '-e',
'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package'
)
result = script.pip('list', '--editable')
result = script.pip('list', '--editable', '--format=legacy')
assert 'simple (1.0)' not in result.stdout, str(result)
assert os.path.join('src', 'pip-test-package') in result.stdout, (
str(result)
......@@ -364,7 +347,7 @@ def test_editables_columns_flag(script, data):
@pytest.mark.network
def test_editables_nocolumns_flag(script, data):
def test_editables_legacy(script, data):
"""
Test the behavior of --editables flag in the list command
"""
......@@ -374,9 +357,8 @@ def test_editables_nocolumns_flag(script, data):
'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package'
)
result = script.pip(
'list', '--editable', '--no-columns', expect_stderr=True,
'list', '--editable', '--format=legacy', expect_stderr=True,
)
assert WARN_NOCOL in result.stderr, str(result)
assert 'simple (1.0)' not in result.stdout, str(result)
assert os.path.join('src', 'pip-test-package') in result.stdout, (
str(result)
......@@ -396,7 +378,7 @@ def test_uptodate_editables_flag(script, data):
result = script.pip(
'list', '-f', data.find_links, '--no-index',
'--editable', '--uptodate',
expect_stderr=True,
'--format=legacy',
)
assert 'simple (1.0)' not in result.stdout, str(result)
assert os.path.join('src', 'pip-test-package') in result.stdout, (
......@@ -428,9 +410,9 @@ def test_uptodate_editables_columns_flag(script, data):
@pytest.mark.network
def test_uptodate_editables_nocolumns_flag(script, data):
def test_uptodate_editables_legacy(script, data):
"""
test the behavior of --editable --uptodate --columns --no-columns flag
test the behavior of --editable --uptodate --columns --format=legacy flag
in the list command
"""
script.pip('install', '-f', data.find_links, '--no-index', 'simple==1.0')
......@@ -440,9 +422,8 @@ def test_uptodate_editables_nocolumns_flag(script, data):
)
result = script.pip(
'list', '-f', data.find_links, '--no-index', '--editable',
'--uptodate', '--no-columns', expect_stderr=True,
'--uptodate', '--format=legacy',
)
assert WARN_NOCOL in result.stderr, str(result)
assert 'simple (1.0)' not in result.stdout, str(result)
assert os.path.join('src', 'pip-test-package') in result.stdout, (
str(result)
......@@ -463,7 +444,7 @@ def test_outdated_editables_flag(script, data):
result = script.pip(
'list', '-f', data.find_links, '--no-index',
'--editable', '--outdated',
expect_stderr=True,
'--format=legacy',
)
assert 'simple (1.0)' not in result.stdout, str(result)
assert os.path.join('src', 'pip-test-package') in result.stdout, (
......@@ -495,7 +476,7 @@ def test_outdated_editables_columns_flag(script, data):
@pytest.mark.network
def test_outdated_editables_nocolumns_flag(script, data):
def test_outdated_editables_legacy(script, data):
"""
test the behavior of --editable --outdated flag in the list command
"""
......@@ -507,10 +488,8 @@ def test_outdated_editables_nocolumns_flag(script, data):
)
result = script.pip(
'list', '-f', data.find_links, '--no-index',
'--editable', '--outdated', '--no-columns',
expect_stderr=True,
'--editable', '--outdated', '--format=legacy',
)
assert WARN_NOCOL in result.stderr, str(result)
assert 'simple (1.0)' not in result.stdout, str(result)
assert os.path.join('src', 'pip-test-package') in result.stdout, (
str(result)
......@@ -525,58 +504,90 @@ def test_outdated_pre(script, data):
wheelhouse_path = script.scratch_path / 'wheelhouse'
wheelhouse_path.join('simple-1.1-py2.py3-none-any.whl').write('')
wheelhouse_path.join('simple-2.0.dev0-py2.py3-none-any.whl').write('')
result = script.pip('list', '--no-index', '--find-links', wheelhouse_path)
result = script.pip(
'list', '--no-index', '--find-links', wheelhouse_path,
'--format=legacy',
)
assert 'simple (1.0)' in result.stdout
result = script.pip('list', '--no-index', '--find-links', wheelhouse_path,
'--outdated')
result = script.pip(
'list', '--no-index', '--find-links', wheelhouse_path, '--outdated',
'--format=legacy',
)
assert 'simple (1.0) - Latest: 1.1 [wheel]' in result.stdout
result_pre = script.pip('list', '--no-index',
'--find-links', wheelhouse_path,
'--outdated', '--pre')
'--outdated', '--pre', '--format=legacy')
assert 'simple (1.0) - Latest: 2.0.dev0 [wheel]' in result_pre.stdout
def test_outdated_pre_columns(script, data):
""" Test of interaction behavior of --pre and --columns """
def test_outdated_formats(script, data):
""" Test of different outdated formats """
script.pip('install', '-f', data.find_links, '--no-index', 'simple==1.0')
# Let's build a fake wheelhouse
script.scratch_path.join("wheelhouse").mkdir()
wheelhouse_path = script.scratch_path / 'wheelhouse'
wheelhouse_path.join('simple-1.1-py2.py3-none-any.whl').write('')
wheelhouse_path.join('simple-2.0.dev0-py2.py3-none-any.whl').write('')
result = script.pip('list', '--no-index', '--find-links', wheelhouse_path)
assert 'simple (1.0)' in result.stdout
result = script.pip(
'list', '--no-index', '--find-links', wheelhouse_path,
'--format=freeze',
)
assert 'simple==1.0' in result.stdout
# Check legacy
result = script.pip('list', '--no-index', '--find-links', wheelhouse_path,
'--outdated')
'--outdated', '--format=legacy')
assert 'simple (1.0) - Latest: 1.1 [wheel]' in result.stdout
result_pre = script.pip(
# Check columns
result = script.pip(
'list', '--no-index', '--find-links', wheelhouse_path,
'--outdated', '--pre', '--columns',
'--outdated', '--columns',
)
assert 'Package' in result_pre.stdout
assert 'Version' in result_pre.stdout
assert 'Latest' in result_pre.stdout
assert 'Type' in result_pre.stdout
assert 'Package Version Latest Type' in result.stdout
assert 'simple 1.0 1.1 wheel' in result.stdout
def test_outdated_pre_nocolumns(script, data):
""" Test of interaction behavior of --pre and --no-columns """
script.pip('install', '-f', data.find_links, '--no-index', 'simple==1.0')
# Check freeze
result = script.pip(
'list', '--no-index', '--find-links', wheelhouse_path,
'--outdated', '--format=freeze',
)
assert 'simple==1.0' in result.stdout
# Let's build a fake wheelhouse
script.scratch_path.join("wheelhouse").mkdir()
wheelhouse_path = script.scratch_path / 'wheelhouse'
wheelhouse_path.join('simple-1.1-py2.py3-none-any.whl').write('')
wheelhouse_path.join('simple-2.0.dev0-py2.py3-none-any.whl').write('')
result = script.pip('list', '--no-index', '--find-links', wheelhouse_path)
assert 'simple (1.0)' in result.stdout
result = script.pip('list', '--no-index', '--find-links', wheelhouse_path,
'--outdated')
assert 'simple (1.0) - Latest: 1.1 [wheel]' in result.stdout
# Check json
result = script.pip(
'list', '--no-index',
'--find-links', wheelhouse_path,
'--outdated', '--pre', '--no-columns', expect_stderr=True
'list', '--no-index', '--find-links', wheelhouse_path,
'--outdated', '--format=json',
)
data = json.loads(result.stdout)
assert data == [{'name': 'simple', 'version': '1.0',
'latest_version': '1.1', 'latest_filetype': 'wheel'}]
def test_list_freeze(script, data):
"""
Test freeze formating of list command
"""
script.pip(
'install', '-f', data.find_links, '--no-index', 'simple==1.0',
'simple2==3.0',
)
result = script.pip('list', '--format=freeze')
assert 'simple==1.0' in result.stdout, str(result)
assert 'simple2==3.0' in result.stdout, str(result)
def test_list_json(script, data):
"""
Test json formating of list command
"""
script.pip(
'install', '-f', data.find_links, '--no-index', 'simple==1.0',
'simple2==3.0',
)
assert WARN_NOCOL in result.stderr, str(result)
result = script.pip('list', '--format=json')
data = json.loads(result.stdout)
assert {'name': 'simple', 'version': '1.0'} in data
assert {'name': 'simple2', 'version': '3.0'} in data
......@@ -47,10 +47,10 @@ def test_simple_uninstall_distutils(script):
)
"""))
result = script.run('python', pkg_path / 'setup.py', 'install')
result = script.pip('list')
result = script.pip('list', '--format=legacy')
assert "distutils-install (0.1)" in result.stdout
script.pip('uninstall', 'distutils_install', '-y', expect_stderr=True)
result2 = script.pip('list')
result2 = script.pip('list', '--format=legacy')
assert "distutils-install (0.1)" not in result2.stdout
......@@ -173,10 +173,10 @@ def test_uninstall_entry_point(script):
)
"""))
result = script.pip('install', pkg_path)
result = script.pip('list')
result = script.pip('list', '--format=legacy')
assert "ep-install (0.1)" in result.stdout
script.pip('uninstall', 'ep_install', '-y')
result2 = script.pip('list')
result2 = script.pip('list', '--format=legacy')
assert "ep-install (0.1)" not in result2.stdout
......@@ -416,7 +416,7 @@ def test_uninstall_setuptools_develop_install(script, data):
expect_stderr=True, cwd=pkg_path)
script.run('python', 'setup.py', 'install',
expect_stderr=True, cwd=pkg_path)
list_result = script.pip('list')
list_result = script.pip('list', '--format=legacy')
assert "FSPkg (0.1.dev0, " in list_result.stdout
# Uninstall both develop and install
uninstall = script.pip('uninstall', 'FSPkg', '-y')
......@@ -426,5 +426,5 @@ def test_uninstall_setuptools_develop_install(script, data):
assert join(
script.site_packages, 'FSPkg.egg-link'
) in uninstall2.files_deleted, list(uninstall2.files_deleted.keys())
list_result2 = script.pip('list')
list_result2 = script.pip('list', '--format=legacy')
assert "FSPkg" not in list_result2.stdout
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册