Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._vendor.distlib.metadata Namespace Reference

Data Structures

class  LegacyMetadata
 
class  Metadata
 
class  MetadataConflictError
 
class  MetadataInvalidError
 
class  MetadataMissingError
 
class  MetadataUnrecognizedVersionError
 

Functions

 _version2fieldlist (version)
 
 _best_version (fields)
 
 _get_name_and_version (name, version, for_filename=False)
 

Variables

 logger = logging.getLogger(__name__)
 
str PKG_INFO_ENCODING = 'utf-8'
 
str PKG_INFO_PREFERRED_VERSION = '1.1'
 
 _LINE_PREFIX_1_2 = re.compile('\n \\|')
 
 _LINE_PREFIX_PRE_1_2 = re.compile('\n ')
 
tuple _241_FIELDS
 
tuple _314_FIELDS
 
tuple _314_MARKERS
 
tuple _345_FIELDS
 
tuple _345_MARKERS
 
tuple _426_FIELDS
 
tuple _426_MARKERS
 
tuple _566_FIELDS
 
tuple _566_MARKERS = ('Description-Content-Type',)
 
tuple _643_MARKERS = ('Dynamic', 'License-File')
 
tuple _643_FIELDS = _566_FIELDS + _643_MARKERS
 
 _ALL_FIELDS = set()
 
 EXTRA_RE = re.compile()
 
dict _ATTR2FIELD
 
dict _FIELD2ATTR = {field: attr for attr, field in _ATTR2FIELD.items()}
 
tuple _PREDICATE_FIELDS = ('Requires-Dist', 'Obsoletes-Dist', 'Provides-Dist')
 
tuple _VERSIONS_FIELDS = ('Requires-Python',)
 
tuple _VERSION_FIELDS = ('Version',)
 
tuple _LISTFIELDS
 
tuple _LISTTUPLEFIELDS = ('Project-URL',)
 
tuple _ELEMENTSFIELD = ('Keywords',)
 
tuple _UNICODEFIELDS = ('Author', 'Maintainer', 'Summary', 'Description')
 
 _MISSING = object()
 
 _FILESAFE = re.compile('[^A-Za-z0-9.]+')
 
str METADATA_FILENAME = 'pydist.json'
 
str WHEEL_METADATA_FILENAME = 'metadata.json'
 
str LEGACY_METADATA_FILENAME = 'METADATA'
 

Detailed Description

Implementation of the Metadata for Python packages PEPs.

Supports all metadata formats (1.0, 1.1, 1.2, 1.3/2.1 and 2.2).

Function Documentation

◆ _best_version()

_best_version (   fields)
protected
Detect the best version depending on the fields used.

Definition at line 136 of file metadata.py.

136def _best_version(fields):
137 """Detect the best version depending on the fields used."""
138 def _has_marker(keys, markers):
139 for marker in markers:
140 if marker in keys:
141 return True
142 return False
143
144 keys = []
145 for key, value in fields.items():
146 if value in ([], 'UNKNOWN', None):
147 continue
148 keys.append(key)
149
150 possible_versions = ['1.0', '1.1', '1.2', '1.3', '2.1', '2.2'] # 2.0 removed
151
152 # first let's try to see if a field is not part of one of the version
153 for key in keys:
154 if key not in _241_FIELDS and '1.0' in possible_versions:
156 logger.debug('Removed 1.0 due to %s', key)
157 if key not in _314_FIELDS and '1.1' in possible_versions:
159 logger.debug('Removed 1.1 due to %s', key)
160 if key not in _345_FIELDS and '1.2' in possible_versions:
162 logger.debug('Removed 1.2 due to %s', key)
163 if key not in _566_FIELDS and '1.3' in possible_versions:
165 logger.debug('Removed 1.3 due to %s', key)
166 if key not in _566_FIELDS and '2.1' in possible_versions:
167 if key != 'Description': # In 2.1, description allowed after headers
169 logger.debug('Removed 2.1 due to %s', key)
170 if key not in _643_FIELDS and '2.2' in possible_versions:
172 logger.debug('Removed 2.2 due to %s', key)
173 # if key not in _426_FIELDS and '2.0' in possible_versions:
174 # possible_versions.remove('2.0')
175 # logger.debug('Removed 2.0 due to %s', key)
176
177 # possible_version contains qualified versions
178 if len(possible_versions) == 1:
179 return possible_versions[0] # found !
180 elif len(possible_versions) == 0:
181 logger.debug('Out of options - unknown metadata set: %s', fields)
182 raise MetadataConflictError('Unknown metadata set')
183
184 # let's see if one unique marker is found
185 is_1_1 = '1.1' in possible_versions and _has_marker(keys, _314_MARKERS)
186 is_1_2 = '1.2' in possible_versions and _has_marker(keys, _345_MARKERS)
187 is_2_1 = '2.1' in possible_versions and _has_marker(keys, _566_MARKERS)
188 # is_2_0 = '2.0' in possible_versions and _has_marker(keys, _426_MARKERS)
189 is_2_2 = '2.2' in possible_versions and _has_marker(keys, _643_MARKERS)
190 if int(is_1_1) + int(is_1_2) + int(is_2_1) + int(is_2_2) > 1:
191 raise MetadataConflictError('You used incompatible 1.1/1.2/2.1/2.2 fields')
192
193 # we have the choice, 1.0, or 1.2, 2.1 or 2.2
194 # - 1.0 has a broken Summary field but works with all tools
195 # - 1.1 is to avoid
196 # - 1.2 fixes Summary but has little adoption
197 # - 2.1 adds more features
198 # - 2.2 is the latest
199 if not is_1_1 and not is_1_2 and not is_2_1 and not is_2_2:
200 # we couldn't find any specific marker
201 if PKG_INFO_PREFERRED_VERSION in possible_versions:
202 return PKG_INFO_PREFERRED_VERSION
203 if is_1_1:
204 return '1.1'
205 if is_1_2:
206 return '1.2'
207 if is_2_1:
208 return '2.1'
209 # if is_2_2:
210 # return '2.2'
211
212 return '2.2'
213
214# This follows the rules about transforming keys as described in
215# https://www.python.org/dev/peps/pep-0566/#id17
for i

