2 from optparse
import Values
3 from typing
import AbstractSet
, List
5 from pip
._internal
.cli
import cmdoptions
6 from pip
._internal
.cli
.base_command
import Command
7 from pip
._internal
.cli
.status_codes
import SUCCESS
8 from pip
._internal
.operations
.freeze
import freeze
9 from pip
._internal
.utils
.compat
import stdlib_pkgs
12 def _should_suppress_build_backends() -> bool:
13 return sys
.version_info
< (3, 12)
16 def _dev_pkgs() -> AbstractSet
[str]:
19 if _should_suppress_build_backends():
20 pkgs |
= {"setuptools", "distribute", "wheel"}
25 class FreezeCommand(Command
):
27 Output installed packages in requirements format.
29 packages are listed in a case-insensitive sorted order.
34 log_streams
= ("ext://sys.stderr", "ext://sys.stderr")
36 def add_options(self
) -> None:
37 self
.cmd_opts
.add_option(
45 "Use the order in the given requirements file and its "
46 "comments when generating output. This option can be "
47 "used multiple times."
50 self
.cmd_opts
.add_option(
57 "If in a virtualenv that has global access, do not output "
58 "globally-installed packages."
61 self
.cmd_opts
.add_option(
66 help="Only output packages installed in user-site.",
68 self
.cmd_opts
.add_option(cmdoptions
.list_path())
69 self
.cmd_opts
.add_option(
74 "Do not skip these packages in the output:"
75 " {}".format(", ".join(_dev_pkgs()))
78 self
.cmd_opts
.add_option(
80 dest
="exclude_editable",
82 help="Exclude editable package from output.",
84 self
.cmd_opts
.add_option(cmdoptions
.list_exclude())
86 self
.parser
.insert_option_group(0, self
.cmd_opts
)
88 def run(self
, options
: Values
, args
: List
[str]) -> int:
89 skip
= set(stdlib_pkgs
)
90 if not options
.freeze_all
:
91 skip
.update(_dev_pkgs())
94 skip
.update(options
.excludes
)
96 cmdoptions
.check_list_path_option(options
)
99 requirement
=options
.requirements
,
100 local_only
=options
.local
,
101 user_only
=options
.user
,
103 isolated
=options
.isolated_mode
,
105 exclude_editable
=options
.exclude_editable
,
107 sys
.stdout
.write(line
+ "\n")