Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/commands/uninstall.py @ 1:64071f2a4cf0 draft default tip
Deleted selected files
| author | guerler |
|---|---|
| date | Mon, 27 Jul 2020 03:55:49 -0400 |
| parents | 9e54283cc701 |
| children |
comparison
equal
deleted
inserted
replaced
| 0:9e54283cc701 | 1:64071f2a4cf0 |
|---|---|
| 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 install_req_from_line | |
| 13 from pip._internal.utils.misc import protect_pip_from_modification_on_windows | |
| 14 | |
| 15 | |
| 16 class UninstallCommand(Command, SessionCommandMixin): | |
| 17 """ | |
| 18 Uninstall packages. | |
| 19 | |
| 20 pip is able to uninstall most installed packages. Known exceptions are: | |
| 21 | |
| 22 - Pure distutils packages installed with ``python setup.py install``, which | |
| 23 leave behind no metadata to determine what files were installed. | |
| 24 - Script wrappers installed by ``python setup.py develop``. | |
| 25 """ | |
| 26 | |
| 27 usage = """ | |
| 28 %prog [options] <package> ... | |
| 29 %prog [options] -r <requirements file> ...""" | |
| 30 | |
| 31 def __init__(self, *args, **kw): | |
| 32 super(UninstallCommand, self).__init__(*args, **kw) | |
| 33 self.cmd_opts.add_option( | |
| 34 '-r', '--requirement', | |
| 35 dest='requirements', | |
| 36 action='append', | |
| 37 default=[], | |
| 38 metavar='file', | |
| 39 help='Uninstall all the packages listed in the given requirements ' | |
| 40 'file. This option can be used multiple times.', | |
| 41 ) | |
| 42 self.cmd_opts.add_option( | |
| 43 '-y', '--yes', | |
| 44 dest='yes', | |
| 45 action='store_true', | |
| 46 help="Don't ask for confirmation of uninstall deletions.") | |
| 47 | |
| 48 self.parser.insert_option_group(0, self.cmd_opts) | |
| 49 | |
| 50 def run(self, options, args): | |
| 51 session = self.get_default_session(options) | |
| 52 | |
| 53 reqs_to_uninstall = {} | |
| 54 for name in args: | |
| 55 req = install_req_from_line( | |
| 56 name, isolated=options.isolated_mode, | |
| 57 ) | |
| 58 if req.name: | |
| 59 reqs_to_uninstall[canonicalize_name(req.name)] = req | |
| 60 for filename in options.requirements: | |
| 61 for req in parse_requirements( | |
| 62 filename, | |
| 63 options=options, | |
| 64 session=session): | |
| 65 if req.name: | |
| 66 reqs_to_uninstall[canonicalize_name(req.name)] = req | |
| 67 if not reqs_to_uninstall: | |
| 68 raise InstallationError( | |
| 69 'You must give at least one requirement to %(name)s (see ' | |
| 70 '"pip help %(name)s")' % dict(name=self.name) | |
| 71 ) | |
| 72 | |
| 73 protect_pip_from_modification_on_windows( | |
| 74 modifying_pip="pip" in reqs_to_uninstall | |
| 75 ) | |
| 76 | |
| 77 for req in reqs_to_uninstall.values(): | |
| 78 uninstall_pathset = req.uninstall( | |
| 79 auto_confirm=options.yes, verbose=self.verbosity > 0, | |
| 80 ) | |
| 81 if uninstall_pathset: | |
| 82 uninstall_pathset.commit() |
