From d05feb78f9468fd154e945bc7dee80209a76b26c Mon Sep 17 00:00:00 2001 From: gwen Date: Mon, 13 Aug 2012 09:32:33 +0200 Subject: [PATCH] suppression of the notion of normal and expert mode --- doc/status.txt | 21 +++++++++++---------- test/test_option_setting.py | 10 ---------- tiramisu/basetype.py | 11 ----------- tiramisu/config.py | 18 ++---------------- tiramisu/error.py | 2 -- tiramisu/option.py | 6 +++--- 6 files changed, 16 insertions(+), 52 deletions(-) diff --git a/doc/status.txt b/doc/status.txt index 23de627..695d1fb 100644 --- a/doc/status.txt +++ b/doc/status.txt @@ -92,19 +92,20 @@ corresponding convenience API provided: `enable()`: set the `disabled` attribute to `False` -mode +.. + mode - a mode is `normal` or `expert`, just a category of `Option()` or - group wich determines if an option is easy to choose or not, - available methods are: + a mode is `normal` or `expert`, just a category of `Option()` or + group wich determines if an option is easy to choose or not, + available methods are: - `get_mode()`: - returns the current mode - - `set_mode(mode)`: - sets a new mode + `get_mode()`: + returns the current mode + + `set_mode(mode)`: + sets a new mode - see it in :api:`option.ModeBaseType` + see it in :api:`option.ModeBaseType` Value owners ------------- diff --git a/test/test_option_setting.py b/test/test_option_setting.py index 2b7b88c..672034b 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -250,16 +250,6 @@ def test_setoption_from_option(): cfg = Config(descr) booloption.setoption(cfg, False, 'owner') assert cfg.bool == False -# ____________________________________________________________ -def test_set_mode_in_config(): - booloption = BoolOption('bool', 'Test boolean option', default=True, - mode='expert') - descr = OptionDescription('descr', '', [booloption]) - cfg = Config(descr) - cfg.cfgimpl_set_mode('expert') - raises(ModeOptionError, "cfg.bool") - cfg.cfgimpl_set_mode('normal') - assert cfg.bool == True #____________________________________________________________ def test_dwim_set(): descr = OptionDescription("opt", "", [ diff --git a/tiramisu/basetype.py b/tiramisu/basetype.py index 3176849..3f8e0c7 100644 --- a/tiramisu/basetype.py +++ b/tiramisu/basetype.py @@ -20,8 +20,6 @@ # the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/ # the whole pypy projet is under MIT licence # ____________________________________________________________ -# Option and OptionDescription modes -modes = ['normal', 'expert'] class HiddenBaseType(object): hidden = False @@ -42,12 +40,3 @@ class DisabledBaseType(object): def _is_disabled(self): return self.disabled -class ModeBaseType(object): - mode = 'normal' - def get_mode(self): - return self.mode - def set_mode(self, mode): - if mode not in modes: - raise TypeError("Unknown mode: {0}".format(mode)) - self.mode = mode - diff --git a/tiramisu/config.py b/tiramisu/config.py index 91720f7..d9db3b2 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -24,9 +24,9 @@ from copy import copy from tiramisu.error import (HiddenOptionError, ConfigError, NotFoundError, AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound, SpecialOwnersError, MandatoryError, MethodCallError, - DisabledOptionError, ModeOptionError) + DisabledOptionError) from tiramisu.option import (OptionDescription, Option, SymLinkOption, group_types, - Multi, apply_requires, modes) + Multi, apply_requires) from tiramisu.autolib import special_owners, special_owner_factory # ______________________________________________________________________ # generic owner. 'default' is the general config owner after init time @@ -39,7 +39,6 @@ class Config(object): _cfgimpl_frozen = False _cfgimpl_owner = default_owner _cfgimpl_toplevel = None - _cfgimpl_mode = 'normal' def __init__(self, descr, parent=None, **overrides): self._cfgimpl_descr = descr @@ -184,12 +183,6 @@ class Config(object): (opt_or_descr._is_disabled() or self._cfgimpl_descr._is_disabled()): raise DisabledOptionError("this option is disabled:" " {0}".format(name)) - # expert options - # XXX currently doesn't look at the group, is it really necessary ? - if self._cfgimpl_toplevel._cfgimpl_mode != 'normal': - if opt_or_descr.get_mode() != 'normal': - raise ModeOptionError("this option's mode is not normal:" - " {0}".format(name)) def __getattr__(self, name): # attribute access by passing a path, @@ -441,13 +434,6 @@ class Config(object): rootconfig._cfgimpl_disabled = True rootconfig._cfgimpl_mandatory = True - def cfgimpl_set_mode(self, mode): - # normal or expert mode - rootconfig = self._cfgimpl_get_toplevel() - if mode not in modes: - raise ConfigError("mode {0} not available".format(mode)) - rootconfig._cfgimpl_mode = mode - def cfgimpl_read_write(self): # hung up on freeze, hidden and disabled concepts self.cfgimpl_unfreeze() diff --git a/tiramisu/error.py b/tiramisu/error.py index 1ca0901..0ef3ae3 100644 --- a/tiramisu/error.py +++ b/tiramisu/error.py @@ -22,6 +22,4 @@ class MandatoryError(Exception): pass class SpecialOwnersError(Exception): pass -class ModeOptionError(Exception): - pass diff --git a/tiramisu/option.py b/tiramisu/option.py index 58c1b77..73652dd 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -21,7 +21,7 @@ # the whole pypy projet is under MIT licence # ____________________________________________________________ from tiramisu.autolib import special_owners -from tiramisu.basetype import HiddenBaseType, DisabledBaseType, ModeBaseType, modes +from tiramisu.basetype import HiddenBaseType, DisabledBaseType from tiramisu.error import (ConfigError, ConflictConfigError, NotFoundError, SpecialOwnersError, RequiresError, RequirementRecursionError) available_actions = ['hide', 'show', 'enable', 'disable'] @@ -80,7 +80,7 @@ class Multi(list): super(Multi, self).pop(key) # ____________________________________________________________ # -class Option(HiddenBaseType, DisabledBaseType, ModeBaseType): +class Option(HiddenBaseType, DisabledBaseType): #reminder: an Option object is **not** a container for the value _frozen = False def __init__(self, name, doc, default=None, default_multi=None, @@ -379,7 +379,7 @@ class ArbitraryOption(Option): return self.defaultfactory() return self.default -class OptionDescription(HiddenBaseType, DisabledBaseType, ModeBaseType): +class OptionDescription(HiddenBaseType, DisabledBaseType): group_type = 'default' def __init__(self, name, doc, children, requires=None):