diff --git a/platformio/package/manifest/parser.py b/platformio/package/manifest/parser.py index 4e6399f3..f41d97e6 100644 --- a/platformio/package/manifest/parser.py +++ b/platformio/package/manifest/parser.py @@ -54,7 +54,7 @@ class ManifestFileType(object): return ManifestFileType.MODULE_JSON if uri.endswith("package.json"): return ManifestFileType.PACKAGE_JSON - return ManifestFileType.LIBRARY_JSON + return None class ManifestParserFactory(object): @@ -76,6 +76,16 @@ class ManifestParserFactory(object): @staticmethod def new_from_dir(path, remote_url=None): assert os.path.isdir(path), "Invalid directory %s" % path + + type_from_uri = ManifestFileType.from_uri(remote_url) if remote_url else None + if type_from_uri and os.path.isfile(os.path.join(path, type_from_uri)): + return ManifestParserFactory.new( + get_file_contents(os.path.join(path, type_from_uri)), + type_from_uri, + remote_url=remote_url, + package_dir=path, + ) + file_order = [ ManifestFileType.PLATFORM_JSON, ManifestFileType.LIBRARY_JSON, @@ -99,7 +109,9 @@ class ManifestParserFactory(object): r = requests.get(remote_url) r.raise_for_status() return ManifestParserFactory.new( - r.text, ManifestFileType.from_uri(remote_url), remote_url + r.text, + ManifestFileType.from_uri(remote_url) or ManifestFileType.LIBRARY_JSON, + remote_url, ) @staticmethod diff --git a/tests/test_pkgmanifest.py b/tests/test_pkgmanifest.py index e8b827d6..027733a1 100644 --- a/tests/test_pkgmanifest.py +++ b/tests/test_pkgmanifest.py @@ -425,6 +425,20 @@ def test_package_json_model(): assert mp.as_dict()["system"] == ["darwin_x86_64"] +def test_parser_from_dir(tmpdir_factory): + pkg_dir = tmpdir_factory.mktemp("package") + pkg_dir.join("library.json").write('{"name": "library.json"}') + pkg_dir.join("library.properties").write("name=library.properties") + + data = parser.ManifestParserFactory.new_from_dir(str(pkg_dir)).as_dict() + assert data["name"] == "library.json" + + data = parser.ManifestParserFactory.new_from_dir( + str(pkg_dir), remote_url="http://localhost/library.properties" + ).as_dict() + assert data["name"] == "library.properties" + + def test_examples_from_dir(tmpdir_factory): package_dir = tmpdir_factory.mktemp("project") package_dir.join("library.json").write(