提交 2956a3ef 编写于 作者: X Xavier Fernandez

Add --all option to pip freeze

In order to include pip/setuptools/wheel in the freeze output
Closes #1610
上级 ceb79a63
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
* Fix PipDeprecationWarning so that warnings can be turned off by * Fix PipDeprecationWarning so that warnings can be turned off by
``-W`` / ``PYTHONWARNINGS`` (:pull:`3455`) ``-W`` / ``PYTHONWARNINGS`` (:pull:`3455`)
* Add a `--all` option to `pip freeze` to include usually skipped package
(like pip, setuptools and wheel) to the freeze output. :issue:`1610`.
**8.0.2 (2016-01-21)** **8.0.2 (2016-01-21)**
......
...@@ -3,11 +3,15 @@ from __future__ import absolute_import ...@@ -3,11 +3,15 @@ from __future__ import absolute_import
import sys import sys
import pip import pip
from pip.compat import stdlib_pkgs
from pip.basecommand import Command from pip.basecommand import Command
from pip.operations.freeze import freeze from pip.operations.freeze import freeze
from pip.wheel import WheelCache from pip.wheel import WheelCache
DEV_PKGS = ('pip', 'setuptools', 'distribute', 'wheel')
class FreezeCommand(Command): class FreezeCommand(Command):
""" """
Output installed packages in requirements format. Output installed packages in requirements format.
...@@ -52,12 +56,22 @@ class FreezeCommand(Command): ...@@ -52,12 +56,22 @@ class FreezeCommand(Command):
action='store_true', action='store_true',
default=False, default=False,
help='Only output packages installed in user-site.') help='Only output packages installed in user-site.')
self.cmd_opts.add_option(
'--all',
dest='freeze_all',
action='store_true',
help='Do not skip these packages in the output:'
' %s' % ', '.join(DEV_PKGS))
self.parser.insert_option_group(0, self.cmd_opts) self.parser.insert_option_group(0, self.cmd_opts)
def run(self, options, args): def run(self, options, args):
format_control = pip.index.FormatControl(set(), set()) format_control = pip.index.FormatControl(set(), set())
wheel_cache = WheelCache(options.cache_dir, format_control) wheel_cache = WheelCache(options.cache_dir, format_control)
skip = set(stdlib_pkgs)
if not options.freeze_all:
skip.update(DEV_PKGS)
freeze_kwargs = dict( freeze_kwargs = dict(
requirement=options.requirement, requirement=options.requirement,
find_links=options.find_links, find_links=options.find_links,
...@@ -65,7 +79,8 @@ class FreezeCommand(Command): ...@@ -65,7 +79,8 @@ class FreezeCommand(Command):
user_only=options.user, user_only=options.user,
skip_regex=options.skip_requirements_regex, skip_regex=options.skip_requirements_regex,
isolated=options.isolated_mode, isolated=options.isolated_mode,
wheel_cache=wheel_cache) wheel_cache=wheel_cache,
skip=skip)
for line in freeze(**freeze_kwargs): for line in freeze(**freeze_kwargs):
sys.stdout.write(line + '\n') sys.stdout.write(line + '\n')
...@@ -4,23 +4,21 @@ import logging ...@@ -4,23 +4,21 @@ import logging
import re import re
import pip import pip
from pip.compat import stdlib_pkgs
from pip.req import InstallRequirement from pip.req import InstallRequirement
from pip.utils import get_installed_distributions from pip.utils import canonicalize_name, get_installed_distributions
from pip._vendor import pkg_resources from pip._vendor import pkg_resources
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
freeze_excludes = stdlib_pkgs + ('setuptools', 'pip', 'distribute', 'wheel')
def freeze( def freeze(
requirement=None, requirement=None,
find_links=None, local_only=None, user_only=None, skip_regex=None, find_links=None, local_only=None, user_only=None, skip_regex=None,
default_vcs=None, default_vcs=None,
isolated=False, isolated=False,
wheel_cache=None): wheel_cache=None,
skip=()):
find_links = find_links or [] find_links = find_links or []
skip_match = None skip_match = None
...@@ -41,7 +39,7 @@ def freeze( ...@@ -41,7 +39,7 @@ def freeze(
yield '-f %s' % link yield '-f %s' % link
installations = {} installations = {}
for dist in get_installed_distributions(local_only=local_only, for dist in get_installed_distributions(local_only=local_only,
skip=freeze_excludes, skip=(),
user_only=user_only): user_only=user_only):
req = pip.FrozenRequirement.from_dist( req = pip.FrozenRequirement.from_dist(
dist, dist,
...@@ -111,4 +109,5 @@ def freeze( ...@@ -111,4 +109,5 @@ def freeze(
) )
for installation in sorted( for installation in sorted(
installations.values(), key=lambda x: x.name.lower()): installations.values(), key=lambda x: x.name.lower()):
if canonicalize_name(installation.name) not in skip:
yield str(installation).rstrip() yield str(installation).rstrip()
...@@ -63,6 +63,12 @@ def test_freeze_basic(script): ...@@ -63,6 +63,12 @@ def test_freeze_basic(script):
_check_output(result.stdout, expected) _check_output(result.stdout, expected)
def test_freeze_with_pip(script):
"""Test pip shows itself"""
result = script.pip('freeze', '--all')
assert 'pip==' in result.stdout
@pytest.mark.svn @pytest.mark.svn
def test_freeze_svn(script, tmpdir): def test_freeze_svn(script, tmpdir):
"""Test freezing a svn checkout""" """Test freezing a svn checkout"""
......
...@@ -16,7 +16,6 @@ from pip.exceptions import HashMismatch, HashMissing, InstallationError ...@@ -16,7 +16,6 @@ from pip.exceptions import HashMismatch, HashMissing, InstallationError
from pip.utils import (egg_link_path, get_installed_distributions, from pip.utils import (egg_link_path, get_installed_distributions,
untar_file, unzip_file, rmtree, normalize_path) untar_file, unzip_file, rmtree, normalize_path)
from pip.utils.hashes import Hashes, MissingHashes from pip.utils.hashes import Hashes, MissingHashes
from pip.operations.freeze import freeze_excludes
from pip._vendor.six import BytesIO from pip._vendor.six import BytesIO
...@@ -261,7 +260,8 @@ class Tests_get_installed_distributions: ...@@ -261,7 +260,8 @@ class Tests_get_installed_distributions:
mock_dist_is_editable.side_effect = self.dist_is_editable mock_dist_is_editable.side_effect = self.dist_is_editable
mock_dist_is_local.side_effect = self.dist_is_local mock_dist_is_local.side_effect = self.dist_is_local
mock_dist_in_usersite.side_effect = self.dist_in_usersite mock_dist_in_usersite.side_effect = self.dist_in_usersite
dists = get_installed_distributions(skip=freeze_excludes) dists = get_installed_distributions(
skip=('setuptools', 'pip', 'distribute'))
assert len(dists) == 0 assert len(dists) == 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册