Skip to content
Permalink
Browse files

core: settings: add overlay

Signed-off-by: Florian Scherf <f.scherf@pengutronix.de>
  • Loading branch information...
fscherf committed Jul 25, 2019
1 parent 485c2ac commit b717c5ea433f53f1ed3701d9fe2045a0f5898f00
Showing with 13 additions and 21 deletions.
  1. +13 −21 flamingo/core/settings/settings.py
@@ -3,15 +3,20 @@
import runpy

from . import defaults
from flamingo.core.types import OverlayObject


class Settings:
class Settings(OverlayObject):
def __init__(self):
self._values = {}
super().__init__()

self.modules = []

for i in dir(defaults):
attr = getattr(defaults, i)
for name in dir(defaults):
if name.startswith('_'):
continue

attr = getattr(defaults, name)

try:
attr_copy = deepcopy(attr)
@@ -20,30 +25,17 @@ def __init__(self):
pass

else:
self._values[i] = attr_copy
self._attrs[name] = attr_copy

def add(self, module):
if not (module.endswith('.py') or '/' in module):
module = importlib.import_module(module).__file__

values = runpy.run_path(module, init_globals=self._values)
attrs = runpy.run_path(module, init_globals=self._attrs)

self.modules.append(module)
self._values = {k: v for k, v in values.items()
if not k.startswith('_')}

def __getattribute__(self, name):
try:
return super().__getattribute__(name)

except AttributeError:
if name in self._values:
return self._values[name]

raise

def __dir__(self):
return list(set(super().__dir__() + list(self._values.keys())))
self._attrs = {k: v for k, v in attrs.items()
if not k.startswith('_')}

def __iter__(self):
ignore = ('add', )

0 comments on commit b717c5e

Please sign in to comment.
You can’t perform that action at this time.