From 05404e89bcc82433d5ef4cd8f5652e0c2eea0758 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 7 Sep 2018 06:14:52 +0200 Subject: [PATCH] remove _getcontext in Settings --- test/auto/test_auto.py | 147 +++++++++++++++++++++-------------------- tiramisu/api.py | 21 ++++-- tiramisu/config.py | 24 +++---- tiramisu/setting.py | 59 ++++++++--------- tiramisu/value.py | 7 +- 5 files changed, 128 insertions(+), 130 deletions(-) diff --git a/test/auto/test_auto.py b/test/auto/test_auto.py index a412f33..6e58bcf 100644 --- a/test/auto/test_auto.py +++ b/test/auto/test_auto.py @@ -71,7 +71,7 @@ def autocheck(func): @autocheck -def autocheck_option_multi(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_option_multi(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): cfg.option(pathread).option.ismulti() cfg.option(pathread).option.issubmulti() @@ -101,7 +101,7 @@ def autocheck_option_multi(cfg, pathread, pathwrite, confread, confwrite, **kwar @autocheck -def autocheck_default_owner(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_default_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): """check different value of owner when any value is set to this option """ isslave = cfg.unrestraint.option(pathread).option.isslave() @@ -195,7 +195,7 @@ def _autocheck_default_value(cfg, path, conf, **kwargs): @autocheck -def autocheck_default_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_default_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): _autocheck_default_value(cfg, pathread, confread, **kwargs) if confread != confwrite: _autocheck_default_value(cfg, pathread, confwrite, **kwargs) @@ -276,12 +276,12 @@ def _set_value(cfg, pathwrite, conf, **kwargs): @autocheck -def autocheck_set_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_set_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): _set_value(cfg, pathwrite, confwrite, **kwargs) @autocheck -def autocheck_get_value_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_get_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): multi = cfg.unrestraint.option(pathread).option.ismulti() submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() isslave = cfg.unrestraint.option(pathread).option.isslave() @@ -390,7 +390,7 @@ def _autocheck_get_value(cfg, pathread, conf, **kwargs): @autocheck -def autocheck_get_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_get_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): _set_value(cfg, pathwrite, confwrite, set_permissive=False, **kwargs) _autocheck_get_value(cfg, pathread, confread, set_permissive=False, **kwargs) if pathread.endswith('val1'): @@ -403,7 +403,7 @@ def autocheck_get_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs) @autocheck -def autocheck_value_slave(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_value_slave(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): isslave = cfg.unrestraint.option(pathread).option.isslave() if not isslave: if kwargs.get('propertyerror', False): @@ -454,7 +454,7 @@ def autocheck_value_slave(cfg, pathread, pathwrite, confread, confwrite, **kwarg @autocheck -def autocheck_reset_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_reset_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a multi, a master or a slave multi = cfg.unrestraint.option(pathread).option.ismulti() submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() @@ -509,7 +509,7 @@ def autocheck_reset_value(cfg, pathread, pathwrite, confread, confwrite, **kwarg @autocheck -def autocheck_append_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_append_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): ismaster = cfg.unrestraint.option(pathread).option.ismaster() submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() if not ismaster: @@ -546,7 +546,7 @@ def autocheck_append_value(cfg, pathread, pathwrite, confread, confwrite, **kwar @autocheck -def autocheck_pop_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_pop_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): ismaster = cfg.unrestraint.option(pathread).option.ismaster() submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() if not ismaster: @@ -597,7 +597,7 @@ def autocheck_pop_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs) @autocheck -def autocheck_reset_value_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_reset_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a multi, a master or a slave isslave = cfg.unrestraint.option(pathread).option.isslave() _set_value(cfg, pathwrite, confwrite, **kwargs) @@ -624,7 +624,7 @@ def autocheck_reset_value_permissive(cfg, pathread, pathwrite, confread, confwri @autocheck -def autocheck_display(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): """re set value """ if kwargs['callback']: @@ -655,7 +655,7 @@ def _getproperties(multi, isslave, kwargs): return default_props, frozenset(properties) -def _check_properties(cfg, pathread, conf, kwargs, props_permissive, props): +def _check_properties(cfg, mcfg, pathread, conf, kwargs, props_permissive, props): if not cfg.unrestraint.option(pathread).option.isslave(): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert set(cfg.config(conf).option(pathread).property.get()) == set(props_permissive) @@ -704,7 +704,7 @@ def _check_properties(cfg, pathread, conf, kwargs, props_permissive, props): @autocheck -def autocheck_property(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): """get property from path """ # check if is a multi or a slave @@ -713,20 +713,20 @@ def autocheck_property(cfg, pathread, pathwrite, confread, confwrite, **kwargs): default_props, properties = _getproperties(multi, isslave, kwargs) - _check_properties(cfg, pathread, confread, kwargs, default_props, default_props) + _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) if confread != confwrite: - _check_properties(cfg, pathread, confwrite, kwargs, default_props, default_props) + _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) # set properties without permissive for prop in properties: - cfg.unrestraint.config(confwrite).option(pathwrite).property.add(prop) - _check_properties(cfg, pathread, confread, kwargs, properties, properties) - if confread != confwrite: - _check_properties(cfg, pathread, confwrite, kwargs, properties, properties) + cfg.unrestraint.config(confread).option(pathwrite).property.add(prop) + _check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties) + #if confread != confwrite: + # _check_properties(cfg, mcfg, pathread, confwrite, kwargs, properties, properties) -def _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a multi or a slave multi = cfg.unrestraint.option(pathread).option.ismulti() isslave = cfg.unrestraint.option(pathread).option.isslave() @@ -744,30 +744,30 @@ def _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs default_props.extend(extra_properties) default_props, properties = _getproperties(multi, isslave, kwargs) - _check_properties(cfg, pathread, confwrite, kwargs, default_props, default_props) - if confwrite != confread: - _check_properties(cfg, pathread, confread, kwargs, default_props, default_props) + _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) + #if confwrite != confread: + # _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) # set properties with permissive for prop in properties: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - cfg.config(confwrite).option(pathwrite).property.add(prop) + cfg.config(confread).option(pathwrite).property.add(prop) if not kwargs.get('propertyerror', False): - cfg.forcepermissive.config(confwrite).option(pathwrite).property.add(prop) - cfg.unrestraint.config(confwrite).option(pathwrite).property.add(prop) + cfg.forcepermissive.config(confread).option(pathwrite).property.add(prop) + cfg.unrestraint.config(confread).option(pathwrite).property.add(prop) - _check_properties(cfg, pathread, confwrite, kwargs, properties, properties) - if confwrite != confread: - _check_properties(cfg, pathread, confread, kwargs, properties, properties) + _check_properties(cfg, mcfg, pathread, confwrite, kwargs, properties, properties) + #if confwrite != confread: + # _check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties) @autocheck -def autocheck_property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): - _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs) +def autocheck_property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): + _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs) @autocheck -def autocheck_reset_property(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_reset_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): """check properties after set with permissive """ # check if is a multi or a slave @@ -775,36 +775,36 @@ def autocheck_reset_property(cfg, pathread, pathwrite, confread, confwrite, **kw isslave = cfg.unrestraint.option(pathread).option.isslave() default_props, properties = _getproperties(multi, isslave, kwargs) - _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs) + _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs) # reset properties without permissive cfg.unrestraint.config(confwrite).option(pathwrite).property.reset() - _check_properties(cfg, pathread, confread, kwargs, default_props, default_props) + _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) if confread != confwrite: - _check_properties(cfg, pathread, confwrite, kwargs, default_props, default_props) + _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) @autocheck -def autocheck_reset_property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_reset_property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a multi or a slave multi = cfg.unrestraint.option(pathread).option.ismulti() isslave = cfg.unrestraint.option(pathread).option.isslave() default_props, properties = _getproperties(multi, isslave, kwargs) - _property_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs) + _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs) for prop in properties: cfg.unrestraint.option(pathwrite).property.add(prop) cfg.unrestraint.option(pathwrite).property.reset() - _check_properties(cfg, pathread, confwrite, kwargs, default_props, default_props) + _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) if confread != confwrite: - _check_properties(cfg, pathread, confread, kwargs, default_props, default_props) + _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) @autocheck -def autocheck_context_owner(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_context_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): owner = cfg.owner.get() assert owner == kwargs['owner'] @@ -838,7 +838,7 @@ def _check_owner(cfg, pathread, conf, kwargs, owner, permissive_owner): @autocheck -def autocheck_owner_with_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): """value is now changed, check owner in this case """ _set_value(cfg, pathwrite, confwrite, **kwargs) @@ -848,7 +848,7 @@ def autocheck_owner_with_value(cfg, pathread, pathwrite, confread, confwrite, ** @autocheck -def autocheck_default_owner_with_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_default_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): isslave = cfg.unrestraint.option(pathread).option.isslave() _set_value(cfg, pathwrite, confwrite, **kwargs) @@ -874,7 +874,7 @@ def autocheck_default_owner_with_value(cfg, pathread, pathwrite, confread, confw @autocheck -def autocheck_default_owner_with_value_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_default_owner_with_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): # check if is a isslave isslave = cfg.unrestraint.option(pathread).option.isslave() @@ -896,7 +896,7 @@ def autocheck_default_owner_with_value_permissive(cfg, pathread, pathwrite, conf @autocheck -def autocheck_set_owner_no_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_set_owner_no_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): isslave = cfg.unrestraint.option(pathread).option.isslave() if not kwargs.get('propertyerror', False): if not isslave: @@ -906,7 +906,7 @@ def autocheck_set_owner_no_value(cfg, pathread, pathwrite, confread, confwrite, @autocheck -def autocheck_set_owner(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_set_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): # test set owner without permissive isslave = cfg.unrestraint.option(pathread).option.isslave() @@ -933,7 +933,7 @@ def autocheck_set_owner(cfg, pathread, pathwrite, confread, confwrite, **kwargs) @autocheck -def autocheck_set_owner_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_set_owner_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): isslave = cfg.unrestraint.option(pathread).option.isslave() _set_value(cfg, pathwrite, confwrite, **kwargs) @@ -958,7 +958,7 @@ def autocheck_set_owner_permissive(cfg, pathread, pathwrite, confread, confwrite @autocheck -def autocheck_option(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_option(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): expected_name = pathread.split('.')[-1] if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): current_name = cfg.option(pathread).option.name() @@ -991,13 +991,13 @@ def autocheck_option(cfg, pathread, pathwrite, confread, confwrite, **kwargs): @autocheck -def autocheck_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): """test permissive for hidden and disabled value """ # no permissive before - assert cfg.unrestraint.config(confread).option(pathread).permissive.get() == frozenset() + assert cfg.unrestraint.config(confwrite).option(pathread).permissive.get() == frozenset() if kwargs.get('permissive_od', False): - assert cfg.unrestraint.config(confread).option(pathread.rsplit('.', 1)[0]).permissive.get() == frozenset() + assert cfg.unrestraint.config(confwrite).option(pathread.rsplit('.', 1)[0]).permissive.get() == frozenset() # cannot access to hidden value without forcepermissive # and to disabled value (with forcepermissive too) @@ -1017,8 +1017,8 @@ def autocheck_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs # have permissive assert cfg.unrestraint.config(confwrite).option(pathread).permissive.get() == frozenset(['disabled']) - if confwrite != confread: - assert cfg.unrestraint.config(confread).option(pathread).permissive.get() == frozenset(['disabled']) + #if confwrite != confread: + # assert cfg.unrestraint.config(confread).option(pathread).permissive.get() == frozenset(['disabled']) # can access to disabled value ckwargs = copy(kwargs) @@ -1042,8 +1042,8 @@ def autocheck_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs 'hidden'])) ckwargs['permissive'] = False _autocheck_default_value(cfg, pathread, confread, **ckwargs) - if confread != confwrite: - _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) + #if confread != confwrite: + # _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) # only hidden cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['hidden'])) @@ -1057,8 +1057,8 @@ def autocheck_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs ckwargs = copy(kwargs) ckwargs['permissive'] = False _autocheck_default_value(cfg, pathread, confread, **ckwargs) - if confread != confwrite: - _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) + #if confread != confwrite: + # _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) # no permissive cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset()) @@ -1070,12 +1070,12 @@ def autocheck_permissive(cfg, pathread, pathwrite, confread, confwrite, **kwargs _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset()) _autocheck_default_value(cfg, pathread, confread, **kwargs) - if confread != confwrite: - _autocheck_default_value(cfg, pathread, confwrite, **kwargs) + #if confread != confwrite: + # _autocheck_default_value(cfg, pathread, confwrite, **kwargs) @autocheck -def autocheck_option_get(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_option_get(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): if '.' in pathread: name = pathread.rsplit('.', 1)[1] else: @@ -1084,7 +1084,7 @@ def autocheck_option_get(cfg, pathread, pathwrite, confread, confwrite, **kwargs @autocheck -def autocheck_find(cfg, pathread, pathwrite, confread, confwrite, **kwargs): +def autocheck_find(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): def _getoption(opt): opt = opt.option.get() if opt.impl_is_dynsymlinkoption(): @@ -1317,20 +1317,22 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c for func in autocheck_registers: cfg_name = 'conftest' + str(idx) idx += 1 - ncfg = cfg.config.duplicate(session_id=cfg_name) + ncfg = cfg.config.copy(session_id=cfg_name) if meta: confwrite = None confread = cfg_name - ncfg = MetaConfig([ncfg], session_id='metatest') + mcfg = MetaConfig([ncfg], session_id='metatest') weakrefs.append(weakref.ref(cfg)) + else: + mcfg = ncfg ckwargs = copy(kwargs) if meta: - ncfg.owner.set('meta') + mcfg.owner.set('meta') ckwargs['owner'] = owners.meta else: ckwargs['owner'] = OWNER - if ncfg.unrestraint.option(path).option.isslave(): + if mcfg.unrestraint.option(path).option.isslave(): dirname = path.rsplit('.', 1)[0] master_path = dirname + '.first' master_path_2 = None @@ -1343,7 +1345,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c else: value = LIST_SECOND_VALUE with warnings.catch_warnings(record=True) as w: - ncfg.option(master_path).value.set(value) + mcfg.option(master_path).value.set(value) ckwargs['make_dict'][master_path] = value ckwargs['make_dict_value'][master_path] = value if symlink: @@ -1351,7 +1353,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c ckwargs['make_dict_value'][master_path + 'link'] = value if master_path_2: with warnings.catch_warnings(record=True) as w: - ncfg.option(master_path_2).value.set(value) + mcfg.option(master_path_2).value.set(value) ckwargs['make_dict'][master_path_2] = value ckwargs['make_dict_value'][master_path_2] = value if symlink: @@ -1408,11 +1410,12 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c do('val2', 'val1') ncfg.property.read_write() + mcfg.property.read_write() if req: name = 'extraoptrequire' if symlink: name += 'link' - ncfg.option(name).value.set('value') + mcfg.option(name).value.set('value') if 'permissive' in ckwargs and not 'permissive_od' in ckwargs or \ 'propertyerror' in ckwargs and not 'propertyerror_od' in ckwargs: for to_del in ['permissive', 'propertyerror', 'extra_properties']: @@ -1426,7 +1429,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c else: pathwrite = path try: - func(ncfg, pathread, pathwrite, confread, confwrite, **ckwargs) + func(mcfg, ncfg, pathread, pathwrite, confread, confwrite, **ckwargs) except Exception as err: msg = u'error in function {} for {}'.format(func.__name__, path) if multi is True: @@ -1441,6 +1444,8 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c msg += u' (symlink)' print(u'{}: {}'.format(msg, ckwargs)) raise err + if meta: + del mcfg del ncfg @@ -1451,7 +1456,7 @@ def check_deref(weakrefs): assert wrf() is None -def make_conf(options, meta, multi, default, default_multi, require, consistency, callback, symlink): +def make_conf(options, multi, default, default_multi, require, consistency, callback, symlink): weakrefs = [] dyn = [] goptions = [] @@ -1760,7 +1765,7 @@ def test_options(paths): continue if multi is False and default_multi: continue - cfg, weakrefs, dyn = make_conf(paths, meta, multi, default, default_multi, require, consistency, callback, symlink) + cfg, weakrefs, dyn = make_conf(paths, multi, default, default_multi, require, consistency, callback, symlink) if cfg is None: continue if dyn: diff --git a/tiramisu/api.py b/tiramisu/api.py index 597f361..74fa33d 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -328,7 +328,8 @@ class TiramisuOptionProperty(CommonTiramisuOption): apply_requires=False) self.settings.setproperties(self.option_bag.path, props | {prop}, - self.option_bag) + self.option_bag, + self.option_bag.config_bag.context) def pop(self, prop): """remove new property for an option""" @@ -337,12 +338,14 @@ class TiramisuOptionProperty(CommonTiramisuOption): apply_requires=False) self.settings.setproperties(self.option_bag.path, props - {prop}, - self.option_bag) + self.option_bag, + self.option_bag.config_bag.context) def reset(self): """reset all personalised properties""" option = self.option_bag.option - self.settings.reset(self.option_bag) + self.settings.reset(self.option_bag, + self.option_bag.config_bag.context) class TiramisuOptionPermissive(CommonTiramisuOption): @@ -734,7 +737,7 @@ class TiramisuContextProperty(TiramisuContext): def read_only(self): """set configuration to read only mode""" settings = self.config_bag.context.cfgimpl_get_settings() - settings.read_only() + settings.read_only(self.config_bag.context) try: del self.config_bag.properties except AttributeError: @@ -743,7 +746,7 @@ class TiramisuContextProperty(TiramisuContext): def read_write(self): """set configuration to read and write mode""" settings = self.config_bag.context.cfgimpl_get_settings() - settings.read_write() + settings.read_write(self.config_bag.context) # #FIXME ? permissives = frozenset(settings.get_context_permissives() | frozenset(['hidden'])) settings.set_context_permissives(permissives) @@ -772,11 +775,15 @@ class TiramisuContextProperty(TiramisuContext): def set(self, props): """personalise configuration properties""" - self.config_bag.context.cfgimpl_get_settings().set_context_properties(props) + context = self.config_bag.context + context.cfgimpl_get_settings().set_context_properties(props, + context) def reset(self): """remove configuration properties""" - self.config_bag.context.cfgimpl_get_settings().reset(None) + context = self.config_bag.context + context.cfgimpl_get_settings().reset(None, + context) def exportation(self): """export configuration properties""" diff --git a/tiramisu/config.py b/tiramisu/config.py index cdeb385..0f32797 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -746,13 +746,11 @@ class KernelConfig(_CommonConfig): raise ConfigError(_('cannot set dynoptiondescription object has root optiondescription')) if force_settings is not None and force_values is not None: if isinstance(force_settings, tuple): - self._impl_settings = Settings(self, - force_settings[0], + self._impl_settings = Settings(force_settings[0], force_settings[1]) else: self._impl_settings = force_settings - self._impl_values = Values(self, - force_values) + self._impl_values = Values(force_values) else: properties, permissives, values, session_id = get_storages(self, session_id, @@ -760,11 +758,9 @@ class KernelConfig(_CommonConfig): storage=storage) if not valid_name(session_id): raise ValueError(_("invalid session ID: {0} for config").format(session_id)) - self._impl_settings = Settings(self, - properties, + self._impl_settings = Settings(properties, permissives) - self._impl_values = Values(self, - values) + self._impl_values = Values(values) super().__init__(descr, weakref.ref(self), ConfigBag(self), @@ -815,11 +811,9 @@ class KernelGroupConfig(_CommonConfig): self._impl_children = children if force_settings is not None and force_values is not None: - self._impl_settings = Settings(self, - force_settings[0], + self._impl_settings = Settings(force_settings[0], force_settings[1]) - self._impl_values = Values(self, - force_values) + self._impl_values = Values(force_values) else: properties, permissives, values, session_id = get_storages(self, session_id, @@ -827,11 +821,9 @@ class KernelGroupConfig(_CommonConfig): storage=storage) if not valid_name(session_id): raise ValueError(_("invalid session ID: {0} for config").format(session_id)) - self._impl_settings = Settings(self, - properties, + self._impl_settings = Settings(properties, permissives) - self._impl_values = Values(self, - values) + self._impl_values = Values(values) self._impl_meta = None super().__init__(_descr, diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 723525a..8081247 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -319,9 +319,11 @@ undefined = Undefined() #____________________________________________________________ class Settings(object): "``config.Config()``'s configuration options settings" - __slots__ = ('context', '_owner', '_p_', '_pp_', '__weakref__') + __slots__ = ('_owner', '_p_', '_pp_', '__weakref__') - def __init__(self, context, properties, permissives): + def __init__(self, + properties, + permissives): """ initializer @@ -333,21 +335,9 @@ class Settings(object): """ # generic owner self._owner = owners.user - self.context = weakref.ref(context) self._p_ = properties self._pp_ = permissives - def _getcontext(self): - """context could be None, we need to test it - context is None only if all reference to `Config` object is deleted - (for example we delete a `Config` and we manipulate a reference to - old `SubConfig`, `Values`, `Multi` or `Settings`) - """ - context = self.context() - if context is None: # pragma: no cover - raise ConfigError(_('the context does not exist anymore')) - return context - #____________________________________________________________ # get properties and permissive methods @@ -475,7 +465,7 @@ class Settings(object): if not current_requires: return calc_properties - context = self._getcontext() + context = option_bag.config_bag.context all_properties = None for requires in current_requires: for require in requires: @@ -574,15 +564,18 @@ class Settings(object): #____________________________________________________________ # set methods def set_context_properties(self, - properties): + properties, + context): self.setproperties(None, properties, - None) + None, + context) def setproperties(self, path, properties, - option_bag): + option_bag, + context): """save properties for specified path (never save properties if same has option properties) """ @@ -611,7 +604,7 @@ class Settings(object): self._p_.setproperties(path, properties) #values too because of slave values could have a PropertiesOptionError has value - self._getcontext().cfgimpl_reset_cache(option_bag) + context.cfgimpl_reset_cache(option_bag) if option_bag is not None: try: del option_bag.properties @@ -651,14 +644,14 @@ class Settings(object): ' '.join(forbidden_permissives))) self._pp_.setpermissives(path, permissives) if option_bag is not None: - self._getcontext().cfgimpl_reset_cache(option_bag) + option_bag.config_bag.context.cfgimpl_reset_cache(option_bag) #____________________________________________________________ # reset methods def reset(self, - option_bag): - # all_properties=False): + option_bag, + context): if option_bag is None: opt = None else: @@ -677,7 +670,7 @@ class Settings(object): else: path = None self._p_.delproperties(path) - self._getcontext().cfgimpl_reset_cache(option_bag) + context.cfgimpl_reset_cache(option_bag) #____________________________________________________________ # validate properties @@ -716,7 +709,7 @@ class Settings(object): value, option_bag): if 'mandatory' in option_bag.config_bag.properties: - values = self._getcontext().cfgimpl_get_values() + values = option_bag.config_bag.context.cfgimpl_get_values() is_mandatory = False if ('permissive' in option_bag.config_bag.properties) and \ 'mandatory' in option_bag.config_bag.permissives: @@ -751,7 +744,8 @@ class Settings(object): def _read(self, remove, - append): + append, + context): props = self._p_.getproperties(None, default_properties) modified = False @@ -762,17 +756,22 @@ class Settings(object): props = props | append modified = True if modified: - self.set_context_properties(frozenset(props)) + self.set_context_properties(frozenset(props), + context) - def read_only(self): + def read_only(self, + context): "convenience method to freeze, hide and disable" self._read(ro_remove, - ro_append) + ro_append, + context) - def read_write(self): + def read_write(self, + context): "convenience method to freeze, hide and disable" self._read(rw_remove, - rw_append) + rw_append, + context) #____________________________________________________________ # default owner methods diff --git a/tiramisu/value.py b/tiramisu/value.py index bc15f24..41a9d42 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -27,21 +27,17 @@ class Values(object): but the values are physicaly located here, in `Values`, wich is also responsible of a caching utility. """ - __slots__ = ('context', - '_p_', + __slots__ = ('_p_', '__weakref__') def __init__(self, - context, storage): """ Initializes the values's dict. - :param context: the context is the home config's values :param storage: where values or owners are stored """ - self.context = weakref.ref(context) # store the storage self._p_ = storage @@ -436,7 +432,6 @@ class Values(object): _commit=True): context = option_bag.config_bag.context - setting = context.cfgimpl_get_settings() hasvalue = self._p_.hasvalue(option_bag.path) if hasvalue and 'validator' in option_bag.config_bag.properties: