2019-10-25 19:28:44 +00:00
|
|
|
import six
|
2022-10-23 09:55:41 +00:00
|
|
|
|
|
|
|
from clearml_agent.external.pyhocon import ConfigTree
|
2020-12-22 21:00:57 +00:00
|
|
|
from clearml_agent.helper.base import Singleton
|
2019-10-25 19:28:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
@six.add_metaclass(Singleton)
|
|
|
|
class Config(object):
|
|
|
|
|
|
|
|
def __init__(self, tree=None):
|
|
|
|
self.__dict__['_tree'] = tree or ConfigTree()
|
|
|
|
|
|
|
|
def __getitem__(self, item):
|
|
|
|
return self._tree[item]
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
return self._tree.__setitem__(key, value)
|
|
|
|
|
|
|
|
def new(self, name):
|
|
|
|
return self._tree.setdefault(name, ConfigTree())
|
|
|
|
|
|
|
|
__getattr__ = __getitem__
|
|
|
|
__setattr__ = __setitem__
|
|
|
|
|
|
|
|
|
|
|
|
def get_config(name=None):
|
|
|
|
config = Config()
|
|
|
|
if name:
|
|
|
|
return getattr(config, name)
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
def make_config(name):
|
|
|
|
return get_config().new(name)
|