From 261c46d4ef5e1b78344edc70cb23ef5f0051c51e Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 3 Mar 2020 23:10:19 +0200 Subject: [PATCH] Add support for Arm Mbed "module.json" ``dependencies`` field // Resolve #3400 --- HISTORY.rst | 1 + platformio/package/manifest/parser.py | 11 +++++++++++ tests/package/test_manifest.py | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 172f7bee..16145dfa 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,6 +9,7 @@ PlatformIO Core 4 4.2.2 (2020-??-??) ~~~~~~~~~~~~~~~~~~ +* Added support for Arm Mbed "module.json" ``dependencies`` field (`issue #3400 `_) * Fixed an issue when quitting from PlatformIO IDE does not shutdown PIO Home server * Fixed an issue "the JSON object must be str, not 'bytes'" when PIO Home is used with Python 3.5 (`issue #3396 `_) diff --git a/platformio/package/manifest/parser.py b/platformio/package/manifest/parser.py index 87d81f03..8d9cf654 100644 --- a/platformio/package/manifest/parser.py +++ b/platformio/package/manifest/parser.py @@ -392,6 +392,8 @@ class ModuleJsonManifestParser(BaseManifestParser): if "licenses" in data: data["license"] = self._parse_license(data.get("licenses")) del data["licenses"] + if "dependencies" in data: + data["dependencies"] = self._parse_dependencies(data["dependencies"]) return data def _parse_authors(self, raw): @@ -411,6 +413,15 @@ class ModuleJsonManifestParser(BaseManifestParser): return None return raw[0].get("type") + @staticmethod + def _parse_dependencies(raw): + if isinstance(raw, dict): + return [ + dict(name=name, version=version, frameworks=["mbed"]) + for name, version in raw.items() + ] + raise ManifestParserError("Invalid dependencies format, should be a dictionary") + class LibraryPropertiesManifestParser(BaseManifestParser): manifest_type = ManifestFileType.LIBRARY_PROPERTIES diff --git a/tests/package/test_manifest.py b/tests/package/test_manifest.py index 80de5e75..abf66ab3 100644 --- a/tests/package/test_manifest.py +++ b/tests/package/test_manifest.py @@ -154,6 +154,10 @@ def test_module_json_parser(): "url": "git@github.com:username/repo.git" }, "version": "1.2.3", + "dependencies": { + "usefulmodule": "^1.2.3", + "simplelog": "ARMmbed/simplelog#~0.0.1" + }, "customField": "Custom Value" } """ @@ -173,6 +177,14 @@ def test_module_json_parser(): "authors": [{"email": "name@surname.com", "name": "Name Surname"}], "version": "1.2.3", "repository": {"type": "git", "url": "git@github.com:username/repo.git"}, + "dependencies": [ + {"name": "usefulmodule", "version": "^1.2.3", "frameworks": ["mbed"]}, + { + "name": "simplelog", + "version": "ARMmbed/simplelog#~0.0.1", + "frameworks": ["mbed"], + }, + ], "customField": "Custom Value", }, )