# HG changeset patch # User Éric Araujo # Parent fc263035cfaef6046c6ca82e2212397a7c8eadb5 $ py24 setup.py check running check warning: check: missing required metadata: Version, Home-page $ py24 setup.py check running check warning: check: missing required metadata: version, home_page diff --git a/src/distutils2/command/check.py b/src/distutils2/command/check.py --- a/src/distutils2/command/check.py +++ b/src/distutils2/command/check.py @@ -60,7 +60,7 @@ class check(Command): Warns if any are missing. """ - missing, __ = self.distribution.metadata.check() + missing, __ = self.distribution.metadata.check(attr_style=True) if missing != []: self.warn("missing required meta-data: %s" % ', '.join(missing)) diff --git a/src/distutils2/metadata.py b/src/distutils2/metadata.py --- a/src/distutils2/metadata.py +++ b/src/distutils2/metadata.py @@ -167,6 +167,8 @@ _ATTR2FIELD = {'metadata_version': 'Meta 'project_url': 'Project-URL', } +_FIELD2ATTR = dict((field, attr) for (attr, field) in _ATTR2FIELD.iteritems() + _PREDICATE_FIELDS = ('Requires-Dist', 'Obsoletes-Dist', 'Provides-Dist') _VERSIONS_FIELDS = ('Requires-Python',) _VERSION_FIELDS = ('Version',) @@ -402,25 +404,34 @@ class DistributionMetadata(object): return None return value - def check(self): - """Checks if the metadata are compliant.""" + def check(self, attr_style=False): + """Checks if the metadata is compliant. + + Return (list of missing metadata fields, list of warnings). If + *attr_style* is true, field names will use the same spelling used for + DistributionMetadata attributes (a.k.a. distutils2.core.setup keyword + arguments), i.e home_page instead of Home-page. + """ # XXX should check the versions (if the file was loaded) - missing = [] + missing, warnings = [], [] + + if attr_style: + getname = _FIELD2ATTR.__getitem__ + else: + getname = lambda field: field + for attr in ('Name', 'Version', 'Home-page'): value = self[attr] if value == 'UNKNOWN': - missing.append(attr) + missing.append(getname(attr)) if _HAS_DOCUTILS: - warnings = self._check_rst_data(self['Description']) - else: - warnings = [] + warnings.extend(self._check_rst_data(self['Description'])) # checking metadata 1.2 (XXX needs to check 1.1, 1.0) if self['Metadata-Version'] != '1.2': return missing, warnings - def is_valid_predicates(value): for v in value: if not is_valid_predicate(v.split(';')[0]): @@ -437,7 +448,7 @@ class DistributionMetadata(object): if not controller(value): warnings.append('Wrong value for "%s": %s' \ - % (field, value)) + % (getname(field), value)) return missing, warnings