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.ABCA 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:
-
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
-
-
class
configcrunch.DocReference(referenced_doc_type: Type[configcrunch.abstract.YamlConfigDocument])[source]¶ Bases:
objectFor Schemas. Marks a reference to another YamlConfigDocument inside a schema.
-
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: