Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/pip/operations/freeze.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 from __future__ import absolute_import | |
2 | |
3 import logging | |
4 import re | |
5 | |
6 import pip | |
7 from pip.compat import stdlib_pkgs | |
8 from pip.req import InstallRequirement | |
9 from pip.utils import get_installed_distributions | |
10 from pip._vendor import pkg_resources | |
11 | |
12 | |
13 logger = logging.getLogger(__name__) | |
14 | |
15 # packages to exclude from freeze output | |
16 freeze_excludes = stdlib_pkgs + ['setuptools', 'pip', 'distribute'] | |
17 | |
18 | |
19 def freeze( | |
20 requirement=None, | |
21 find_links=None, local_only=None, user_only=None, skip_regex=None, | |
22 find_tags=False, | |
23 default_vcs=None, | |
24 isolated=False): | |
25 find_links = find_links or [] | |
26 skip_match = None | |
27 | |
28 if skip_regex: | |
29 skip_match = re.compile(skip_regex) | |
30 | |
31 dependency_links = [] | |
32 | |
33 for dist in pkg_resources.working_set: | |
34 if dist.has_metadata('dependency_links.txt'): | |
35 dependency_links.extend( | |
36 dist.get_metadata_lines('dependency_links.txt') | |
37 ) | |
38 for link in find_links: | |
39 if '#egg=' in link: | |
40 dependency_links.append(link) | |
41 for link in find_links: | |
42 yield '-f %s' % link | |
43 installations = {} | |
44 for dist in get_installed_distributions(local_only=local_only, | |
45 skip=freeze_excludes, | |
46 user_only=user_only): | |
47 req = pip.FrozenRequirement.from_dist( | |
48 dist, | |
49 dependency_links, | |
50 find_tags=find_tags, | |
51 ) | |
52 installations[req.name] = req | |
53 | |
54 if requirement: | |
55 with open(requirement) as req_file: | |
56 for line in req_file: | |
57 if (not line.strip() or | |
58 line.strip().startswith('#') or | |
59 (skip_match and skip_match.search(line)) or | |
60 line.startswith(( | |
61 '-r', '--requirement', | |
62 '-Z', '--always-unzip', | |
63 '-f', '--find-links', | |
64 '-i', '--index-url', | |
65 '--extra-index-url'))): | |
66 yield line.rstrip() | |
67 continue | |
68 | |
69 if line.startswith('-e') or line.startswith('--editable'): | |
70 if line.startswith('-e'): | |
71 line = line[2:].strip() | |
72 else: | |
73 line = line[len('--editable'):].strip().lstrip('=') | |
74 line_req = InstallRequirement.from_editable( | |
75 line, | |
76 default_vcs=default_vcs, | |
77 isolated=isolated, | |
78 ) | |
79 else: | |
80 line_req = InstallRequirement.from_line( | |
81 line, | |
82 isolated=isolated, | |
83 ) | |
84 | |
85 if not line_req.name: | |
86 logger.info( | |
87 "Skipping line because it's not clear what it " | |
88 "would install: %s", | |
89 line.strip(), | |
90 ) | |
91 logger.info( | |
92 " (add #egg=PackageName to the URL to avoid" | |
93 " this warning)" | |
94 ) | |
95 elif line_req.name not in installations: | |
96 logger.warning( | |
97 "Requirement file contains %s, but that package is" | |
98 " not installed", | |
99 line.strip(), | |
100 ) | |
101 else: | |
102 yield str(installations[line_req.name]).rstrip() | |
103 del installations[line_req.name] | |
104 | |
105 yield( | |
106 '## The following requirements were added by ' | |
107 'pip freeze:' | |
108 ) | |
109 for installation in sorted( | |
110 installations.values(), key=lambda x: x.name.lower()): | |
111 yield str(installation).rstrip() |