Partitions / Sections / Namespaces
Parameters' sections (or partitions or namespaces, as you like) are contained in their names. HOCON uses a period (.
) as path delimiter and this applies to parameter names as well. A section is defined as any part of the parameter name but the last (which is the parameter's actual name): section.subsection.name
.
Sections can be specified at various stages / places:
At class creation.
As part of the parameter's name.
In place of the parameter's name.
Class sections
Sections that apply to complete classes are declared as part of the class:
from hanna import Configurable, String
class Book(Configurable, path='book'):
title = String()
Book.title.name # "book.title"
The specified path can be any valid HOCON path expression (e.g. path='library.book'
results in Book.title.name == 'library.book.title'
). It is prepended to the name (or path) of all declared parameters.
Full name sections
We can specify a section as part of a parameter's name as for example:
class Book(Configurable):
title = String('book.title')
Book.title.name # "book.title"
This can also be combined with class sections:
class Book(Configurable, path='library'):
title = String('book.title')
Book.title.name # "library.book.title"
Prefix sections
Instead of specifying the full name of a parameter we can also only specify the parameter's section followed by a period and make use of the libraries feature to automatically derive the parameter name from the field name:
class Book(Configurable):
title = String('book.')
Book.title.name # "book.title"
Again this feature works together with class-wide sections:
class Book(Configurable, path='library'):
title = String('book.')
Book.title.name # "library.book.title"
Last updated