diff options
author | Shubham Saini <shubham6405@gmail.com> | 2019-08-05 08:32:33 +0000 |
---|---|---|
committer | Shubham Saini <shubham6405@gmail.com> | 2019-08-05 08:32:33 +0000 |
commit | 227b2d30a8675b44918f9d9ca89b24144a938215 (patch) | |
tree | 9f8e6a28724514b6fdf463a9ab2067a7ef309b72 /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/list.py | |
parent | 842a8cfbbbdb1f92889d892e4859dbd5d40c5be8 (diff) |
removing venv files
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/list.py')
-rw-r--r-- | venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/list.py | 343 |
1 files changed, 0 insertions, 343 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/list.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/list.py deleted file mode 100644 index 1b46c6f..0000000 --- a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/list.py +++ /dev/null | |||
@@ -1,343 +0,0 @@ | |||
1 | from __future__ import absolute_import | ||
2 | |||
3 | import json | ||
4 | import logging | ||
5 | import warnings | ||
6 | |||
7 | from pip._vendor import six | ||
8 | from pip._vendor.six.moves import zip_longest | ||
9 | |||
10 | from pip._internal.basecommand import Command | ||
11 | from pip._internal.cmdoptions import index_group, make_option_group | ||
12 | from pip._internal.exceptions import CommandError | ||
13 | from pip._internal.index import PackageFinder | ||
14 | from pip._internal.utils.deprecation import RemovedInPip11Warning | ||
15 | from pip._internal.utils.misc import ( | ||
16 | dist_is_editable, get_installed_distributions, | ||
17 | ) | ||
18 | from pip._internal.utils.packaging import get_installer | ||
19 | |||
20 | logger = logging.getLogger(__name__) | ||
21 | |||
22 | |||
23 | class ListCommand(Command): | ||
24 | """ | ||
25 | List installed packages, including editables. | ||
26 | |||
27 | Packages are listed in a case-insensitive sorted order. | ||
28 | """ | ||
29 | name = 'list' | ||
30 | usage = """ | ||
31 | %prog [options]""" | ||
32 | summary = 'List installed packages.' | ||
33 | |||
34 | def __init__(self, *args, **kw): | ||
35 | super(ListCommand, self).__init__(*args, **kw) | ||
36 | |||
37 | cmd_opts = self.cmd_opts | ||
38 | |||
39 | cmd_opts.add_option( | ||
40 | '-o', '--outdated', | ||
41 | action='store_true', | ||
42 | default=False, | ||
43 | help='List outdated packages') | ||
44 | cmd_opts.add_option( | ||
45 | '-u', '--uptodate', | ||
46 | action='store_true', | ||
47 | default=False, | ||
48 | help='List uptodate packages') | ||
49 | cmd_opts.add_option( | ||
50 | '-e', '--editable', | ||
51 | action='store_true', | ||
52 | default=False, | ||
53 | help='List editable projects.') | ||
54 | cmd_opts.add_option( | ||
55 | '-l', '--local', | ||
56 | action='store_true', | ||
57 | default=False, | ||
58 | help=('If in a virtualenv that has global access, do not list ' | ||
59 | 'globally-installed packages.'), | ||
60 | ) | ||
61 | self.cmd_opts.add_option( | ||
62 | '--user', | ||
63 | dest='user', | ||
64 | action='store_true', | ||
65 | default=False, | ||
66 | help='Only output packages installed in user-site.') | ||
67 | |||
68 | cmd_opts.add_option( | ||
69 | '--pre', | ||
70 | action='store_true', | ||
71 | default=False, | ||
72 | help=("Include pre-release and development versions. By default, " | ||
73 | "pip only finds stable versions."), | ||
74 | ) | ||
75 | |||
76 | cmd_opts.add_option( | ||
77 | '--format', | ||
78 | action='store', | ||
79 | dest='list_format', | ||
80 | default="columns", | ||
81 | choices=('legacy', 'columns', 'freeze', 'json'), | ||
82 | help="Select the output format among: columns (default), freeze, " | ||
83 | "json, or legacy.", | ||
84 | ) | ||
85 | |||
86 | cmd_opts.add_option( | ||
87 | '--not-required', | ||
88 | action='store_true', | ||
89 | dest='not_required', | ||
90 | help="List packages that are not dependencies of " | ||
91 | "installed packages.", | ||
92 | ) | ||
93 | |||
94 | cmd_opts.add_option( | ||
95 | '--exclude-editable', | ||
96 | action='store_false', | ||
97 | dest='include_editable', | ||
98 | help='Exclude editable package from output.', | ||
99 | ) | ||
100 | cmd_opts.add_option( | ||
101 | '--include-editable', | ||
102 | action='store_true', | ||
103 | dest='include_editable', | ||
104 | help='Include editable package from output.', | ||
105 | default=True, | ||
106 | ) | ||
107 | index_opts = make_option_group(index_group, self.parser) | ||
108 | |||
109 | self.parser.insert_option_group(0, index_opts) | ||
110 | self.parser.insert_option_group(0, cmd_opts) | ||
111 | |||
112 | def _build_package_finder(self, options, index_urls, session): | ||
113 | """ | ||
114 | Create a package finder appropriate to this list command. | ||
115 | """ | ||
116 | return PackageFinder( | ||
117 | find_links=options.find_links, | ||
118 | index_urls=index_urls, | ||
119 | allow_all_prereleases=options.pre, | ||
120 | trusted_hosts=options.trusted_hosts, | ||
121 | process_dependency_links=options.process_dependency_links, | ||
122 | session=session, | ||
123 | ) | ||
124 | |||
125 | def run(self, options, args): | ||
126 | if options.list_format == "legacy": | ||
127 | warnings.warn( | ||
128 | "The legacy format has been deprecated and will be removed " | ||
129 | "in the future.", | ||
130 | RemovedInPip11Warning, | ||
131 | ) | ||
132 | |||
133 | if options.outdated and options.uptodate: | ||
134 | raise CommandError( | ||
135 | "Options --outdated and --uptodate cannot be combined.") | ||
136 | |||
137 | packages = get_installed_distributions( | ||
138 | local_only=options.local, | ||
139 | user_only=options.user, | ||
140 | editables_only=options.editable, | ||
141 | include_editables=options.include_editable, | ||
142 | ) | ||
143 | |||
144 | if options.outdated: | ||
145 | packages = self.get_outdated(packages, options) | ||
146 | elif options.uptodate: | ||
147 | packages = self.get_uptodate(packages, options) | ||
148 | |||
149 | if options.not_required: | ||
150 | packages = self.get_not_required(packages, options) | ||
151 | |||
152 | self.output_package_listing(packages, options) | ||
153 | |||
154 | def get_outdated(self, packages, options): | ||
155 | return [ | ||
156 | dist for dist in self.iter_packages_latest_infos(packages, options) | ||
157 | if dist.latest_version > dist.parsed_version | ||
158 | ] | ||
159 | |||
160 | def get_uptodate(self, packages, options): | ||
161 | return [ | ||
162 | dist for dist in self.iter_packages_latest_infos(packages, options) | ||
163 | if dist.latest_version == dist.parsed_version | ||
164 | ] | ||
165 | |||
166 | def get_not_required(self, packages, options): | ||
167 | dep_keys = set() | ||
168 | for dist in packages: | ||
169 | dep_keys.update(requirement.key for requirement in dist.requires()) | ||
170 | return {pkg for pkg in packages if pkg.key not in dep_keys} | ||
171 | |||
172 | def iter_packages_latest_infos(self, packages, options): | ||
173 | index_urls = [options.index_url] + options.extra_index_urls | ||
174 | if options.no_index: | ||
175 | logger.debug('Ignoring indexes: %s', ','.join(index_urls)) | ||
176 | index_urls = [] | ||
177 | |||
178 | dependency_links = [] | ||
179 | for dist in packages: | ||
180 | if dist.has_metadata('dependency_links.txt'): | ||
181 | dependency_links.extend( | ||
182 | dist.get_metadata_lines('dependency_links.txt'), | ||
183 | ) | ||
184 | |||
185 | with self._build_session(options) as session: | ||
186 | finder = self._build_package_finder(options, index_urls, session) | ||
187 | finder.add_dependency_links(dependency_links) | ||
188 | |||
189 | for dist in packages: | ||
190 | typ = 'unknown' | ||
191 | all_candidates = finder.find_all_candidates(dist.key) | ||
192 | if not options.pre: | ||
193 | # Remove prereleases | ||
194 | all_candidates = [candidate for candidate in all_candidates | ||
195 | if not candidate.version.is_prerelease] | ||
196 | |||
197 | if not all_candidates: | ||
198 | continue | ||
199 | best_candidate = max(all_candidates, | ||
200 | key=finder._candidate_sort_key) | ||
201 | remote_version = best_candidate.version | ||
202 | if best_candidate.location.is_wheel: | ||
203 | typ = 'wheel' | ||
204 | else: | ||
205 | typ = 'sdist' | ||
206 | # This is dirty but makes the rest of the code much cleaner | ||
207 | dist.latest_version = remote_version | ||
208 | dist.latest_filetype = typ | ||
209 | yield dist | ||
210 | |||
211 | def output_legacy(self, dist, options): | ||
212 | if options.verbose >= 1: | ||
213 | return '%s (%s, %s, %s)' % ( | ||
214 | dist.project_name, | ||
215 | dist.version, | ||
216 | dist.location, | ||
217 | get_installer(dist), | ||
218 | ) | ||
219 | elif dist_is_editable(dist): | ||
220 | return '%s (%s, %s)' % ( | ||
221 | dist.project_name, | ||
222 | dist.version, | ||
223 | dist.location, | ||
224 | ) | ||
225 | else: | ||
226 | return '%s (%s)' % (dist.project_name, dist.version) | ||
227 | |||
228 | def output_legacy_latest(self, dist, options): | ||
229 | return '%s - Latest: %s [%s]' % ( | ||
230 | self.output_legacy(dist, options), | ||
231 | dist.latest_version, | ||
232 | dist.latest_filetype, | ||
233 | ) | ||
234 | |||
235 | def output_package_listing(self, packages, options): | ||
236 | packages = sorted( | ||
237 | packages, | ||
238 | key=lambda dist: dist.project_name.lower(), | ||
239 | ) | ||
240 | if options.list_format == 'columns' and packages: | ||
241 | data, header = format_for_columns(packages, options) | ||
242 | self.output_package_listing_columns(data, header) | ||
243 | elif options.list_format == 'freeze': | ||
244 | for dist in packages: | ||
245 | if options.verbose >= 1: | ||
246 | logger.info("%s==%s (%s)", dist.project_name, | ||
247 | dist.version, dist.location) | ||
248 | else: | ||
249 | logger.info("%s==%s", dist.project_name, dist.version) | ||
250 | elif options.list_format == 'json': | ||
251 | logger.info(format_for_json(packages, options)) | ||
252 | elif options.list_format == "legacy": | ||
253 | for dist in packages: | ||
254 | if options.outdated: | ||
255 | logger.info(self.output_legacy_latest(dist, options)) | ||
256 | else: | ||
257 | logger.info(self.output_legacy(dist, options)) | ||
258 | |||
259 | def output_package_listing_columns(self, data, header): | ||
260 | # insert the header first: we need to know the size of column names | ||
261 | if len(data) > 0: | ||
262 | data.insert(0, header) | ||
263 | |||
264 | pkg_strings, sizes = tabulate(data) | ||
265 | |||
266 | # Create and add a separator. | ||
267 | if len(data) > 0: | ||
268 | pkg_strings.insert(1, " ".join(map(lambda x: '-' * x, sizes))) | ||
269 | |||
270 | for val in pkg_strings: | ||
271 | logger.info(val) | ||
272 | |||
273 | |||
274 | def tabulate(vals): | ||
275 | # From pfmoore on GitHub: | ||
276 | # https://github.com/pypa/pip/issues/3651#issuecomment-216932564 | ||
277 | assert len(vals) > 0 | ||
278 | |||
279 | sizes = [0] * max(len(x) for x in vals) | ||
280 | for row in vals: | ||
281 | sizes = [max(s, len(str(c))) for s, c in zip_longest(sizes, row)] | ||
282 | |||
283 | result = [] | ||
284 | for row in vals: | ||
285 | display = " ".join([str(c).ljust(s) if c is not None else '' | ||
286 | for s, c in zip_longest(sizes, row)]) | ||
287 | result.append(display) | ||
288 | |||
289 | return result, sizes | ||
290 | |||
291 | |||
292 | def format_for_columns(pkgs, options): | ||
293 | """ | ||
294 | Convert the package data into something usable | ||
295 | by output_package_listing_columns. | ||
296 | """ | ||
297 | running_outdated = options.outdated | ||
298 | # Adjust the header for the `pip list --outdated` case. | ||
299 | if running_outdated: | ||
300 | header = ["Package", "Version", "Latest", "Type"] | ||
301 | else: | ||
302 | header = ["Package", "Version"] | ||
303 | |||
304 | data = [] | ||
305 | if options.verbose >= 1 or any(dist_is_editable(x) for x in pkgs): | ||
306 | header.append("Location") | ||
307 | if options.verbose >= 1: | ||
308 | header.append("Installer") | ||
309 | |||
310 | for proj in pkgs: | ||
311 | # if we're working on the 'outdated' list, separate out the | ||
312 | # latest_version and type | ||
313 | row = [proj.project_name, proj.version] | ||
314 | |||
315 | if running_outdated: | ||
316 | row.append(proj.latest_version) | ||
317 | row.append(proj.latest_filetype) | ||
318 | |||
319 | if options.verbose >= 1 or dist_is_editable(proj): | ||
320 | row.append(proj.location) | ||
321 | if options.verbose >= 1: | ||
322 | row.append(get_installer(proj)) | ||
323 | |||
324 | data.append(row) | ||
325 | |||
326 | return data, header | ||
327 | |||
328 | |||
329 | def format_for_json(packages, options): | ||
330 | data = [] | ||
331 | for dist in packages: | ||
332 | info = { | ||
333 | 'name': dist.project_name, | ||
334 | 'version': six.text_type(dist.version), | ||
335 | } | ||
336 | if options.verbose >= 1: | ||
337 | info['location'] = dist.location | ||
338 | info['installer'] = get_installer(dist) | ||
339 | if options.outdated: | ||
340 | info['latest_version'] = six.text_type(dist.latest_version) | ||
341 | info['latest_filetype'] = dist.latest_filetype | ||
342 | data.append(info) | ||
343 | return json.dumps(data) | ||