Merge pull request #146 from teto/module_inherit_settings
Settings are inherited between modules
This commit is contained in:
commit
523975cf39
@ -13,7 +13,7 @@ pep8 --ignore E501 i3pystatus tests
|
|||||||
# Check that the setup.py script works
|
# Check that the setup.py script works
|
||||||
rm -rf ${BUILD}/test-install ${BUILD}/test-install-bin
|
rm -rf ${BUILD}/test-install ${BUILD}/test-install-bin
|
||||||
mkdir ${BUILD}/test-install ${BUILD}/test-install-bin
|
mkdir ${BUILD}/test-install ${BUILD}/test-install-bin
|
||||||
PYTHONPATH=${BUILD}/test-install python setup.py --quiet install --install-lib ${BUILD}/test-install --install-scripts ${BUILD}/test-install-bin
|
PYTHONPATH=${BUILD}/test-install python3 setup.py --quiet install --install-lib ${BUILD}/test-install --install-scripts ${BUILD}/test-install-bin
|
||||||
|
|
||||||
test -f ${BUILD}/test-install-bin/i3pystatus
|
test -f ${BUILD}/test-install-bin/i3pystatus
|
||||||
|
|
||||||
|
@ -2,4 +2,4 @@ pytest>=2.5
|
|||||||
sphinx>=1.1
|
sphinx>=1.1
|
||||||
colour>=0.0.5
|
colour>=0.0.5
|
||||||
mock>=1.0
|
mock>=1.0
|
||||||
pep8>=1.5
|
pep8>=1.5.7
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
from i3pystatus.core.util import KeyConstraintDict
|
from i3pystatus.core.util import KeyConstraintDict
|
||||||
from i3pystatus.core.exceptions import ConfigKeyError, ConfigMissingError
|
from i3pystatus.core.exceptions import ConfigKeyError, ConfigMissingError
|
||||||
|
import inspect
|
||||||
|
|
||||||
|
|
||||||
class SettingsBase:
|
class SettingsBase:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Support class for providing a nice and flexible settings interface
|
Support class for providing a nice and flexible settings interface
|
||||||
|
|
||||||
@ -15,16 +17,22 @@ class SettingsBase:
|
|||||||
Settings are stored as attributes of self.
|
Settings are stored as attributes of self.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = tuple()
|
settings = (
|
||||||
|
("enable_log", "Set to true to log error to .i3pystatus-<pid> file"),
|
||||||
|
)
|
||||||
|
|
||||||
"""settings should be tuple containing two types of elements:
|
"""settings should be tuple containing two types of elements:
|
||||||
|
|
||||||
* bare strings, which must be valid Python identifiers.
|
* bare strings, which must be valid Python identifiers.
|
||||||
* two-tuples, the first element being a identifier (as above) and the second
|
* two-tuples, the first element being a identifier (as above) and the second a docstring for the particular setting
|
||||||
a docstring for the particular setting"""
|
|
||||||
|
"""
|
||||||
|
|
||||||
required = tuple()
|
required = tuple()
|
||||||
"""required can list settings which are required"""
|
"""required can list settings which are required"""
|
||||||
|
|
||||||
|
enable_log = False
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
def get_argument_dict(args, kwargs):
|
def get_argument_dict(args, kwargs):
|
||||||
if len(args) == 1 and not kwargs:
|
if len(args) == 1 and not kwargs:
|
||||||
@ -33,9 +41,20 @@ class SettingsBase:
|
|||||||
return args[0]
|
return args[0]
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
self.settings = self.flatten_settings(self.settings)
|
def merge_with_parents_settings():
|
||||||
|
|
||||||
sm = KeyConstraintDict(self.settings, self.required)
|
settings = tuple()
|
||||||
|
|
||||||
|
# getmro returns base classes according to Method Resolution Order
|
||||||
|
for cls in inspect.getmro(self.__class__):
|
||||||
|
if hasattr(cls, "settings"):
|
||||||
|
settings = settings + cls.settings
|
||||||
|
return settings
|
||||||
|
|
||||||
|
settings = merge_with_parents_settings()
|
||||||
|
settings = self.flatten_settings(settings)
|
||||||
|
|
||||||
|
sm = KeyConstraintDict(settings, self.required)
|
||||||
settings_source = get_argument_dict(args, kwargs)
|
settings_source = get_argument_dict(args, kwargs)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -11,7 +11,7 @@ class IntervalModuleMetaTest(unittest.TestCase):
|
|||||||
def test_no_settings(self):
|
def test_no_settings(self):
|
||||||
class NoSettings(IntervalModule):
|
class NoSettings(IntervalModule):
|
||||||
pass
|
pass
|
||||||
self.assertEqual(NoSettings.settings, ('interval',))
|
self.assertTrue('interval' in NoSettings.settings)
|
||||||
|
|
||||||
def test_no_interval_setting(self):
|
def test_no_interval_setting(self):
|
||||||
class NoIntervalSetting(IntervalModule):
|
class NoIntervalSetting(IntervalModule):
|
||||||
|
Loading…
Reference in New Issue
Block a user