Partitioning / Sections / Parameter namespaces
Parameter sections (or namespaces) are contained in their names. In HOCON path expressions the delimiter is a period (.
). A section is defined as any part of the path but the last which is the parameter's actual name: "section.subsection.name"
.
We can specify sections in various ways:
- At class creation.
- As part of the parameter's name.
- In place of the parameter's name.
At class creation
The keyword argument path
lets us specify the section (plus any subsections) as a string and will be prepended to the parameters' names.
class Book(Configurable, path='book'):
title = String()
year = Integer()
Book.title.name # 'book.title'
Book.title.year # 'book.year'
class Book(Configurable, path='library.book'):
title = String()
year = Integer()
Book.title.name # 'library.book.title'
Book.title.year # 'library.book.year'
As part of the name
The name of a parameter may contain any number of sections separated by periods.
class Book(Configurable):
title = String('library.book.title')
year = Integer('library.book.year')
Book.title.name # 'library.book.title'
Book.title.year # 'library.book.year'
In place of the name
Instead of specifying the full name of a parameter we can only specify its sections with a trailing period. The full name will be adjusted when the parameter is set as a an class member.
class Book(Configurable):
title = String('library.book.')
year = Integer('library.book.')
Book.title.name # 'library.book.title'
Book.title.year # 'library.book.year'
title = String('library.book.')
title.name # 'library.book.'
class Book(Configurable):
title = title
Book.title.name # 'library.book.title'
Combining the different methods
class Book(Configurable, path='library'):
title = String('book.')
year = Integer('book.year')
Book.title.name # 'library.book.title'
Book.title.year # 'library.book.year'