From bc2eb0d79f45f2ede4ed38e1a5e35ab83d993024 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 26 Jun 2020 19:49:25 +0300 Subject: [PATCH] Parse dev-platform keywords --- platformio/package/manifest/parser.py | 34 ++++++++++++++------------- tests/package/test_manifest.py | 7 +++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/platformio/package/manifest/parser.py b/platformio/package/manifest/parser.py index 837fabd6..720d4ea3 100644 --- a/platformio/package/manifest/parser.py +++ b/platformio/package/manifest/parser.py @@ -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: diff --git a/tests/package/test_manifest.py b/tests/package/test_manifest.py index 73acfdaf..13dff94e 100644 --- a/tests/package/test_manifest.py +++ b/tests/package/test_manifest.py @@ -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",