Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(58)

Side by Side Diff: Lib/packaging/database.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/packaging/command/upload.py ('k') | Lib/packaging/install.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """PEP 376 implementation.""" 1 """PEP 376 implementation."""
2 2
3 import io 3 import io
4 import os 4 import os
5 import re 5 import re
6 import csv 6 import csv
7 import sys 7 import sys
8 import zipimport 8 import zipimport
9 from hashlib import md5 9 from hashlib import md5
10 from packaging import logger 10 from packaging import logger
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 Note that this function will not clear the cache in any case, for that 54 Note that this function will not clear the cache in any case, for that
55 functionality see :func:`clear_cache`. 55 functionality see :func:`clear_cache`.
56 """ 56 """
57 global _cache_enabled 57 global _cache_enabled
58 58
59 _cache_enabled = False 59 _cache_enabled = False
60 60
61 61
62 def clear_cache(): 62 def clear_cache():
63 """ Clears the internal cache. """ 63 """ Clears the internal cache. """
64 global _cache_generated, _cache_generated_egg 64 global _cache_name, _cache_name_egg, _cache_path, _cache_path_egg, \
65 _cache_generated, _cache_generated_egg
65 66
66 _cache_name.clear() 67 _cache_name = {}
67 _cache_name_egg.clear() 68 _cache_name_egg = {}
68 _cache_path.clear() 69 _cache_path = {}
69 _cache_path_egg.clear() 70 _cache_path_egg = {}
70 _cache_generated = False 71 _cache_generated = False
71 _cache_generated_egg = False 72 _cache_generated_egg = False
72 73
73 74
74 def _yield_distributions(include_dist, include_egg, paths): 75 def _yield_distributions(include_dist, include_egg, paths):
75 """ 76 """
76 Yield .dist-info and .egg(-info) distributions, based on the arguments 77 Yield .dist-info and .egg(-info) distributions, based on the arguments
77 78
78 :parameter include_dist: yield .dist-info distributions 79 :parameter include_dist: yield .dist-info distributions
79 :parameter include_egg: yield .egg(-info) distributions 80 :parameter include_egg: yield .egg(-info) distributions
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 self.path = path 151 self.path = path
151 152
152 if _cache_enabled and path not in _cache_path: 153 if _cache_enabled and path not in _cache_path:
153 _cache_path[path] = self 154 _cache_path[path] = self
154 155
155 def __repr__(self): 156 def __repr__(self):
156 return '<Distribution %r %s at %r>' % ( 157 return '<Distribution %r %s at %r>' % (
157 self.name, self.version, self.path) 158 self.name, self.version, self.path)
158 159
159 def _get_records(self, local=False): 160 def _get_records(self, local=False):
160 results = []
161 with self.get_distinfo_file('RECORD') as record: 161 with self.get_distinfo_file('RECORD') as record:
162 record_reader = csv.reader(record, delimiter=',', 162 record_reader = csv.reader(record, delimiter=',',
163 lineterminator='\n') 163 lineterminator='\n')
164 # XXX needs an explaining comment
164 for row in record_reader: 165 for row in record_reader:
165 missing = [None for i in range(len(row), 3)] 166 path, checksum, size = (row[:] +
166 path, checksum, size = row + missing 167 [None for i in range(len(row), 3)])
167 if local: 168 if local:
168 path = path.replace('/', os.sep) 169 path = path.replace('/', os.sep)
169 path = os.path.join(sys.prefix, path) 170 path = os.path.join(sys.prefix, path)
170 results.append((path, checksum, size)) 171 yield path, checksum, size
171 return results
172 172
173 def get_resource_path(self, relative_path): 173 def get_resource_path(self, relative_path):
174 with self.get_distinfo_file('RESOURCES') as resources_file: 174 with self.get_distinfo_file('RESOURCES') as resources_file:
175 resources_reader = csv.reader(resources_file, delimiter=',', 175 resources_reader = csv.reader(resources_file, delimiter=',',
176 lineterminator='\n') 176 lineterminator='\n')
177 for relative, destination in resources_reader: 177 for relative, destination in resources_reader:
178 if relative == relative_path: 178 if relative == relative_path:
179 return destination 179 return destination
180 raise KeyError( 180 raise KeyError(
181 'no resource file with relative path %r is installed' % 181 'no resource file with relative path %r is installed' %
182 relative_path) 182 relative_path)
183 183
184 def list_installed_files(self, local=False): 184 def list_installed_files(self, local=False):
185 """ 185 """
186 Iterates over the ``RECORD`` entries and returns a tuple 186 Iterates over the ``RECORD`` entries and returns a tuple
187 ``(path, md5, size)`` for each line. If *local* is ``True``, 187 ``(path, md5, size)`` for each line. If *local* is ``True``,
188 the returned path is transformed into a local absolute path. 188 the returned path is transformed into a local absolute path.
189 Otherwise the raw value from RECORD is returned. 189 Otherwise the raw value from RECORD is returned.
190 190
191 A local absolute path is an absolute path in which occurrences of 191 A local absolute path is an absolute path in which occurrences of
192 ``'/'`` have been replaced by the system separator given by ``os.sep``. 192 ``'/'`` have been replaced by the system separator given by ``os.sep``.
193 193
194 :parameter local: flag to say if the path should be returned a local 194 :parameter local: flag to say if the path should be returned a local
195 absolute path 195 absolute path
196 196
197 :type local: boolean 197 :type local: boolean
198 :returns: iterator of (path, md5, size) 198 :returns: iterator of (path, md5, size)
199 """ 199 """
200 for result in self._get_records(local): 200 return self._get_records(local)
201 yield result
202 201
203 def uses(self, path): 202 def uses(self, path):
204 """ 203 """
205 Returns ``True`` if path is listed in ``RECORD``. *path* can be a local 204 Returns ``True`` if path is listed in ``RECORD``. *path* can be a local
206 absolute path or a relative ``'/'``-separated path. 205 absolute path or a relative ``'/'``-separated path.
207 206
208 :rtype: boolean 207 :rtype: boolean
209 """ 208 """
210 for p, checksum, size in self._get_records(): 209 for p, checksum, size in self._get_records():
211 local_absolute = os.path.join(sys.prefix, p) 210 local_absolute = os.path.join(sys.prefix, p)
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 dist = get_distribution(distribution_name) 637 dist = get_distribution(distribution_name)
639 if dist is not None: 638 if dist is not None:
640 return dist.get_resource_path(relative_path) 639 return dist.get_resource_path(relative_path)
641 raise LookupError('no distribution named %r found' % distribution_name) 640 raise LookupError('no distribution named %r found' % distribution_name)
642 641
643 642
644 def get_file(distribution_name, relative_path, *args, **kwargs): 643 def get_file(distribution_name, relative_path, *args, **kwargs):
645 """Open and return a resource file.""" 644 """Open and return a resource file."""
646 return open(get_file_path(distribution_name, relative_path), 645 return open(get_file_path(distribution_name, relative_path),
647 *args, **kwargs) 646 *args, **kwargs)
OLDNEW
« no previous file with comments | « Lib/packaging/command/upload.py ('k') | Lib/packaging/install.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+