Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/npm.py
Show First 20 Lines • Show All 270 Lines • ▼ Show 20 Lines | def normalize_license(self, s): | ||||
""" | """ | ||||
if isinstance(s, str): | if isinstance(s, str): | ||||
if s.startswith("SEE LICENSE IN "): | if s.startswith("SEE LICENSE IN "): | ||||
# Very common pattern, because it is an example in the specification. | # Very common pattern, because it is an example in the specification. | ||||
# It is followed by the filename; and the indexer architecture currently | # It is followed by the filename; and the indexer architecture currently | ||||
# does not allow accessing that from metadata mappings. | # does not allow accessing that from metadata mappings. | ||||
# (Plus, an hypothetical license mapping would eventually pick it up) | # (Plus, an hypothetical license mapping would eventually pick it up) | ||||
return | return | ||||
if " " in s: | |||||
# Either an SPDX expression, or unusable data | |||||
# TODO: handle it | |||||
return | |||||
return SPDX + s | return SPDX + s | ||||
def normalize_keywords(self, lst): | def normalize_keywords(self, lst): | ||||
"""https://docs.npmjs.com/files/package.json#homepage | """https://docs.npmjs.com/files/package.json#homepage | ||||
>>> NpmMapping().normalize_keywords(['foo', 'bar']) | >>> NpmMapping().normalize_keywords(['foo', 'bar']) | ||||
[rdflib.term.Literal('foo'), rdflib.term.Literal('bar')] | [rdflib.term.Literal('foo'), rdflib.term.Literal('bar')] | ||||
""" | """ | ||||
if isinstance(lst, list): | if isinstance(lst, list): | ||||
return [Literal(x) for x in lst if isinstance(x, str)] | return [Literal(x) for x in lst if isinstance(x, str)] |