API Documentation

class configcrunch.YamlConfigDocument(document: dict, path: str = None, parent: Optional[configcrunch.abstract.YamlConfigDocument] = None, already_loaded_docs: List[str] = None, absolute_paths=None)[source]

Bases: configcrunch.interface.IYamlConfigDocument, abc.ABC

A document represented by a dictionary, that can be validated, can contain references to other (sub-)documents, which can be resolved, and variables that can be parsed.

error_str() → str[source]

Error string representation. This short string representation is used in Schema errors and is meant to assist in finding document errors. Set this to a small representation of the document, that the user can understand.

classmethod from_yaml(path_to_yaml: str) → configcrunch.abstract.YamlConfigDocument[source]

Constructs a YamlConfigDocument from a YAML-file.

Expects the content to be a dictionary with one key (defined in the header method) and it’s value is the body of the document, validated by the schema method.

Parameters:path_to_yaml
Returns:
classmethod header() → str[source]

Header that YAML-documents must contain.

items()[source]
parent() → configcrunch.abstract.YamlConfigDocument[source]

Variable Helper

Can be used inside configuration files.

A helper function that can be used by variable-placeholders to the get the parent document (if any is set).

Example usage:

something: '{{ parent().field }}'

Example result:

something: 'value of parent field'
process_vars() → configcrunch.abstract.YamlConfigDocument[source]

Process all {{ variables }} inside this document and all sub-documents. All references must be resolved beforehand to work correctly (resolve_and_merge_references). Changes this document in place.

process_vars_for(target: str, additional_helpers: List[Callable] = None) → str[source]

Process all {{ variables }} inside the specified string as if it were part of this document. All references must be resolved beforehand to work correctly (resolve_and_merge_references).

additional_helpers may contain additional variable helper functions to use.

resolve_and_merge_references(lookup_paths: List[str]) → configcrunch.abstract.YamlConfigDocument[source]

Resolve the $ref entry at the beginning of the document body and merge with referenced documents (changes this document in place).

Parameters:lookup_paths – Paths to the repositories, where referenced should be looked up.
Final:Since 0.2.0 this function must not be extended, otherwise the $remove markers will not be removed. Please use _load_subdocuments to load sub-documents during the merging step instead!
Returns:self
classmethod schema() → schema.Schema[source]

Schema that the document should be validated against.

to_dict()[source]
validate() → bool[source]

Validates the document against the Schema.

class configcrunch.DocReference(referenced_doc_type: Type[configcrunch.abstract.YamlConfigDocument])[source]

Bases: object

For Schemas. Marks a reference to another YamlConfigDocument inside a schema.

validate(data)[source]

Validates. If the subdocument still contains $ref, it is not validated further, please call resolve_and_merge_references. Otherwise the sub-document is expected to match according to it’s schema.

Parameters:data
Returns:
configcrunch.variable_helper(func)[source]
configcrunch.load_subdocument(doc: Union[dict, YamlConfigDocument], source_doc: YamlConfigDocument, doc_clss: Type[YamlConfigDocument], lookup_paths: List[str]) → Optional[YamlConfigDocument][source]

Load a subdocument of a specific type. This will convert the dict at this position into a YamlConfigDocument with the matching type and perform resolve_and_merge_references on it.

Parameters:
  • doc – Dictionary with data to convert. Can also already be a document of the target type.
  • source_doc – Parent document
  • doc_clss – Class that is expected from the subdocument (target class)
  • lookup_paths – Paths to the repositories, where referenced should be looked up.
Returns:

Errors

exception configcrunch.errors.CircularDependencyError[source]

Bases: configcrunch.errors.ConfigcrunchError

exception configcrunch.errors.ConfigcrunchError[source]

Bases: Exception

exception configcrunch.errors.InvalidDocumentError[source]

Bases: configcrunch.errors.ConfigcrunchError

exception configcrunch.errors.InvalidHeaderError[source]

Bases: configcrunch.errors.InvalidDocumentError

exception configcrunch.errors.InvalidRemoveError[source]

Bases: configcrunch.errors.InvalidDocumentError

exception configcrunch.errors.ReferencedDocumentNotFound[source]

Bases: configcrunch.errors.ConfigcrunchError

exception configcrunch.errors.VariableProcessingError[source]

Bases: configcrunch.errors.ConfigcrunchError