RealItemDefinition

class ase2sprkkr.common.configuration_definitions.RealItemDefinition(name, written_name=None, is_optional=None, is_hidden=False, is_expert=False, experimental=False, name_in_grammar=None, name_format=None, info=None, description=None, name_regex=None, condition=None, write_condition=None, result_class=None, is_repeated=False, repeated_delimiter=None, repeated_count=None, repeated_with_name=None, warning_condition=None, validators=(), plot=None, indent=None)[source]

A base class for a configuration definition, either of an option, or of a container. The definition determine the type of value(s) in the configuration/problem-definition file, the format of the values, the way how it/they is/are read etc…

Class hierarchy

Inheritance diagram of ase2sprkkr.common.configuration_definitions.RealItemDefinition


Constructor

Parameters:
  • warning_condition (Callable[[Any], Any] | None)

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

__init__(name, written_name=None, is_optional=None, is_hidden=False, is_expert=False, experimental=False, name_in_grammar=None, name_format=None, info=None, description=None, name_regex=None, condition=None, write_condition=None, result_class=None, is_repeated=False, repeated_delimiter=None, repeated_count=None, repeated_with_name=None, warning_condition=None, validators=(), plot=None, indent=None)[source]
Parameters:
  • name (str | Tuple(str)) – Name of the value/section

  • written_name (str or None) – Name to write to the input file. Default None means use the name.

  • is_optional (bool or callable) – If True, the section/value may be omitted from input. A callable accepts its runtime item and is evaluated after parsing.

  • is_hidden (boolean) – Hidden values are not offered to a user, usually they are set by another object (and so a direct setting of their values has no sense)

  • is_expert (boolean) – Expert values/sections are not required and they are somewhat hidden from the user

  • experimental (bool) – Whether this value or section is experimental (metadata only).

  • name_in_grammar (boolean or None) – If False, there the name of the variable is not printed in the configuration file. The variable is recognized by its position. If None, the default class value is used

  • name_format (str or None) – The way how the name is written

  • info (str) – A short help message for the value/section. It will be the perex for description.

  • description (str) – The additional informations for the users.

  • write_condition – If defined, write the value, only if write_condition(the option) is True.

  • condition –

    If defined, the condition
    • the condition.parse_condition() is invoked, when a given grammar element should be parsed. If it is False, the element is skipped

    • the condition() is invoked, when the elements of the container is listed to hide the inactive members

  • result_class – Redefine the class that holds data for this option/section.

  • is_repeated (bool or string) – The section can be repeated. If a non-empty string is given, the values are divided by the string.

  • repeated_delimiter (string) – The delimiter used between repeated instances of self, if not repeated_with_name

  • repeated_count (string or int or callable) – The number of repetitions. If string, the repetition is given from the parsed value at that exact path; .. selects the parent section (for example ..NPAN). If callable, the function is called on the values of the local options named by its parameters.

  • repeated_with_name (bool) – If True, the whole value-name pair is repeated

  • warning_condition (Callable[[Any], Any] | None) – A one-value warning condition executed through the validator pipeline.

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

    A callable or an iterable of callables accepting the runtime item,

    its containing runtime section, and the validation reason (set, parse or save). Validators return a DataValidityWarning, DataValidityError, an iterable of such issues, or None.

    indent

    Vytiskne daný string před názvem

is_stored = True

Real values and containers are present in input files by default.

name_in_grammar = True

Is the name of the value/section present in the file?

When False, the option/section name is not written to the file at all. The value(s) of the option/section is/are then expected to be located in the file just after the previous one.

By default, all options and sections… are named (in the configuration file). However, the attribute can be redefined in instantiated objects and/or descendant classes to change the behavior.

info_in_data_description = False
written_name

The name of the option/section

_info

A short help text describing the content for the users.

_description

A longer help text describing the content for the users.

result_class = None

Parsing of the data results in an instance of this class. To be redefined in descendants.

default_repeated_type = (Type.LIST, <class fRepeatedKey>)
all_names = None
property repeated_delimiter
added_to_container(container)[source]

Hook called when this item is assigned to a parent container.

Used to attach grammar hooks for dynamic repeated-count behavior.

property lower_case_names[source]
enrich(option)[source]
option_attribute_index(name)[source]

Return an index exposed as option.<name>, or None.

property formated_name
has_name(name, lower_case=False)[source]
run_validators(item, container, why)[source]

Run validators for runtime item in container during why.

Parameters:
  • item (Any)

  • container (Any)

  • why (str)

Return type:

None

get_generated(option, key=<object object>)[source]

Invoke a generated getter using its section-oriented API.

Parameters:
  • option (Any)

  • key (Any)

Return type:

Any

stage_generated(option, transaction, value, key=<object object>)[source]

Invoke a generated setter using its section-oriented API.

Parameters:
  • option (Any)

  • transaction (Any)

  • value (Any)

  • key (Any)

Return type:

None

intrinsic_validators = (<function _validate_warning_condition>,)
all_names_in_grammar()[source]
allow_duplication()[source]

Can be the item repeated in the output file

property is_independent_on_the_predecessor

Some value have to be positioned just after their predecessor in the output.

info(generic=True)[source]

Return short help string.

Parameters:

generic (bool) – If the definition has no help specified and generic is True, return a (not saying much) generic help string

Return type:

str

_description_indentation = '    '

Nested levels of description will be indented using this ‘prefix’

description(verbose=True, show_hidden=False, prefix='')[source]
Parameters:
  • verbose (bool) – If true, add also detailed documentation of all included items (e.g. members of a container)

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

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

_grammar_of_name()[source]

Return grammar for the name (and possible alternative names etc.)

_tuple_with_my_name(expr, delimiter=None, has_value=True, name_in_grammar=None)[source]

Create the grammar returning tuple (self.name, <result of the expr>)

Parameters:
  • expr – Pyparsing expresion for the value of the option/section

  • delimiter – Pyparsing expression for the name-value delimiter

  • has_value (bool) – If False, do not add the parsed value to the results. This can be used e.g. for separators (see ase2sprkkr.common.grammar_types.Separator) etc.

do_not_skip_whitespaces_before_name = False
_copy_excluded_args = ['container', 'grammar_hooks', 'expert', 'indent']