find in group or meta should return GroupConfig (and not KerneleGroupConfig) and remote 'first' attributs

This commit is contained in:
2018-10-07 16:29:56 +02:00
parent 5b5f06a612
commit e4362e9b09
3 changed files with 52 additions and 47 deletions

View File

@ -1086,10 +1086,10 @@ class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
storage=None,
metaconfig_prefix=None):
return Config(self._config_bag.context.duplicate(session_id,
persistent=persistent,
storage=storage,
metaconfig_prefix=metaconfig_prefix,
deep=True))
persistent=persistent,
storage=storage,
metaconfig_prefix=metaconfig_prefix,
deep=True))
def metaconfig(self):
return Config(self._config_bag.context.cfgimpl_get_meta())
@ -1108,15 +1108,11 @@ class _TiramisuContextGroupConfig(TiramisuContext):
def find(self,
name: str,
value=undefined,
first: bool=False):
"""Find an or a list of options"""
if first:
return Config(self._config_bag.context.find_firsts(byname=name,
byvalue=value,
config_bag=self._config_bag))
else:
raise APIError('not implemented yet')
value=undefined):
"""Find an or a list of config with finding option"""
return GroupConfig(self._config_bag.context.find_group(byname=name,
byvalue=value,
config_bag=self._config_bag))
def __call__(self,
path: Optional[str]):
@ -1258,7 +1254,10 @@ class GroupConfig(TiramisuAPI):
session_id: Union[str, None]=None) -> None:
_children = []
for child in children:
_children.append(child._config_bag.context)
if isinstance(child, TiramisuAPI):
_children.append(child._config_bag.context)
else:
_children.append(child)
config = KernelGroupConfig(_children,
session_id=session_id)

View File

@ -871,14 +871,14 @@ class KernelGroupConfig(_CommonConfig):
return ret
def find_firsts(self,
config_bag,
byname=None,
bypath=undefined,
byoption=undefined,
byvalue=undefined,
raise_if_not_found=True,
_sub=False):
def find_group(self,
config_bag,
byname=None,
bypath=undefined,
byoption=undefined,
byvalue=undefined,
raise_if_not_found=True,
_sub=False):
"""Find first not in current KernelGroupConfig, but in each children
"""
#if KernelMetaConfig, all children have same OptionDescription in context
@ -898,13 +898,13 @@ class KernelGroupConfig(_CommonConfig):
ret = []
for child in self._impl_children:
if isinstance(child, KernelGroupConfig):
ret.extend(child.find_firsts(byname=byname,
bypath=bypath,
byoption=byoption,
byvalue=byvalue,
config_bag=config_bag,
raise_if_not_found=False,
_sub=True))
ret.extend(child.find_group(byname=byname,
bypath=bypath,
byoption=byoption,
byvalue=byvalue,
config_bag=config_bag,
raise_if_not_found=False,
_sub=True))
else:
try:
cconfig_bag = config_bag.copy()
@ -919,12 +919,10 @@ class KernelGroupConfig(_CommonConfig):
ret.append(child)
except StopIteration:
pass
if _sub:
return ret
else:
if not _sub:
self._find_return_results(ret != [],
raise_if_not_found)
return KernelGroupConfig(ret)
return ret
def impl_getname(self):
return self._impl_name