Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
keewenaw
GitHub Repository: keewenaw/ethereum-wallet-cracker
Path: blob/main/test/lib/python3.9/site-packages/pip/_internal/commands/freeze.py
4804 views
1
import sys
2
from optparse import Values
3
from typing import List
4
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
10
11
DEV_PKGS = {"pip", "setuptools", "distribute", "wheel"}
12
13
14
class FreezeCommand(Command):
15
"""
16
Output installed packages in requirements format.
17
18
packages are listed in a case-insensitive sorted order.
19
"""
20
21
usage = """
22
%prog [options]"""
23
log_streams = ("ext://sys.stderr", "ext://sys.stderr")
24
25
def add_options(self) -> None:
26
self.cmd_opts.add_option(
27
"-r",
28
"--requirement",
29
dest="requirements",
30
action="append",
31
default=[],
32
metavar="file",
33
help=(
34
"Use the order in the given requirements file and its "
35
"comments when generating output. This option can be "
36
"used multiple times."
37
),
38
)
39
self.cmd_opts.add_option(
40
"-l",
41
"--local",
42
dest="local",
43
action="store_true",
44
default=False,
45
help=(
46
"If in a virtualenv that has global access, do not output "
47
"globally-installed packages."
48
),
49
)
50
self.cmd_opts.add_option(
51
"--user",
52
dest="user",
53
action="store_true",
54
default=False,
55
help="Only output packages installed in user-site.",
56
)
57
self.cmd_opts.add_option(cmdoptions.list_path())
58
self.cmd_opts.add_option(
59
"--all",
60
dest="freeze_all",
61
action="store_true",
62
help=(
63
"Do not skip these packages in the output:"
64
" {}".format(", ".join(DEV_PKGS))
65
),
66
)
67
self.cmd_opts.add_option(
68
"--exclude-editable",
69
dest="exclude_editable",
70
action="store_true",
71
help="Exclude editable package from output.",
72
)
73
self.cmd_opts.add_option(cmdoptions.list_exclude())
74
75
self.parser.insert_option_group(0, self.cmd_opts)
76
77
def run(self, options: Values, args: List[str]) -> int:
78
skip = set(stdlib_pkgs)
79
if not options.freeze_all:
80
skip.update(DEV_PKGS)
81
82
if options.excludes:
83
skip.update(options.excludes)
84
85
cmdoptions.check_list_path_option(options)
86
87
for line in freeze(
88
requirement=options.requirements,
89
local_only=options.local,
90
user_only=options.user,
91
paths=options.path,
92
isolated=options.isolated_mode,
93
skip=skip,
94
exclude_editable=options.exclude_editable,
95
):
96
sys.stdout.write(line + "\n")
97
return SUCCESS
98
99