configblock.outputwriter module

Classes to help outputting help about or representations of config blocks

class configblock.outputwriter.DictWriter(only_active: bool = True, default=<object object>)

Bases: OutputWriterBase

Convert the current state of the configuration to a python dictionary

This can be used to save a configuration to a file like a JSON

begin_globals()

Begin writing the globals

Returns

Whether the block should be entered

Return type

bool

begin_subcfg(key: str, subcfg: ConfigBlock)

Begin writing a single subconfig

Note that this method should not handle further iteration into the subconfig

Returns

Whether the subconfig should be entered

Return type

bool

property current_dict: Dict
end_globals()

End writing the globals

end_subcfg()

End writing the currrent subconfig

write(root: ConfigBlock)

Return a dictionary representation of the provided hierarchy

write_option(key: str, option: OptionData)

Write a single option

class configblock.outputwriter.OutputWriterBase(only_active: bool, section_order: ~typing.Tuple[~configblock.outputwriter.Section] = (<Section.Options: 1>, <Section.Subconfigs: 2>, <Section.SubconfigTypes: 3>))

Bases: object

Base class for writing output information about a config block

Provides a mechanism for iterating through a block in a well defined order.

Subclasses should provide overrides for all relevant methods. The return values of the begin_X methods can be used to control the iteration through the hierarchy.

begin() bool

Begin the output for the provided hierarchy

Returns

Whether the hierarchy should be entered

Return type

bool

begin_block() bool

Begin writing the specified block

Returns

Whether the block should be entered

Return type

bool

begin_globals() bool

Begin writing the globals

Returns

Whether the block should be entered

Return type

bool

begin_options() bool

Begin writing the options

Returns

Whether the options should be iterated over

Return type

bool

begin_subcfg(key: str, subcfg: ConfigBlock) bool

Begin writing a single subconfig

Note that this method should not handle further iteration into the subconfig

Returns

Whether the subconfig should be entered

Return type

bool

begin_subcfg_types() bool

Begin writing the subconfig types section

Returns

Whether to iterate over the subconfiguration factories

Return type

bool

begin_subcfgs() bool

Begin writing the subconfigs section

Returns

Whether the subconfigs section should be iterated over

Return type

bool

property current_block: Optional[ConfigBlock]

The current block in the hierarchy

property depth: int

The depth in the hierarchy being visited currently

end()

End the output

end_block()

End writing the current block

end_globals()

End writing the globals

end_options()

End writing the options on the current block

end_subcfg()

End writing the currrent subconfig

end_subcfg_types()

End the subconfig types section

end_subcfgs()

End writing the subconfigs section

property only_active: bool

Whether this output writer only visits active blocks

property root: Optional[ConfigBlock]

The root of the hierarchy being visited currently

property section_order: Tuple[Section]

The section order for this writer

stack_block(block: ConfigBlock)

Add a block to the stack of currently visited blocks

stack_factory(factory: Callable[[], ConfigBlock])

Called when entering a factory to avoid infinite recursion

write(root: ConfigBlock)

Write information for the provided block

write_block(block: ConfigBlock)

Write information for a block

write_default_subcfg_type(factory: Optional[Callable[[], ConfigBlock]], already_output: bool)

Write the default subconfig factory

Parameters
  • factory (Optional[ConfigBlockFactory]) – The default subconfig factory for the current block

  • already_output (bool) – Whether or not the information has been output in the current stack. This is to prevent infinite recursion where a block has itself as the default type

write_globals()

Write information for the global options

write_option(key: str, option: OptionData)

Write a single option

write_options()

Output information on the options declared on this block

write_subcfg_type(key: str, factory: Callable[[], ConfigBlock], already_output: bool)

Write a single subconfig type

Parameters
  • factory (Optional[ConfigBlockFactory]) – The factory to write

  • already_output (bool) – Whether or not the information has been output in the current stack. This is to prevent infinite recursion where a block has itself as the default type

write_subcfg_types()

Output information on the subconfiguration factories declared on this block

write_subcfgs()

Output information on the subconfigurations declared on this block

class configblock.outputwriter.Section(value)

Bases: Enum

Enum describing the different types of data in each ConfigBlock

Options = 1

The options directly defined on this block

SubconfigTypes = 3

The factories on this block, including both the default and any named factories

Subconfigs = 2

All subconfigs directly defined on this block, including instantiated extra subconfigs

configblock.outputwriter.get_short_doc(obj) str

Get the short docstring from an object