forked from platformio/platformio-core
DataModel: add support for silent validation and "get_exceptions" API
This commit is contained in:
1 parent
39c8996093
commit
df6a8da290
4 files changed
+128
-53
No files matched your search
@@ -14,7 +14,7 @@
|
||||
|
||||
import semantic_version
|
||||
|
||||
from platformio.datamodel import DataField, DataModel, ListOfType
|
||||
from platformio.datamodel import DataField, DataModel, ListOfType, StrictDataModel
|
||||
|
||||
|
||||
def validate_semver_field(_, value):
|
||||
@@ -48,12 +48,12 @@ class ManifestModel(DataModel):
|
||||
version = DataField(
|
||||
max_length=50, validate_factory=validate_semver_field, required=True
|
||||
)
|
||||
|
||||
description = DataField(max_length=1000)
|
||||
description = DataField(max_length=1000, required=True)
|
||||
keywords = DataField(
|
||||
type=ListOfType(DataField(max_length=255, regex=r"^[a-z][a-z\d\- ]*[a-z]$"))
|
||||
type=ListOfType(DataField(max_length=255, regex=r"^[a-z\d\- ]+$")),
|
||||
required=True,
|
||||
)
|
||||
authors = DataField(type=ListOfType(AuthorModel))
|
||||
authors = DataField(type=ListOfType(AuthorModel), required=True)
|
||||
|
||||
homepage = DataField(max_length=255)
|
||||
license = DataField(max_length=255)
|
||||
@@ -68,8 +68,5 @@ class ManifestModel(DataModel):
|
||||
export = DataField(type=ExportModel)
|
||||
|
||||
|
||||
class StrictManifestModel(ManifestModel):
|
||||
def __init__(self, *args, **kwargs):
|
||||
for name in ("description", "keywords", "authors"):
|
||||
getattr(self, name).required = True
|
||||
super(StrictManifestModel, self).__init__(*args, **kwargs)
|
||||
class StrictManifestModel(ManifestModel, StrictDataModel):
|
||||
pass
|
||||
@@ -151,6 +151,8 @@ class LibraryJsonManifestParser(BaseManifestParser):
|
||||
data["authors"] = self._parse_authors(data["authors"])
|
||||
if "platforms" in data:
|
||||
data["platforms"] = self._parse_platforms(data["platforms"]) or None
|
||||
if "export" in data:
|
||||
data["export"] = self._parse_export(data["export"])
|
||||
|
||||
return data
|
||||
|
||||
@@ -180,9 +182,7 @@ class LibraryJsonManifestParser(BaseManifestParser):
|
||||
continue
|
||||
if "export" not in data:
|
||||
data["export"] = {}
|
||||
data["export"][key] = (
|
||||
data[key] if isinstance(data[key], list) else [data[key]]
|
||||
)
|
||||
data["export"][key] = data[key]
|
||||
del data[key]
|
||||
|
||||
return data
|
||||
@@ -206,6 +206,17 @@ class LibraryJsonManifestParser(BaseManifestParser):
|
||||
result.append(item)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _parse_export(raw):
|
||||
if not isinstance(raw, dict):
|
||||
return None
|
||||
result = {}
|
||||
for k in ("include", "exclude"):
|
||||
if k not in raw:
|
||||
continue
|
||||
result[k] = raw[k] if isinstance(raw[k], list) else [raw[k]]
|
||||
return result
|
||||
|
||||
|
||||
class ModuleJsonManifestParser(BaseManifestParser):
|
||||
def parse(self, contents):
|
||||
|
||||
Reference in new issue
Block a user