Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/pip/_internal/commands/uninstall.py
811 views
1
# The following comment should be removed at some point in the future.
2
# mypy: disallow-untyped-defs=False
3
4
from __future__ import absolute_import
5
6
from pip._vendor.packaging.utils import canonicalize_name
7
8
from pip._internal.cli.base_command import Command
9
from pip._internal.cli.req_command import SessionCommandMixin
10
from pip._internal.exceptions import InstallationError
11
from pip._internal.req import parse_requirements
12
from pip._internal.req.constructors import (
13
install_req_from_line,
14
install_req_from_parsed_requirement,
15
)
16
from pip._internal.utils.misc import protect_pip_from_modification_on_windows
17
18
19
class UninstallCommand(Command, SessionCommandMixin):
20
"""
21
Uninstall packages.
22
23
pip is able to uninstall most installed packages. Known exceptions are:
24
25
- Pure distutils packages installed with ``python setup.py install``, which
26
leave behind no metadata to determine what files were installed.
27
- Script wrappers installed by ``python setup.py develop``.
28
"""
29
30
usage = """
31
%prog [options] <package> ...
32
%prog [options] -r <requirements file> ..."""
33
34
def __init__(self, *args, **kw):
35
super(UninstallCommand, self).__init__(*args, **kw)
36
self.cmd_opts.add_option(
37
'-r', '--requirement',
38
dest='requirements',
39
action='append',
40
default=[],
41
metavar='file',
42
help='Uninstall all the packages listed in the given requirements '
43
'file. This option can be used multiple times.',
44
)
45
self.cmd_opts.add_option(
46
'-y', '--yes',
47
dest='yes',
48
action='store_true',
49
help="Don't ask for confirmation of uninstall deletions.")
50
51
self.parser.insert_option_group(0, self.cmd_opts)
52
53
def run(self, options, args):
54
session = self.get_default_session(options)
55
56
reqs_to_uninstall = {}
57
for name in args:
58
req = install_req_from_line(
59
name, isolated=options.isolated_mode,
60
)
61
if req.name:
62
reqs_to_uninstall[canonicalize_name(req.name)] = req
63
for filename in options.requirements:
64
for parsed_req in parse_requirements(
65
filename,
66
options=options,
67
session=session):
68
req = install_req_from_parsed_requirement(
69
parsed_req,
70
isolated=options.isolated_mode
71
)
72
if req.name:
73
reqs_to_uninstall[canonicalize_name(req.name)] = req
74
if not reqs_to_uninstall:
75
raise InstallationError(
76
'You must give at least one requirement to {self.name} (see '
77
'"pip help {self.name}")'.format(**locals())
78
)
79
80
protect_pip_from_modification_on_windows(
81
modifying_pip="pip" in reqs_to_uninstall
82
)
83
84
for req in reqs_to_uninstall.values():
85
uninstall_pathset = req.uninstall(
86
auto_confirm=options.yes, verbose=self.verbosity > 0,
87
)
88
if uninstall_pathset:
89
uninstall_pathset.commit()
90
91