mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-06-25 09:58:21 -04:00
Merge branch 'prawn/reposyamllocal' into 'dev'
ReposConfigFile: allow_extra=True See merge request kupfer/kupferbootstrap!64
This commit is contained in:
commit
19a7cf9fa1
4 changed files with 25 additions and 19 deletions
|
@ -73,6 +73,9 @@ class ProfilesSection(DictScheme):
|
||||||
current: str
|
current: str
|
||||||
default: SparseProfile
|
default: SparseProfile
|
||||||
|
|
||||||
|
def __init__(self, *kargs, allow_extra: bool = True, **kwargs):
|
||||||
|
super().__init__(*kargs, allow_extra=allow_extra, **kwargs) # type: ignore[misc]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def transform(cls, values: Mapping[str, Any], validate: bool = True, allow_extra: bool = True, type_hints: Optional[dict[str, Any]] = None):
|
def transform(cls, values: Mapping[str, Any], validate: bool = True, allow_extra: bool = True, type_hints: Optional[dict[str, Any]] = None):
|
||||||
results = {}
|
results = {}
|
||||||
|
@ -84,11 +87,11 @@ class ProfilesSection(DictScheme):
|
||||||
raise Exception(f'Unknown key {k} in profiles section (Hint: extra_keys not allowed for some reason)')
|
raise Exception(f'Unknown key {k} in profiles section (Hint: extra_keys not allowed for some reason)')
|
||||||
if not isinstance(v, dict):
|
if not isinstance(v, dict):
|
||||||
raise Exception(f'profile {v} is not a dict!')
|
raise Exception(f'profile {v} is not a dict!')
|
||||||
results[k] = SparseProfile.fromDict(v, validate=True)
|
results[k] = SparseProfile.fromDict(v, validate=True, allow_extra=allow_extra)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def update(self, d, validate: bool = True):
|
def update(self, d, validate: bool = True, **kwargs): # type: ignore[override]
|
||||||
Munch.update(self, self.transform(values=d, validate=validate))
|
Munch.update(self, self.transform(values=d, validate=validate, **kwargs))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'{type(self)}{dict.__repr__(self.toDict())}'
|
return f'{type(self)}{dict.__repr__(self.toDict())}'
|
||||||
|
@ -103,12 +106,12 @@ class Config(DictScheme):
|
||||||
profiles: ProfilesSection
|
profiles: ProfilesSection
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromDict(
|
def fromDict( # type: ignore[override]
|
||||||
cls,
|
cls,
|
||||||
values: Mapping[str, Any],
|
values: Mapping[str, Any],
|
||||||
validate: bool = True,
|
validate: bool = True,
|
||||||
allow_extra: bool = False,
|
allow_extra: bool = False,
|
||||||
allow_incomplete: bool = False,
|
allow_incomplete: bool = False,
|
||||||
):
|
):
|
||||||
values = dict(values) # copy for later modification
|
values = dict(values) # copy for later modification
|
||||||
_vals = {}
|
_vals = {}
|
||||||
|
@ -119,7 +122,7 @@ class Config(DictScheme):
|
||||||
continue
|
continue
|
||||||
value = values.pop(name)
|
value = values.pop(name)
|
||||||
if not isinstance(value, _class):
|
if not isinstance(value, _class):
|
||||||
value = _class.fromDict(value, validate=validate)
|
value = _class(value, validate=validate)
|
||||||
_vals[name] = value
|
_vals[name] = value
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
|
|
|
@ -269,5 +269,5 @@ def parse_deviceinfo(deviceinfo_lines: list[str], device_name: str, kernel='main
|
||||||
if 'arch' in info:
|
if 'arch' in info:
|
||||||
arch = info['arch']
|
arch = info['arch']
|
||||||
info['arch'] = PMOS_ARCHES_OVERRIDES.get(arch, arch) # type: ignore[arg-type]
|
info['arch'] = PMOS_ARCHES_OVERRIDES.get(arch, arch) # type: ignore[arg-type]
|
||||||
dev = DeviceInfo.fromDict(info)
|
dev = DeviceInfo.fromDict(info, allow_extra=True)
|
||||||
return dev
|
return dev
|
||||||
|
|
|
@ -51,8 +51,8 @@ class DictScheme(Munch):
|
||||||
_strip_hidden: ClassVar[bool] = False
|
_strip_hidden: ClassVar[bool] = False
|
||||||
_sparse: ClassVar[bool] = False
|
_sparse: ClassVar[bool] = False
|
||||||
|
|
||||||
def __init__(self, d: Mapping = {}, validate: bool = True, **kwargs):
|
def __init__(self, d: Mapping = {}, validate: bool = True, allow_extra: bool = False, **kwargs):
|
||||||
self.update(dict(d) | kwargs, validate=validate)
|
self.update(dict(d) | kwargs, validate=validate, allow_extra=allow_extra)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def transform(
|
def transform(
|
||||||
|
@ -162,8 +162,8 @@ class DictScheme(Munch):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromDict(cls, values: Mapping[str, Any], validate: bool = True):
|
def fromDict(cls, values: Mapping[str, Any], validate: bool = True, **kwargs):
|
||||||
return cls(d=values, validate=validate)
|
return cls(d=values, validate=validate, **kwargs)
|
||||||
|
|
||||||
def toDict(
|
def toDict(
|
||||||
self,
|
self,
|
||||||
|
@ -251,8 +251,8 @@ class DictScheme(Munch):
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update(self, d: Mapping[str, Any], validate: bool = True):
|
def update(self, d: Mapping[str, Any], validate: bool = True, allow_extra: bool = False):
|
||||||
Munch.update(self, type(self).transform(d, validate=validate))
|
Munch.update(self, type(self).transform(d, validate=validate, allow_extra=allow_extra))
|
||||||
|
|
||||||
def __init_subclass__(cls):
|
def __init_subclass__(cls):
|
||||||
super().__init_subclass__()
|
super().__init_subclass__()
|
||||||
|
|
|
@ -51,8 +51,8 @@ class ReposConfigFile(DictScheme):
|
||||||
_strip_hidden: ClassVar[bool] = True
|
_strip_hidden: ClassVar[bool] = True
|
||||||
_sparse: ClassVar[bool] = True
|
_sparse: ClassVar[bool] = True
|
||||||
|
|
||||||
def __init__(self, d, **kwargs):
|
def __init__(self, d, *, allow_extra: bool = True, **kwargs):
|
||||||
super().__init__(d=d, **kwargs)
|
super().__init__(d=d, allow_extra=allow_extra, **kwargs)
|
||||||
self[REPOS_KEY] = self.get(REPOS_KEY, {})
|
self[REPOS_KEY] = self.get(REPOS_KEY, {})
|
||||||
for repo_cls, defaults, repos, remote_url in [
|
for repo_cls, defaults, repos, remote_url in [
|
||||||
(RepoConfig, REPO_DEFAULTS, self.get(REPOS_KEY), d.get(REMOTEURL_KEY, None)),
|
(RepoConfig, REPO_DEFAULTS, self.get(REPOS_KEY), d.get(REMOTEURL_KEY, None)),
|
||||||
|
@ -66,6 +66,9 @@ class ReposConfigFile(DictScheme):
|
||||||
_repo[REMOTEURL_KEY] = remote_url
|
_repo[REMOTEURL_KEY] = remote_url
|
||||||
repos[name] = repo_cls(_repo, **kwargs)
|
repos[name] = repo_cls(_repo, **kwargs)
|
||||||
|
|
||||||
|
def update(self, *kargs, allow_extra: bool = True, **kwargs):
|
||||||
|
return super().update(*kargs, allow_extra=allow_extra, **kwargs) # type: ignore[misc]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_config(path: str) -> ReposConfigFile:
|
def parse_config(path: str) -> ReposConfigFile:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue