Path: blob/main/test/lib/python3.9/site-packages/pip/_internal/commands/freeze.py
4804 views
import sys1from optparse import Values2from typing import List34from pip._internal.cli import cmdoptions5from pip._internal.cli.base_command import Command6from pip._internal.cli.status_codes import SUCCESS7from pip._internal.operations.freeze import freeze8from pip._internal.utils.compat import stdlib_pkgs910DEV_PKGS = {"pip", "setuptools", "distribute", "wheel"}111213class FreezeCommand(Command):14"""15Output installed packages in requirements format.1617packages are listed in a case-insensitive sorted order.18"""1920usage = """21%prog [options]"""22log_streams = ("ext://sys.stderr", "ext://sys.stderr")2324def add_options(self) -> None:25self.cmd_opts.add_option(26"-r",27"--requirement",28dest="requirements",29action="append",30default=[],31metavar="file",32help=(33"Use the order in the given requirements file and its "34"comments when generating output. This option can be "35"used multiple times."36),37)38self.cmd_opts.add_option(39"-l",40"--local",41dest="local",42action="store_true",43default=False,44help=(45"If in a virtualenv that has global access, do not output "46"globally-installed packages."47),48)49self.cmd_opts.add_option(50"--user",51dest="user",52action="store_true",53default=False,54help="Only output packages installed in user-site.",55)56self.cmd_opts.add_option(cmdoptions.list_path())57self.cmd_opts.add_option(58"--all",59dest="freeze_all",60action="store_true",61help=(62"Do not skip these packages in the output:"63" {}".format(", ".join(DEV_PKGS))64),65)66self.cmd_opts.add_option(67"--exclude-editable",68dest="exclude_editable",69action="store_true",70help="Exclude editable package from output.",71)72self.cmd_opts.add_option(cmdoptions.list_exclude())7374self.parser.insert_option_group(0, self.cmd_opts)7576def run(self, options: Values, args: List[str]) -> int:77skip = set(stdlib_pkgs)78if not options.freeze_all:79skip.update(DEV_PKGS)8081if options.excludes:82skip.update(options.excludes)8384cmdoptions.check_list_path_option(options)8586for line in freeze(87requirement=options.requirements,88local_only=options.local,89user_only=options.user,90paths=options.path,91isolated=options.isolated_mode,92skip=skip,93exclude_editable=options.exclude_editable,94):95sys.stdout.write(line + "\n")96return SUCCESS979899