comparison env/lib/python3.9/site-packages/pip/_internal/commands/uninstall.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 from pip._vendor.packaging.utils import canonicalize_name
2
3 from pip._internal.cli.base_command import Command
4 from pip._internal.cli.req_command import SessionCommandMixin
5 from pip._internal.cli.status_codes import SUCCESS
6 from pip._internal.exceptions import InstallationError
7 from pip._internal.req import parse_requirements
8 from pip._internal.req.constructors import (
9 install_req_from_line,
10 install_req_from_parsed_requirement,
11 )
12 from pip._internal.utils.misc import protect_pip_from_modification_on_windows
13 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
14
15 if MYPY_CHECK_RUNNING:
16 from optparse import Values
17 from typing import List
18
19
20 class UninstallCommand(Command, SessionCommandMixin):
21 """
22 Uninstall packages.
23
24 pip is able to uninstall most installed packages. Known exceptions are:
25
26 - Pure distutils packages installed with ``python setup.py install``, which
27 leave behind no metadata to determine what files were installed.
28 - Script wrappers installed by ``python setup.py develop``.
29 """
30
31 usage = """
32 %prog [options] <package> ...
33 %prog [options] -r <requirements file> ..."""
34
35 def add_options(self):
36 # type: () -> None
37 self.cmd_opts.add_option(
38 '-r', '--requirement',
39 dest='requirements',
40 action='append',
41 default=[],
42 metavar='file',
43 help='Uninstall all the packages listed in the given requirements '
44 'file. This option can be used multiple times.',
45 )
46 self.cmd_opts.add_option(
47 '-y', '--yes',
48 dest='yes',
49 action='store_true',
50 help="Don't ask for confirmation of uninstall deletions.")
51
52 self.parser.insert_option_group(0, self.cmd_opts)
53
54 def run(self, options, args):
55 # type: (Values, List[str]) -> int
56 session = self.get_default_session(options)
57
58 reqs_to_uninstall = {}
59 for name in args:
60 req = install_req_from_line(
61 name, isolated=options.isolated_mode,
62 )
63 if req.name:
64 reqs_to_uninstall[canonicalize_name(req.name)] = req
65 for filename in options.requirements:
66 for parsed_req in parse_requirements(
67 filename,
68 options=options,
69 session=session):
70 req = install_req_from_parsed_requirement(
71 parsed_req,
72 isolated=options.isolated_mode
73 )
74 if req.name:
75 reqs_to_uninstall[canonicalize_name(req.name)] = req
76 if not reqs_to_uninstall:
77 raise InstallationError(
78 'You must give at least one requirement to {self.name} (see '
79 '"pip help {self.name}")'.format(**locals())
80 )
81
82 protect_pip_from_modification_on_windows(
83 modifying_pip="pip" in reqs_to_uninstall
84 )
85
86 for req in reqs_to_uninstall.values():
87 uninstall_pathset = req.uninstall(
88 auto_confirm=options.yes, verbose=self.verbosity > 0,
89 )
90 if uninstall_pathset:
91 uninstall_pathset.commit()
92
93 return SUCCESS