feat: property that make sens + better dependencies
This commit is contained in:
parent
7e8940252b
commit
da8e4ded3c
8 changed files with 67 additions and 15 deletions
|
|
@ -420,7 +420,7 @@ class _TiramisuOptionOptionDescription:
|
||||||
index = self._index
|
index = self._index
|
||||||
parent = self._subconfig.parent
|
parent = self._subconfig.parent
|
||||||
parent_option = parent.option
|
parent_option = parent.option
|
||||||
for woption in self._subconfig.option.get_dependencies(
|
for is_default, woption in self._subconfig.option.get_dependencies(
|
||||||
self._config_bag.context
|
self._config_bag.context
|
||||||
):
|
):
|
||||||
option = woption()
|
option = woption()
|
||||||
|
|
@ -428,6 +428,10 @@ class _TiramisuOptionOptionDescription:
|
||||||
for subconfig in context.get_dynamic_from_dyn_option(
|
for subconfig in context.get_dynamic_from_dyn_option(
|
||||||
self._subconfig, option
|
self._subconfig, option
|
||||||
):
|
):
|
||||||
|
if subconfig.properties is None:
|
||||||
|
subconfig.properties = undefined
|
||||||
|
if is_default and subconfig.config_bag.context.get_owner(subconfig) != owners.default:
|
||||||
|
continue
|
||||||
options.append(
|
options.append(
|
||||||
TiramisuOption(
|
TiramisuOption(
|
||||||
subconfig.path,
|
subconfig.path,
|
||||||
|
|
@ -439,6 +443,8 @@ class _TiramisuOptionOptionDescription:
|
||||||
for subconfig in context.get_dynamic_from_dyn_option(
|
for subconfig in context.get_dynamic_from_dyn_option(
|
||||||
self._subconfig, option
|
self._subconfig, option
|
||||||
):
|
):
|
||||||
|
if is_default and subconfig.config_bag.context.get_owner(subconfig) != owners.default:
|
||||||
|
continue
|
||||||
options.append(
|
options.append(
|
||||||
TiramisuOption(
|
TiramisuOption(
|
||||||
subconfig.path,
|
subconfig.path,
|
||||||
|
|
@ -460,13 +466,18 @@ class _TiramisuOptionOptionDescription:
|
||||||
else:
|
else:
|
||||||
current_indexes = [None]
|
current_indexes = [None]
|
||||||
for current_index in current_indexes:
|
for current_index in current_indexes:
|
||||||
options.append(
|
t_option = TiramisuOption(
|
||||||
TiramisuOption(
|
|
||||||
option.impl_getpath(),
|
option.impl_getpath(),
|
||||||
current_index,
|
current_index,
|
||||||
self._config_bag,
|
self._config_bag,
|
||||||
allow_dynoption=uncalculated,
|
allow_dynoption=uncalculated,
|
||||||
)
|
)
|
||||||
|
t_option._set_subconfig()
|
||||||
|
subconfig = t_option._subconfig
|
||||||
|
if is_default and subconfig.config_bag.context.get_owner(subconfig) != owners.default:
|
||||||
|
continue
|
||||||
|
options.append(
|
||||||
|
t_option,
|
||||||
)
|
)
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ class CCache:
|
||||||
self.reset_one_option_cache(
|
self.reset_one_option_cache(
|
||||||
subconfig,
|
subconfig,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
False,
|
||||||
)
|
)
|
||||||
subconfig.config_bag.properties = subconfig.config_bag.properties | {
|
subconfig.config_bag.properties = subconfig.config_bag.properties | {
|
||||||
"cache"
|
"cache"
|
||||||
|
|
@ -86,13 +87,16 @@ class CCache:
|
||||||
self,
|
self,
|
||||||
subconfig,
|
subconfig,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
):
|
):
|
||||||
"""reset cache for one option"""
|
"""reset cache for one option"""
|
||||||
if subconfig.path in resetted_opts:
|
if subconfig.path in resetted_opts:
|
||||||
return
|
return
|
||||||
resetted_opts.append(subconfig.path)
|
resetted_opts.append(subconfig.path)
|
||||||
config_bag = subconfig.config_bag
|
config_bag = subconfig.config_bag
|
||||||
for woption in subconfig.option.get_dependencies(subconfig.option):
|
# if is_default and config_bag.context.get_owner(subconfig) != owners.default:
|
||||||
|
# return
|
||||||
|
for is_default, woption in subconfig.option.get_dependencies(subconfig.option):
|
||||||
option = woption()
|
option = woption()
|
||||||
if option.issubdyn():
|
if option.issubdyn():
|
||||||
# it's an option in dynoptiondescription, remove cache for all generated option
|
# it's an option in dynoptiondescription, remove cache for all generated option
|
||||||
|
|
@ -100,12 +104,14 @@ class CCache:
|
||||||
subconfig,
|
subconfig,
|
||||||
option,
|
option,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
)
|
)
|
||||||
elif option.impl_is_dynoptiondescription():
|
elif option.impl_is_dynoptiondescription():
|
||||||
self.reset_cache_dyn_optiondescription(
|
self.reset_cache_dyn_optiondescription(
|
||||||
option,
|
option,
|
||||||
config_bag,
|
config_bag,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
option_subconfig = self.get_sub_config(
|
option_subconfig = self.get_sub_config(
|
||||||
|
|
@ -118,6 +124,7 @@ class CCache:
|
||||||
self.reset_one_option_cache(
|
self.reset_one_option_cache(
|
||||||
option_subconfig,
|
option_subconfig,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
)
|
)
|
||||||
del option
|
del option
|
||||||
subconfig.option.reset_cache(
|
subconfig.option.reset_cache(
|
||||||
|
|
@ -149,6 +156,7 @@ class CCache:
|
||||||
option,
|
option,
|
||||||
config_bag,
|
config_bag,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
):
|
):
|
||||||
# reset cache for all chidren
|
# reset cache for all chidren
|
||||||
for subconfig in self.get_dynamic_from_dyn_optiondescription(
|
for subconfig in self.get_dynamic_from_dyn_optiondescription(
|
||||||
|
|
@ -158,6 +166,7 @@ class CCache:
|
||||||
self.reset_one_option_cache(
|
self.reset_one_option_cache(
|
||||||
subconfig,
|
subconfig,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
)
|
)
|
||||||
for walk_subconfig in self.walk(
|
for walk_subconfig in self.walk(
|
||||||
subconfig,
|
subconfig,
|
||||||
|
|
@ -167,6 +176,7 @@ class CCache:
|
||||||
self.reset_one_option_cache(
|
self.reset_one_option_cache(
|
||||||
walk_subconfig,
|
walk_subconfig,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_dynamic_from_dyn_option(self, subconfig, option):
|
def get_dynamic_from_dyn_option(self, subconfig, option):
|
||||||
|
|
@ -223,11 +233,13 @@ class CCache:
|
||||||
subconfig,
|
subconfig,
|
||||||
option,
|
option,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
):
|
):
|
||||||
for dyn_option_subconfig in self.get_dynamic_from_dyn_option(subconfig, option):
|
for dyn_option_subconfig in self.get_dynamic_from_dyn_option(subconfig, option):
|
||||||
self.reset_one_option_cache(
|
self.reset_one_option_cache(
|
||||||
dyn_option_subconfig,
|
dyn_option_subconfig,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
|
is_default,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ class Base:
|
||||||
)
|
)
|
||||||
for param in chain(prop.params.args, prop.params.kwargs.values()):
|
for param in chain(prop.params.args, prop.params.kwargs.values()):
|
||||||
if isinstance(param, ParamOption):
|
if isinstance(param, ParamOption):
|
||||||
param.option._add_dependency(self)
|
param.option._add_dependency(self, "property")
|
||||||
if properties:
|
if properties:
|
||||||
_setattr(self, "_properties", properties)
|
_setattr(self, "_properties", properties)
|
||||||
self.set_informations(informations)
|
self.set_informations(informations)
|
||||||
|
|
@ -150,11 +150,12 @@ class Base:
|
||||||
def _add_dependency(
|
def _add_dependency(
|
||||||
self,
|
self,
|
||||||
option,
|
option,
|
||||||
|
type_,
|
||||||
is_identifier: bool = False,
|
is_identifier: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
woption = weakref.ref(option)
|
woption = weakref.ref(option)
|
||||||
options = self.get_dependencies(None)
|
options = self.get_dependencies(None)
|
||||||
options.add(woption)
|
options.add((type_ == "default", woption))
|
||||||
self._dependencies = tuple(
|
self._dependencies = tuple(
|
||||||
options
|
options
|
||||||
) # pylint: disable=attribute-defined-outside-init
|
) # pylint: disable=attribute-defined-outside-init
|
||||||
|
|
@ -399,7 +400,11 @@ class BaseOption(Base):
|
||||||
for param in chain(value.params.args, value.params.kwargs.values()):
|
for param in chain(value.params.args, value.params.kwargs.values()):
|
||||||
if isinstance(param, ParamOption):
|
if isinstance(param, ParamOption):
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
param.option._add_dependency(self, is_identifier=is_identifier)
|
if is_identifier:
|
||||||
|
type_ = "identifier"
|
||||||
|
else:
|
||||||
|
type_ = "default"
|
||||||
|
param.option._add_dependency(self, type_, is_identifier=is_identifier)
|
||||||
self._has_dependency = True
|
self._has_dependency = True
|
||||||
elif isinstance(param, ParamInformation):
|
elif isinstance(param, ParamInformation):
|
||||||
dest = self
|
dest = self
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class ChoiceOption(Option):
|
||||||
if isinstance(values, Calculation):
|
if isinstance(values, Calculation):
|
||||||
for param in chain(values.params.args, values.params.kwargs.values()):
|
for param in chain(values.params.args, values.params.kwargs.values()):
|
||||||
if isinstance(param, ParamOption):
|
if isinstance(param, ParamOption):
|
||||||
param.option._add_dependency(self)
|
param.option._add_dependency(self, "choice")
|
||||||
elif not isinstance(values, tuple):
|
elif not isinstance(values, tuple):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
_("values must be a tuple or a calculation for {0}").format(name)
|
_("values must be a tuple or a calculation for {0}").format(name)
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class Leadership(OptionDescription):
|
||||||
# remove empty property for follower
|
# remove empty property for follower
|
||||||
child._properties = frozenset(child._properties - {"empty", "unique"})
|
child._properties = frozenset(child._properties - {"empty", "unique"})
|
||||||
followers.append(child)
|
followers.append(child)
|
||||||
child._add_dependency(self)
|
child._add_dependency(self, "leadership")
|
||||||
child._leadership = weakref.ref(self)
|
child._leadership = weakref.ref(self)
|
||||||
if __debug__:
|
if __debug__:
|
||||||
leader = children[0]
|
leader = children[0]
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class SymLinkOption(BaseOption):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._opt = opt
|
self._opt = opt
|
||||||
self._leadership = None
|
self._leadership = None
|
||||||
opt._add_dependency(self)
|
opt._add_dependency(self, "symlink")
|
||||||
|
|
||||||
def __getattr__(
|
def __getattr__(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,29 @@ RW_REMOVE = frozenset(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
PROPERTIES_MAKE_SENSE = (
|
||||||
|
"cache"
|
||||||
|
"demoting_error_warning",
|
||||||
|
"disabled",
|
||||||
|
"empty",
|
||||||
|
"everything_frozen",
|
||||||
|
"expire",
|
||||||
|
"force_default_on_freeze",
|
||||||
|
"force_metaconfig_on_freeze",
|
||||||
|
"force_store_value",
|
||||||
|
"frozen",
|
||||||
|
"hidden",
|
||||||
|
"mandatory",
|
||||||
|
"notempty",
|
||||||
|
"notunique",
|
||||||
|
"novalidator",
|
||||||
|
"permissive",
|
||||||
|
"unique",
|
||||||
|
"validator",
|
||||||
|
"warnings",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
FORBIDDEN_SET_PROPERTIES = frozenset(["force_store_value"])
|
FORBIDDEN_SET_PROPERTIES = frozenset(["force_store_value"])
|
||||||
FORBIDDEN_SET_PERMISSIVES = frozenset(
|
FORBIDDEN_SET_PERMISSIVES = frozenset(
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -511,9 +511,10 @@ class Values:
|
||||||
was present
|
was present
|
||||||
:returns: a `setting.owners.Owner` object
|
:returns: a `setting.owners.Owner` object
|
||||||
"""
|
"""
|
||||||
|
s_properties = subconfig.properties
|
||||||
if (
|
if (
|
||||||
"frozen" in subconfig.properties
|
"frozen" in s_properties
|
||||||
and "force_default_on_freeze" in subconfig.properties
|
and "force_default_on_freeze" in s_properties
|
||||||
):
|
):
|
||||||
return owners.default
|
return owners.default
|
||||||
if only_default:
|
if only_default:
|
||||||
|
|
@ -531,8 +532,8 @@ class Values:
|
||||||
)[1]
|
)[1]
|
||||||
if validate_meta is not False and (
|
if validate_meta is not False and (
|
||||||
owner is owners.default
|
owner is owners.default
|
||||||
or "frozen" in subconfig.properties
|
or "frozen" in s_properties
|
||||||
and "force_metaconfig_on_freeze" in subconfig.properties
|
and "force_metaconfig_on_freeze" in s_properties
|
||||||
):
|
):
|
||||||
msubconfig = self._get_modified_parent(subconfig)
|
msubconfig = self._get_modified_parent(subconfig)
|
||||||
if msubconfig is not None:
|
if msubconfig is not None:
|
||||||
|
|
@ -541,7 +542,7 @@ class Values:
|
||||||
msubconfig,
|
msubconfig,
|
||||||
only_default=only_default,
|
only_default=only_default,
|
||||||
)
|
)
|
||||||
elif "force_metaconfig_on_freeze" in subconfig.properties:
|
elif "force_metaconfig_on_freeze" in s_properties:
|
||||||
owner = owners.default
|
owner = owners.default
|
||||||
return owner
|
return owner
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue