PyLoader#

class PyLoader(app, filename, *args, **kwargs)#

Bases: FileLoader

Load config from a python file.

Follows the syntax of traitlets python config files:

c.ClassName.parameter = 1

but now also:

c.group.subgroup.parameter = True

Arbitrary sections and sub-sections can be specified. The object c is already defined. It is a simple object only meant to allow for this syntax (PyConfigContainer). Any code will be run, so some logic can be used in the config files directly (changing a value depending on OS or hostname for instance).

Sub-configs are not supported (but could be if necessary).

Parameters:
load_config()#

Populate the config attribute from python file.

Compile the config file, and execute it with the variable c defined as an empty PyConfigContainer object.

Return type:

Iterator[ConfigValue]

serialize_item(value, trait)#

Serialize value using repr.

Parameters:
  • value (Any)

  • trait (TraitType)

Return type:

str | None

serialize_section(section, fullpath, comment='full', comment_default=False)#

Serialize a Section and its subsections recursively.

If comments are present, trait are separated by double comment lines (##) that can be read by editors as magic cells separations.

For the key = value lines, we make use of TraitType.default_value_repr().

Parameters:
Return type:

list[str]

wrap_comment(text)#

Wrap text and return it as commented lines.

Parameters:

text (str | list[str])

Return type:

list[str]

write(fp, comment='full', comment_default=False)#

Return lines of configuration file corresponding to the app config tree.

Parameters:
Return type:

None