Parse dev-platform keywords

This commit is contained in:
Ivan Kravets
2020-06-26 19:49:25 +03:00
parent 0bec1f1585
commit bc2eb0d79f
2 changed files with 22 additions and 19 deletions

View File

@ -159,6 +159,21 @@ class BaseManifestParser(object):
def as_dict(self):
return self._data
@staticmethod
def str_to_list(value, sep=",", lowercase=True):
if isinstance(value, string_types):
value = value.split(sep)
assert isinstance(value, list)
result = []
for item in value:
item = item.strip()
if not item:
continue
if lowercase:
item = item.lower()
result.append(item)
return result
@staticmethod
def normalize_author(author):
assert isinstance(author, dict)
@ -296,7 +311,7 @@ class LibraryJsonManifestParser(BaseManifestParser):
# normalize Union[str, list] fields
for k in ("keywords", "platforms", "frameworks"):
if k in data:
data[k] = self._str_to_list(data[k], sep=",")
data[k] = self.str_to_list(data[k], sep=",")
if "authors" in data:
data["authors"] = self._parse_authors(data["authors"])
@ -309,21 +324,6 @@ class LibraryJsonManifestParser(BaseManifestParser):
return data
@staticmethod
def _str_to_list(value, sep=",", lowercase=True):
if isinstance(value, string_types):
value = value.split(sep)
assert isinstance(value, list)
result = []
for item in value:
item = item.strip()
if not item:
continue
if lowercase:
item = item.lower()
result.append(item)
return result
@staticmethod
def _process_renamed_fields(data):
if "url" in data:
@ -617,6 +617,8 @@ class PlatformJsonManifestParser(BaseManifestParser):
def parse(self, contents):
data = json.loads(contents)
if "keywords" in data:
data["keywords"] = self.str_to_list(data["keywords"], sep=",")
if "frameworks" in data:
data["frameworks"] = self._parse_frameworks(data["frameworks"])
if "packages" in data:

View File

@ -544,8 +544,8 @@ def test_platform_json_schema():
"name": "atmelavr",
"title": "Atmel AVR",
"description": "Atmel AVR 8- and 32-bit MCUs deliver a unique combination of performance, power efficiency and design flexibility. Optimized to speed time to market-and easily adapt to new ones-they are based on the industrys most code-efficient architecture for C and assembly programming.",
"url": "http://www.atmel.com/products/microcontrollers/avr/default.aspx",
"homepage": "http://platformio.org/platforms/atmelavr",
"keywords": "arduino, atmel, avr",
"homepage": "http://www.atmel.com/products/microcontrollers/avr/default.aspx",
"license": "Apache-2.0",
"engines": {
"platformio": "<5"
@ -603,7 +603,8 @@ def test_platform_json_schema():
"on the industrys most code-efficient architecture for C and "
"assembly programming."
),
"homepage": "http://platformio.org/platforms/atmelavr",
"keywords": ["arduino", "atmel", "avr"],
"homepage": "http://www.atmel.com/products/microcontrollers/avr/default.aspx",
"license": "Apache-2.0",
"repository": {
"url": "https://github.com/platformio/platform-atmelavr.git",