forked from platformio/platformio-core
Added support for Arduino's library.properties `depends` field // Resolve #2781
This commit is contained in:
1 parent
bc69259dd1
commit
efe8e599fd
8 files changed
+169
-39
No files matched your search
@@ -19,6 +19,7 @@ import re
|
||||
|
||||
import requests
|
||||
|
||||
from platformio import util
|
||||
from platformio.compat import get_class_attributes, string_types
|
||||
from platformio.fs import get_file_contents
|
||||
from platformio.package.exception import ManifestParserError, UnknownManifestError
|
||||
@@ -286,6 +287,8 @@ class LibraryJsonManifestParser(BaseManifestParser):
|
||||
data["platforms"] = self._parse_platforms(data["platforms"]) or None
|
||||
if "export" in data:
|
||||
data["export"] = self._parse_export(data["export"])
|
||||
if "dependencies" in data:
|
||||
data["dependencies"] = self._parse_dependencies(data["dependencies"])
|
||||
|
||||
return data
|
||||
|
||||
@@ -350,6 +353,26 @@ class LibraryJsonManifestParser(BaseManifestParser):
|
||||
result[k] = raw[k] if isinstance(raw[k], list) else [raw[k]]
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _parse_dependencies(raw):
|
||||
if isinstance(raw, dict):
|
||||
if "name" in raw: # compatibility with dep as dict
|
||||
return [raw]
|
||||
return [dict(name=name, version=version) for name, version in raw.items()]
|
||||
if isinstance(raw, list):
|
||||
for i, dependency in enumerate(raw):
|
||||
assert isinstance(dependency, dict)
|
||||
for k, v in dependency.items():
|
||||
if k not in ("platforms", "frameworks", "authors"):
|
||||
continue
|
||||
if "*" in v:
|
||||
del raw[i][k]
|
||||
raw[i][k] = util.items_to_list(v)
|
||||
return raw
|
||||
raise ManifestParserError(
|
||||
"Invalid dependencies format, should be list or dictionary"
|
||||
)
|
||||
|
||||
|
||||
class ModuleJsonManifestParser(BaseManifestParser):
|
||||
manifest_type = ManifestFileType.MODULE_JSON
|
||||
@@ -408,6 +431,8 @@ class LibraryPropertiesManifestParser(BaseManifestParser):
|
||||
if "author" in data:
|
||||
data["authors"] = self._parse_authors(data)
|
||||
del data["author"]
|
||||
if "depends" in data:
|
||||
data["dependencies"] = self._parse_dependencies(data["depends"])
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
@@ -534,6 +559,26 @@ class LibraryPropertiesManifestParser(BaseManifestParser):
|
||||
result["include"] = [include]
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _parse_dependencies(raw):
|
||||
result = []
|
||||
for item in raw.split(","):
|
||||
item = item.strip()
|
||||
if not item:
|
||||
continue
|
||||
if item.endswith(")") and "(" in item:
|
||||
name, version = item.split("(")
|
||||
result.append(
|
||||
dict(
|
||||
name=name.strip(),
|
||||
version=version[:-1].strip(),
|
||||
frameworks=["arduino"],
|
||||
)
|
||||
)
|
||||
else:
|
||||
result.append(dict(name=item, frameworks=["arduino"]))
|
||||
return result
|
||||
|
||||
|
||||
class PlatformJsonManifestParser(BaseManifestParser):
|
||||
manifest_type = ManifestFileType.PLATFORM_JSON
|
||||
@@ -542,6 +587,8 @@ class PlatformJsonManifestParser(BaseManifestParser):
|
||||
data = json.loads(contents)
|
||||
if "frameworks" in data:
|
||||
data["frameworks"] = self._parse_frameworks(data["frameworks"])
|
||||
if "packages" in data:
|
||||
data["dependencies"] = self._parse_dependencies(data["packages"])
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
@@ -550,6 +597,12 @@ class PlatformJsonManifestParser(BaseManifestParser):
|
||||
return None
|
||||
return [name.lower() for name in raw.keys()]
|
||||
|
||||
@staticmethod
|
||||
def _parse_dependencies(raw):
|
||||
return [
|
||||
dict(name=name, version=opts.get("version")) for name, opts in raw.items()
|
||||
]
|
||||
|
||||
|
||||
class PackageJsonManifestParser(BaseManifestParser):
|
||||
manifest_type = ManifestFileType.PACKAGE_JSON
|
||||
|
||||
@@ -102,6 +102,32 @@ class RepositorySchema(StrictSchema):
|
||||
branch = fields.Str(validate=validate.Length(min=1, max=50))
|
||||
|
||||
|
||||
class DependencySchema(StrictSchema):
|
||||
name = fields.Str(required=True, validate=validate.Length(min=1, max=100))
|
||||
version = fields.Str(validate=validate.Length(min=1, max=100))
|
||||
authors = StrictListField(fields.Str(validate=validate.Length(min=1, max=50)))
|
||||
platforms = StrictListField(
|
||||
fields.Str(
|
||||
validate=[
|
||||
validate.Length(min=1, max=50),
|
||||
validate.Regexp(
|
||||
r"^([a-z\d\-_]+|\*)$", error="Only [a-z0-9-_*] chars are allowed"
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
frameworks = StrictListField(
|
||||
fields.Str(
|
||||
validate=[
|
||||
validate.Length(min=1, max=50),
|
||||
validate.Regexp(
|
||||
r"^([a-z\d\-_]+|\*)$", error="Only [a-z0-9-_*] chars are allowed"
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class ExportSchema(BaseSchema):
|
||||
include = StrictListField(fields.Str)
|
||||
exclude = StrictListField(fields.Str)
|
||||
@@ -133,6 +159,7 @@ class ManifestSchema(BaseSchema):
|
||||
homepage = fields.Url(validate=validate.Length(min=1, max=255))
|
||||
license = fields.Str(validate=validate.Length(min=1, max=255))
|
||||
repository = fields.Nested(RepositorySchema)
|
||||
dependencies = fields.Nested(DependencySchema, many=True)
|
||||
|
||||
# library.json
|
||||
export = fields.Nested(ExportSchema)
|
||||
|
||||
Reference in new issue
Block a user