References i.

Referenced by LegacyMetadata.set_metadata_version().

Here is the caller graph for this function:

◆ _get_name_and_version()

_get_name_and_version (   name,
  version,
  for_filename = False 
)
protected
Return the distribution name with version.

If for_filename is true, return a filename-escaped form.

Definition at line 240 of file metadata.py.

240def _get_name_and_version(name, version, for_filename=False):
241 """Return the distribution name with version.
242
243 If for_filename is true, return a filename-escaped form."""
244 if for_filename:
245 # For both name and version any runs of non-alphanumeric or '.'
246 # characters are replaced with a single '-'. Additionally any
247 # spaces in the version string become '.'
248 name = _FILESAFE.sub('-', name)
249 version = _FILESAFE.sub('-', version.replace(' ', '.'))
250 return '%s-%s' % (name, version)
251
252

References i.

Referenced by LegacyMetadata.get_fullname().

Here is the caller graph for this function:

◆ _version2fieldlist()

_version2fieldlist (   version)
protected

Definition at line 118 of file metadata.py.

118def _version2fieldlist(version):
119 if version == '1.0':
120 return _241_FIELDS
121 elif version == '1.1':
122 return _314_FIELDS
123 elif version == '1.2':
124 return _345_FIELDS
125 elif version in ('1.3', '2.1'):
126 # avoid adding field names if already there
127 return _345_FIELDS + tuple(f for f in _566_FIELDS if f not in _345_FIELDS)
128 elif version == '2.0':
129 raise ValueError('Metadata 2.0 is withdrawn and not supported')
130 # return _426_FIELDS
131 elif version == '2.2':
132 return _643_FIELDS
133 raise MetadataUnrecognizedVersionError(version)
134
135

Referenced by LegacyMetadata.keys(), LegacyMetadata.todict(), and LegacyMetadata.write_file().

Here is the caller graph for this function:

Variable Documentation

◆ _241_FIELDS

tuple _241_FIELDS
protected
Initial value:
1= ('Metadata-Version', 'Name', 'Version', 'Platform',
2 'Summary', 'Description',
3 'Keywords', 'Home-page', 'Author', 'Author-email',
4 'License')

Definition at line 55 of file metadata.py.

◆ _314_FIELDS

tuple _314_FIELDS
protected
Initial value:
1= ('Metadata-Version', 'Name', 'Version', 'Platform',
2 'Supported-Platform', 'Summary', 'Description',
3 'Keywords', 'Home-page', 'Author', 'Author-email',
4 'License', 'Classifier', 'Download-URL', 'Obsoletes',
5 'Provides', 'Requires')

Definition at line 60 of file metadata.py.

◆ _314_MARKERS

tuple _314_MARKERS
protected
Initial value:
1= ('Obsoletes', 'Provides', 'Requires', 'Classifier',
2 'Download-URL')

Definition at line 66 of file metadata.py.

◆ _345_FIELDS

tuple _345_FIELDS
protected
Initial value:
1= ('Metadata-Version', 'Name', 'Version', 'Platform',
2 'Supported-Platform', 'Summary', 'Description',
3 'Keywords', 'Home-page', 'Author', 'Author-email',
4 'Maintainer', 'Maintainer-email', 'License',
5 'Classifier', 'Download-URL', 'Obsoletes-Dist',
6 'Project-URL', 'Provides-Dist', 'Requires-Dist',
7 'Requires-Python', 'Requires-External')

Definition at line 69 of file metadata.py.

◆ _345_MARKERS

tuple _345_MARKERS
protected
Initial value:
1= ('Provides-Dist', 'Requires-Dist', 'Requires-Python',
2 'Obsoletes-Dist', 'Requires-External', 'Maintainer',
3 'Maintainer-email', 'Project-URL')

Definition at line 77 of file metadata.py.

◆ _426_FIELDS

