Path: blob/master/venv/Lib/site-packages/pip/_internal/commands/freeze.py
811 views
# The following comment should be removed at some point in the future.1# mypy: disallow-untyped-defs=False23from __future__ import absolute_import45import sys67from pip._internal.cache import WheelCache8from pip._internal.cli import cmdoptions9from pip._internal.cli.base_command import Command10from pip._internal.models.format_control import FormatControl11from pip._internal.operations.freeze import freeze12from pip._internal.utils.compat import stdlib_pkgs1314DEV_PKGS = {'pip', 'setuptools', 'distribute', 'wheel'}151617class FreezeCommand(Command):18"""19Output installed packages in requirements format.2021packages are listed in a case-insensitive sorted order.22"""2324usage = """25%prog [options]"""26log_streams = ("ext://sys.stderr", "ext://sys.stderr")2728def __init__(self, *args, **kw):29super(FreezeCommand, self).__init__(*args, **kw)3031self.cmd_opts.add_option(32'-r', '--requirement',33dest='requirements',34action='append',35default=[],36metavar='file',37help="Use the order in the given requirements file and its "38"comments when generating output. This option can be "39"used multiple times.")40self.cmd_opts.add_option(41'-f', '--find-links',42dest='find_links',43action='append',44default=[],45metavar='URL',46help='URL for finding packages, which will be added to the '47'output.')48self.cmd_opts.add_option(49'-l', '--local',50dest='local',51action='store_true',52default=False,53help='If in a virtualenv that has global access, do not output '54'globally-installed packages.')55self.cmd_opts.add_option(56'--user',57dest='user',58action='store_true',59default=False,60help='Only output packages installed in user-site.')61self.cmd_opts.add_option(cmdoptions.list_path())62self.cmd_opts.add_option(63'--all',64dest='freeze_all',65action='store_true',66help='Do not skip these packages in the output:'67' {}'.format(', '.join(DEV_PKGS)))68self.cmd_opts.add_option(69'--exclude-editable',70dest='exclude_editable',71action='store_true',72help='Exclude editable package from output.')7374self.parser.insert_option_group(0, self.cmd_opts)7576def run(self, options, args):77format_control = FormatControl(set(), set())78wheel_cache = WheelCache(options.cache_dir, format_control)79skip = set(stdlib_pkgs)80if not options.freeze_all:81skip.update(DEV_PKGS)8283cmdoptions.check_list_path_option(options)8485freeze_kwargs = dict(86requirement=options.requirements,87find_links=options.find_links,88local_only=options.local,89user_only=options.user,90paths=options.path,91isolated=options.isolated_mode,92wheel_cache=wheel_cache,93skip=skip,94exclude_editable=options.exclude_editable,95)9697for line in freeze(**freeze_kwargs):98sys.stdout.write(line + '\n')99100101