|
1 | 1 | from __future__ import absolute_import
|
2 | 2 |
|
3 |
| -import logging |
4 |
| -import re |
5 | 3 | import sys
|
6 | 4 |
|
7 |
| - |
8 |
| -import pip |
9 |
| - |
10 |
| -from pip.compat import stdlib_pkgs |
11 |
| -from pip.req import InstallRequirement |
12 | 5 | from pip.basecommand import Command
|
13 |
| -from pip.utils import get_installed_distributions |
14 |
| -from pip._vendor import pkg_resources |
15 |
| - |
16 |
| -# packages to exclude from freeze output |
17 |
| -freeze_excludes = stdlib_pkgs + ['setuptools', 'pip', 'distribute'] |
18 |
| - |
19 |
| - |
20 |
| -logger = logging.getLogger(__name__) |
| 6 | +from pip.operations.freeze import freeze |
21 | 7 |
|
22 | 8 |
|
23 | 9 | class FreezeCommand(Command):
|
@@ -68,98 +54,13 @@ def __init__(self, *args, **kw):
|
68 | 54 | self.parser.insert_option_group(0, self.cmd_opts)
|
69 | 55 |
|
70 | 56 | def run(self, options, args):
|
71 |
| - requirement = options.requirement |
72 |
| - find_links = options.find_links or [] |
73 |
| - local_only = options.local |
74 |
| - user_only = options.user |
75 |
| - # FIXME: Obviously this should be settable: |
76 |
| - find_tags = False |
77 |
| - skip_match = None |
78 |
| - |
79 |
| - skip_regex = options.skip_requirements_regex |
80 |
| - if skip_regex: |
81 |
| - skip_match = re.compile(skip_regex) |
82 |
| - |
83 |
| - dependency_links = [] |
84 |
| - |
85 |
| - f = sys.stdout |
86 |
| - |
87 |
| - for dist in pkg_resources.working_set: |
88 |
| - if dist.has_metadata('dependency_links.txt'): |
89 |
| - dependency_links.extend( |
90 |
| - dist.get_metadata_lines('dependency_links.txt') |
91 |
| - ) |
92 |
| - for link in find_links: |
93 |
| - if '#egg=' in link: |
94 |
| - dependency_links.append(link) |
95 |
| - for link in find_links: |
96 |
| - f.write('-f %s\n' % link) |
97 |
| - installations = {} |
98 |
| - for dist in get_installed_distributions(local_only=local_only, |
99 |
| - skip=freeze_excludes, |
100 |
| - user_only=user_only): |
101 |
| - req = pip.FrozenRequirement.from_dist( |
102 |
| - dist, |
103 |
| - dependency_links, |
104 |
| - find_tags=find_tags, |
105 |
| - ) |
106 |
| - installations[req.name] = req |
107 |
| - |
108 |
| - if requirement: |
109 |
| - with open(requirement) as req_file: |
110 |
| - for line in req_file: |
111 |
| - if (not line.strip() |
112 |
| - or line.strip().startswith('#') |
113 |
| - or (skip_match and skip_match.search(line)) |
114 |
| - or line.startswith(( |
115 |
| - '-r', '--requirement', |
116 |
| - '-Z', '--always-unzip', |
117 |
| - '-f', '--find-links', |
118 |
| - '-i', '--index-url', |
119 |
| - '--extra-index-url'))): |
120 |
| - f.write(line) |
121 |
| - continue |
122 |
| - |
123 |
| - if line.startswith('-e') or line.startswith('--editable'): |
124 |
| - if line.startswith('-e'): |
125 |
| - line = line[2:].strip() |
126 |
| - else: |
127 |
| - line = line[len('--editable'):].strip().lstrip('=') |
128 |
| - line_req = InstallRequirement.from_editable( |
129 |
| - line, |
130 |
| - default_vcs=options.default_vcs, |
131 |
| - isolated=options.isolated_mode, |
132 |
| - ) |
133 |
| - else: |
134 |
| - line_req = InstallRequirement.from_line( |
135 |
| - line, |
136 |
| - isolated=options.isolated_mode, |
137 |
| - ) |
138 |
| - |
139 |
| - if not line_req.name: |
140 |
| - logger.info( |
141 |
| - "Skipping line because it's not clear what it " |
142 |
| - "would install: %s", |
143 |
| - line.strip(), |
144 |
| - ) |
145 |
| - logger.info( |
146 |
| - " (add #egg=PackageName to the URL to avoid" |
147 |
| - " this warning)" |
148 |
| - ) |
149 |
| - elif line_req.name not in installations: |
150 |
| - logger.warning( |
151 |
| - "Requirement file contains %s, but that package is" |
152 |
| - " not installed", |
153 |
| - line.strip(), |
154 |
| - ) |
155 |
| - else: |
156 |
| - f.write(str(installations[line_req.name])) |
157 |
| - del installations[line_req.name] |
158 |
| - |
159 |
| - f.write( |
160 |
| - '## The following requirements were added by ' |
161 |
| - 'pip %(name)s:\n' % dict(name=self.name) |
162 |
| - ) |
163 |
| - for installation in sorted( |
164 |
| - installations.values(), key=lambda x: x.name.lower()): |
165 |
| - f.write(str(installation)) |
| 57 | + freeze_kwargs = dict( |
| 58 | + requirement=options.requirement, |
| 59 | + find_links=options.find_links, |
| 60 | + local_only=options.local, |
| 61 | + user_only=options.user, |
| 62 | + skip_regex=options.skip_requirements_regex, |
| 63 | + isolated=options.isolated_mode) |
| 64 | + |
| 65 | + for line in freeze(**freeze_kwargs): |
| 66 | + sys.stdout.write(line + '\n') |
0 commit comments