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
|
||||
parent = self._subconfig.parent
|
||||
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
|
||||
):
|
||||
option = woption()
|
||||
|
|
@ -428,6 +428,10 @@ class _TiramisuOptionOptionDescription:
|
|||
for subconfig in context.get_dynamic_from_dyn_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(
|
||||
TiramisuOption(
|
||||
subconfig.path,
|
||||
|
|
@ -439,6 +443,8 @@ class _TiramisuOptionOptionDescription:
|
|||
for subconfig in context.get_dynamic_from_dyn_option(
|
||||
self._subconfig, option
|
||||
):
|
||||
if is_default and subconfig.config_bag.context.get_owner(subconfig) != owners.default:
|
||||
continue
|
||||
options.append(
|
||||
TiramisuOption(
|
||||
subconfig.path,
|
||||
|
|
@ -460,13 +466,18 @@ class _TiramisuOptionOptionDescription:
|
|||
else:
|
||||
current_indexes = [None]
|
||||
for current_index in current_indexes:
|
||||
options.append(
|
||||
TiramisuOption(
|
||||
t_option = TiramisuOption(
|
||||
option.impl_getpath(),
|
||||
current_index,
|
||||
self._config_bag,
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ class CCache:
|
|||
self.reset_one_option_cache(
|
||||
subconfig,
|
||||
resetted_opts,
|
||||
False,
|
||||
)
|
||||
subconfig.config_bag.properties = subconfig.config_bag.properties | {
|
||||
"cache"
|
||||
|
|
@ -86,13 +87,16 @@ class CCache:
|
|||
self,
|
||||
subconfig,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
):
|
||||
"""reset cache for one option"""
|
||||
if subconfig.path in resetted_opts:
|
||||
return
|
||||
resetted_opts.append(subconfig.path)
|
||||
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()
|
||||
if option.issubdyn():
|
||||
# it's an option in dynoptiondescription, remove cache for all generated option
|
||||
|
|
@ -100,12 +104,14 @@ class CCache:
|
|||
subconfig,
|
||||
option,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
)
|
||||
elif option.impl_is_dynoptiondescription():
|
||||
self.reset_cache_dyn_optiondescription(
|
||||
option,
|
||||
config_bag,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
)
|
||||
else:
|
||||
option_subconfig = self.get_sub_config(
|
||||
|
|
@ -118,6 +124,7 @@ class CCache:
|
|||
self.reset_one_option_cache(
|
||||
option_subconfig,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
)
|
||||
del option
|
||||
subconfig.option.reset_cache(
|
||||
|
|
@ -149,6 +156,7 @@ class CCache:
|
|||
option,
|
||||
config_bag,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
):
|
||||
# reset cache for all chidren
|
||||
for subconfig in self.get_dynamic_from_dyn_optiondescription(
|
||||
|
|
@ -158,6 +166,7 @@ class CCache:
|
|||
self.reset_one_option_cache(
|
||||
subconfig,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
)
|
||||
for walk_subconfig in self.walk(
|
||||
subconfig,
|
||||
|
|
@ -167,6 +176,7 @@ class CCache:
|
|||
self.reset_one_option_cache(
|
||||
walk_subconfig,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
)
|
||||
|
||||
def get_dynamic_from_dyn_option(self, subconfig, option):
|
||||
|
|
@ -223,11 +233,13 @@ class CCache:
|
|||
subconfig,
|
||||
option,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
):
|
||||
for dyn_option_subconfig in self.get_dynamic_from_dyn_option(subconfig, option):
|
||||
self.reset_one_option_cache(
|
||||
dyn_option_subconfig,
|
||||
resetted_opts,
|
||||
is_default,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class Base:
|
|||
)
|
||||
for param in chain(prop.params.args, prop.params.kwargs.values()):
|
||||
if isinstance(param, ParamOption):
|
||||
param.option._add_dependency(self)
|
||||
param.option._add_dependency(self, "property")
|
||||
if properties:
|
||||
_setattr(self, "_properties", properties)
|
||||
self.set_informations(informations)
|
||||
|
|
@ -150,11 +150,12 @@ class Base:
|
|||
def _add_dependency(
|
||||
self,
|
||||
option,
|
||||
type_,
|
||||
is_identifier: bool = False,
|
||||
) -> None:
|
||||
woption = weakref.ref(option)
|
||||
options = self.get_dependencies(None)
|
||||
options.add(woption)
|
||||
options.add((type_ == "default", woption))
|
||||
self._dependencies = tuple(
|
||||
options
|
||||
) # pylint: disable=attribute-defined-outside-init
|
||||
|
|
@ -399,7 +400,11 @@ class BaseOption(Base):
|
|||
for param in chain(value.params.args, value.params.kwargs.values()):
|
||||
if isinstance(param, ParamOption):
|
||||
# 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
|
||||
elif isinstance(param, ParamInformation):
|
||||
dest = self
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class ChoiceOption(Option):
|
|||
if isinstance(values, Calculation):
|
||||
for param in chain(values.params.args, values.params.kwargs.values()):
|
||||
if isinstance(param, ParamOption):
|
||||
param.option._add_dependency(self)
|
||||
param.option._add_dependency(self, "choice")
|
||||
elif not isinstance(values, tuple):
|
||||
raise TypeError(
|
||||
_("values must be a tuple or a calculation for {0}").format(name)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Leadership(OptionDescription):
|
|||
# remove empty property for follower
|
||||
child._properties = frozenset(child._properties - {"empty", "unique"})
|
||||
followers.append(child)
|
||||
child._add_dependency(self)
|
||||
child._add_dependency(self, "leadership")
|
||||
child._leadership = weakref.ref(self)
|
||||
if __debug__:
|
||||
leader = children[0]
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class SymLinkOption(BaseOption):
|
|||
self._name = name
|
||||
self._opt = opt
|
||||
self._leadership = None
|
||||
opt._add_dependency(self)
|
||||
opt._add_dependency(self, "symlink")
|
||||
|
||||
def __getattr__(
|
||||
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_PERMISSIVES = frozenset(
|
||||
[
|
||||
|
|
|
|||
|
|
@ -511,9 +511,10 @@ class Values:
|
|||
was present
|
||||
:returns: a `setting.owners.Owner` object
|
||||
"""
|
||||
s_properties = subconfig.properties
|
||||
if (
|
||||
"frozen" in subconfig.properties
|
||||
and "force_default_on_freeze" in subconfig.properties
|
||||
"frozen" in s_properties
|
||||
and "force_default_on_freeze" in s_properties
|
||||
):
|
||||
return owners.default
|
||||
if only_default:
|
||||
|
|
@ -531,8 +532,8 @@ class Values:
|
|||
)[1]
|
||||
if validate_meta is not False and (
|
||||
owner is owners.default
|
||||
or "frozen" in subconfig.properties
|
||||
and "force_metaconfig_on_freeze" in subconfig.properties
|
||||
or "frozen" in s_properties
|
||||
and "force_metaconfig_on_freeze" in s_properties
|
||||
):
|
||||
msubconfig = self._get_modified_parent(subconfig)
|
||||
if msubconfig is not None:
|
||||
|
|
@ -541,7 +542,7 @@ class Values:
|
|||
msubconfig,
|
||||
only_default=only_default,
|
||||
)
|
||||
elif "force_metaconfig_on_freeze" in subconfig.properties:
|
||||
elif "force_metaconfig_on_freeze" in s_properties:
|
||||
owner = owners.default
|
||||
return owner
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue