OSDN Git Service

PEP8対応
[stux/ultron.git] / venv / Lib / site-packages / pip / commands / uninstall.py
1 from __future__ import absolute_import
2
3 import pip
4 from pip.wheel import WheelCache
5 from pip.req import InstallRequirement, RequirementSet, parse_requirements
6 from pip.basecommand import Command
7 from pip.exceptions import InstallationError
8
9
10 class UninstallCommand(Command):
11     """
12     Uninstall packages.
13
14     pip is able to uninstall most installed packages. Known exceptions are:
15
16     - Pure distutils packages installed with ``python setup.py install``, which
17       leave behind no metadata to determine what files were installed.
18     - Script wrappers installed by ``python setup.py develop``.
19     """
20     name = 'uninstall'
21     usage = """
22       %prog [options] <package> ...
23       %prog [options] -r <requirements file> ..."""
24     summary = 'Uninstall packages.'
25
26     def __init__(self, *args, **kw):
27         super(UninstallCommand, self).__init__(*args, **kw)
28         self.cmd_opts.add_option(
29             '-r', '--requirement',
30             dest='requirements',
31             action='append',
32             default=[],
33             metavar='file',
34             help='Uninstall all the packages listed in the given requirements '
35                  'file.  This option can be used multiple times.',
36         )
37         self.cmd_opts.add_option(
38             '-y', '--yes',
39             dest='yes',
40             action='store_true',
41             help="Don't ask for confirmation of uninstall deletions.")
42
43         self.parser.insert_option_group(0, self.cmd_opts)
44
45     def run(self, options, args):
46         with self._build_session(options) as session:
47             format_control = pip.index.FormatControl(set(), set())
48             wheel_cache = WheelCache(options.cache_dir, format_control)
49             requirement_set = RequirementSet(
50                 build_dir=None,
51                 src_dir=None,
52                 download_dir=None,
53                 isolated=options.isolated_mode,
54                 session=session,
55                 wheel_cache=wheel_cache,
56             )
57             for name in args:
58                 requirement_set.add_requirement(
59                     InstallRequirement.from_line(
60                         name, isolated=options.isolated_mode,
61                         wheel_cache=wheel_cache
62                     )
63                 )
64             for filename in options.requirements:
65                 for req in parse_requirements(
66                         filename,
67                         options=options,
68                         session=session,
69                         wheel_cache=wheel_cache):
70                     requirement_set.add_requirement(req)
71             if not requirement_set.has_requirements:
72                 raise InstallationError(
73                     'You must give at least one requirement to %(name)s (see '
74                     '"pip help %(name)s")' % dict(name=self.name)
75                 )
76             requirement_set.uninstall(auto_confirm=options.yes)