tuple _426_FIELDS
protected
Initial value:
1= ('Metadata-Version', 'Name', 'Version', 'Platform',
2 'Supported-Platform', 'Summary', 'Description',
3 'Keywords', 'Home-page', 'Author', 'Author-email',
4 'Maintainer', 'Maintainer-email', 'License',
5 'Classifier', 'Download-URL', 'Obsoletes-Dist',
6 'Project-URL', 'Provides-Dist', 'Requires-Dist',
7 'Requires-Python', 'Requires-External', 'Private-Version',
8 'Obsoleted-By', 'Setup-Requires-Dist', 'Extension',
9 'Provides-Extra')

Definition at line 81 of file metadata.py.

◆ _426_MARKERS

tuple _426_MARKERS
protected
Initial value:
1= ('Private-Version', 'Provides-Extra', 'Obsoleted-By',
2 'Setup-Requires-Dist', 'Extension')

Definition at line 91 of file metadata.py.

◆ _566_FIELDS

tuple _566_FIELDS
protected
Initial value:
1= _426_FIELDS + ('Description-Content-Type',
2 'Requires', 'Provides', 'Obsoletes')

Definition at line 98 of file metadata.py.

◆ _566_MARKERS

tuple _566_MARKERS = ('Description-Content-Type',)
protected

Definition at line 101 of file metadata.py.

◆ _643_FIELDS

tuple _643_FIELDS = _566_FIELDS + _643_MARKERS
protected

Definition at line 105 of file metadata.py.

◆ _643_MARKERS

tuple _643_MARKERS = ('Dynamic', 'License-File')
protected

Definition at line 103 of file metadata.py.

◆ _ALL_FIELDS

_ALL_FIELDS = set()
protected

Definition at line 107 of file metadata.py.

◆ _ATTR2FIELD

dict _ATTR2FIELD
protected
Initial value:
1= {
2 name.lower().replace("-", "_"): name for name in _ALL_FIELDS
3}

Definition at line 216 of file metadata.py.

◆ _ELEMENTSFIELD

tuple _ELEMENTSFIELD = ('Keywords',)
protected

Definition at line 231 of file metadata.py.

◆ _FIELD2ATTR

dict _FIELD2ATTR = {field: attr for attr, field in _ATTR2FIELD.items()}
protected

Definition at line 219 of file metadata.py.

◆ _FILESAFE

_FILESAFE = re.compile('[^A-Za-z0-9.]+')
protected

Definition at line 237 of file metadata.py.

◆ _LINE_PREFIX_1_2

_LINE_PREFIX_1_2 = re.compile('\n \\|')
protected

Definition at line 53 of file metadata.py.

◆ _LINE_PREFIX_PRE_1_2

_LINE_PREFIX_PRE_1_2 = re.compile('\n ')
protected

Definition at line 54 of file metadata.py.

◆ _LISTFIELDS

tuple _LISTFIELDS
protected
Initial value:
1= ('Platform', 'Classifier', 'Obsoletes',
2 'Requires', 'Provides', 'Obsoletes-Dist',
3 'Provides-Dist', 'Requires-Dist', 'Requires-External',
4 'Project-URL', 'Supported-Platform', 'Setup-Requires-Dist',
5 'Provides-Extra', 'Extension', 'License-File')

Definition at line 224 of file metadata.py.

◆ _LISTTUPLEFIELDS

tuple _LISTTUPLEFIELDS = ('Project-URL',)
protected

Definition at line 229 of file metadata.py.

◆ _MISSING

_MISSING = object()
protected

Definition at line 235 of file metadata.py.

◆ _PREDICATE_FIELDS

tuple _PREDICATE_FIELDS = ('Requires-Dist', 'Obsoletes-Dist', 'Provides-Dist')
protected

Definition at line 221 of file metadata.py.

◆ _UNICODEFIELDS

tuple _UNICODEFIELDS = ('Author', 'Maintainer', 'Summary', 'Description')
protected

Definition at line 233 of file metadata.py.

◆ _VERSION_FIELDS

tuple _VERSION_FIELDS = ('Version',)
protected

Definition at line 223 of file metadata.py.

◆ _VERSIONS_FIELDS

tuple _VERSIONS_FIELDS = ('Requires-Python',)
protected

Definition at line 222 of file metadata.py.

◆ EXTRA_RE

EXTRA_RE = re.compile()

Definition at line 115 of file metadata.py.

◆ LEGACY_METADATA_FILENAME

str LEGACY_METADATA_FILENAME = 'METADATA'

Definition at line 615 of file metadata.py.

◆ logger

logger = logging.getLogger(__name__)

Definition at line 25 of file metadata.py.

◆ METADATA_FILENAME

str METADATA_FILENAME = 'pydist.json'

Definition at line 613 of file metadata.py.

◆ PKG_INFO_ENCODING

str PKG_INFO_ENCODING = 'utf-8'

Definition at line 47 of file metadata.py.

◆ PKG_INFO_PREFERRED_VERSION

str PKG_INFO_PREFERRED_VERSION = '1.1'

Definition at line 51 of file metadata.py.

◆ WHEEL_METADATA_FILENAME

str WHEEL_METADATA_FILENAME = 'metadata.json'

Definition at line 614 of file metadata.py.