General
This framework is about parameterizing classes and configuring their instances in a simple yet flexible and powerful approach. It uses pyhocon for specification of the parameters' values.
A class can be made configurable by inheriting from the Configurable
base class. Parameters are then added as class members:
from hanna import Configurable, Integer, String
class Book(Configurable):
title = String()
year = Integer()
Now we can configure this class by providing a pyhocon.ConfigTree
instance:
from pyhocon import ConfigFactory
book = Book(ConfigFactory.parse_file('/path/to/file'))
where /path/to/file
points to the corresponding HOCON file:
title: "some title"
year: 2018
We can then use the parameters' values on the configured instance:
book.title # 'some title'
book.year # 2018
Parameter names
The parameter names are automatically retrieved from the field names if not specified:
class Example(Configurable):
auto = String()
manual = Integer('really_manual')
print(Example.auto.name) # auto
print(Example.manual.name) # really_manual
In case the name is automatically retrieved all leading underscores will be stripped:
class Example(Configurable):
_foo = String()
print(Example._foo.name) # foo
Edited by Dominik Vilsmeier