ContainerDefinition

class ase2sprkkr.common.container_definitions.ContainerDefinition(name, members=[], written_name=None, info=None, description=None, is_optional=None, is_hidden=False, is_expert=False, experimental=False, has_hidden_members=False, name_in_grammar=None, force_order=None, name_regex=False, result_class=None, is_repeated=False, repeated_delimiter=None, repeated_count=None, repeated_with_name=False, write_condition=None, warning_condition=None, validators=())[source]

Base class for a definition (of contained data, format, etc) of either a whole configuration file (e.g. InputParameters or e.g. Potential) or its Section.

Class hierarchy

Inheritance diagram of ase2sprkkr.common.container_definitions.ContainerDefinition


Constructor

Parameters:

validators (Callable[[Any, Any, str], Any] | Iterable[Callable[[Any, Any, str], Any]] | None)

__init__(name, members=[], written_name=None, info=None, description=None, is_optional=None, is_hidden=False, is_expert=False, experimental=False, has_hidden_members=False, name_in_grammar=None, force_order=None, name_regex=False, result_class=None, is_repeated=False, repeated_delimiter=None, repeated_count=None, repeated_with_name=False, write_condition=None, warning_condition=None, validators=())[source]

Definition of container (e.g. section of an input file). For the rest of the parameters see the RealItemDefinition.

Parameters:
  • has_hidden_members (bool) – If true, this section is not intended for a direct editing

  • force_order (bool) – If True, the items has to retain the order, if False, the items can be in the input file in any order.

  • validators (callable or iterable of callables) – Semantic validators passed to RealItemDefinition.

is_option = False

Container definitions create sections or configuration roots, not options.

value_name_format = None

The (print) format, how the name is written

write_last_delimiter = True
item_type = 'section'
static _dict_from_named_values(args, items=None)[source]

auxiliary method that creates dictionary from the arguments

dir_common_attributes = True

In dir listing, show the common ‘object’ attributes

force_order = False

Force order of its members

delimiter
Parameters:

name (Optional[str])

Return type:

ParserElement

default_repeated_type = (Type.LIST, <function Key.NONE>, Numbering.NO, False)
configuration_type_name = 'SECTION'

Name of the container type in the runtime documentation

added_to_container(container)[source]

Attach this container and propagate the callback to its children.

allow_duplication()[source]
data_description(verbose=False, show_hidden=False, prefix='')[source]

Return the runtime documentation for the configuration described by this object.

Parameters:
  • verbose (bool | str | int) – If False, only one line with the section name and basic info is returned. If True, the items contained in the section are listed. If 'all', add also detailed info about all descendants. If an int is given, print detailed informations about n levels. I.e. 1 is the same as True

  • show_hidden (bool) – If False, do not show hidden members.

  • prefix (str) – The string, with with each line will begin (commonly the spaces for the indentation).

additional_data_description(verbose=False, show_hidden=False, prefix='')[source]

Return the description (documentation for runtime) of the items in the container.

Parameters:
  • verbose (bool | str | int) – If True, include detailed description of the children. If 'all', include even detailed description. If int is given, print detailed informations up to n levels.

  • show_hidden – If False, do not show hidden members.

  • prefix (str) – The string, with with each line will begin (commonly the spaces for the indentation).

members()[source]
names()[source]
get_member(name)[source]

Return the definition at the given explicit dotted path.

A leading .. selects the parent container, so ..N resolves N in the direct parent and ....N resolves it two levels up.

remove(name)[source]
copy(add=[], remove=[], defaults={}, **kwargs)[source]

Get the args to copy the container. The method is just repeated to add named argumets.

_get_init_args_for_copy(add=[], remove=[], defaults={}, **kwargs)[source]

Get the args to copy the container.

copy_member(name, **kwargs)[source]

Copy a member, allowing to redefine its properties.

Returns:

new_member – The newly created member

Return type:

BaseDefinition

_grammar_of_values(allow_dangerous=False, delimiter=None, *, allow_incomplete=False)[source]
Parameters:

allow_dangerous (bool)

_allow_duplicates_of(name)[source]

Can a given element (identified by name) have more values in the parsed results? (However, not all definitions have to specify allow_duplicates, just the ones that have a value). For the others, this function raises an error.

_create_grammar(allow_dangerous=False, *, allow_incomplete=False)[source]
classmethod delimited_custom_value_grammar()[source]

Return the grammar for the custom child with delimiter. The delimiter can delimite it either from the previous child or from the section name.

custom_name_characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-()'

Which characters can appears in an unknown child (value/section) name

classmethod custom_member_grammar(name_condition=None)[source]

Grammar for the custom - unknown - child

all_member_names()[source]
excluded_names_condition()[source]

Add the condition to the element, that its value is not any of given names

_first_section_has_to_be_first()[source]

Has/ve the first child(s) in an unordered sequence fixed position?

parse_file(file, return_value_only=True, allow_dangerous=False, allow_incomplete=False)[source]

Parse a file, optionally warning about missing required members.

parse(string, whole_string=True, return_value_only=True, allow_dangerous=False, allow_incomplete=False)[source]

Parse a string, optionally warning about missing required members.

parse_return(val, return_value_only=True)[source]

Clean up the parsed values (unpack then from unnecessary containers)

Parameters:

return_value_only (bool) – Return only value, not name - value tuple

async parse_from_stream(stream, up_to, start=None, whole_string=True, return_value_only=True, allow_dangerous=False)[source]

Parse string readed from asyncio stream. The stream is readed up to the given delimiter

read_from_file(file, allow_dangerous=False, *, allow_incomplete=False, report_invalid=None, **kwargs)[source]

Read a configuration file into an object.

allow_incomplete relaxes presence requirements, not value syntax.

read_from_dict(values, **kwargs)[source]
read_from_string(string, allow_dangerous=False, **kwargs)[source]
repeated_class

Class for the repeated sections

alias of ase2sprkkr.common.repeated_configuration_containers.RepeatedConfigurationContainer

create_object(container=None, repeated=True)[source]

Create an instance (section)

container: BaseConfigurationContainer

To which container the created object will belong

repeated:

Has meaning only for a is_repeated section. Then, if it is True, a Container for repeated values of the section is returned. Otherwise, the container just for one instance of a section is returned.

Parameters:

repeated (bool)

_save_to_file(file, value, always=False, name_in_grammar=None, delimiter='')[source]

Save the content of the container to the file (according to the definition)

Parameters:
  • file (file) – File object (open for writing), where the data should be written

  • always – Do not consider conditions

Returns:

If any value have been written return True, otherwise return False.

Return type:

something_have_been_written