Document Context¶
The document context
- class disseminate.document.document_context.DocumentContext(document, *args, **kwargs)¶
Bases:
disseminate.context.context.BaseContext
A context dict used for documents objects.
- do_not_inherit = {'body', 'builders', 'doc_id', 'document', 'include', 'includes', 'mtime', 'paths', 'short'}¶
The keys for context entries that should not be inherited from the parent context. They should be unique to each context.
- property document¶
The document that owns this context
- exclude_from_reset = {'document', 'environment', 'label_manager', 'paths'}¶
The keys for context entries that should not be removed when the context is cleared. These are typically for entries setup in the __init__ of the class.
- property includes¶
Retrieve a list of included subdocument source paths from the ‘include’ entry of the context.
- Returns
- include_listList[
SourcePath
] A list of the paths for the included subdocuments.
- include_listList[
- reset()¶
(Selectively) resets the context to its initial state.
The context is reset by removing items with keys not specified in the ‘exclude_from_clear’ class attribute.
Note
Entries in the parent_context are copied to this context. If the parent_context entry is a mutable, like a list or dict, then a copy of that mutable is created if a ‘copy’ method exists for that mutable. However, mutables within those mutables will still point to the original.
Examples
>>> l1, l2 = ['a'], ['b'] >>> context = BaseContext(l1=l1) >>> context['l2'] = l2 >>> context['l1'].append(1) >>> context['l2'].append(2) >>> context.reset() >>> context['l1'] == ['a'] # reset to original l1 True >>> 'l2' in context False
- property root_document¶
The root document for a project
- target_filepath(target)¶
Return the target filepath for this document’s target, given the target.
The target filepaths are retrieved from the builders. Accordingly, these should already have been loaded in the context. Additionally, this function may return target_filepaths for targets not listed by the ‘targets’ property. This is because these targets may be intermediary targets stored in a cache directory.
- Parameters
- targetstr
The target to search
- Returns
- target_filepath
paths.TargetPath
The filepath for the target file of the document.
- target_filepath
- Raises
- TargetNotFound
Raised if a target was requested but not found.
- target_filepaths()¶
Return all target filepaths for this document’s targets
The target filepaths are retrieved from the builders. Accordingly, these should already have been loaded in the context. Additionally, this function may return target_filepaths for targets not listed by the ‘targets’ property. This is because these targets may be intermediary targets stored in a cache directory.
- Returns
- targetsDict[str,
paths.TargetPath
] The targets dict. The strings are the targets and the values are the corresponding target_filepaths.
- targetsDict[str,
- property targets¶
Retrieve a list of targets from the ‘targets’ or ‘target’ entry of the document.
- Returns
- target_listList[str]
A list of targets specified in the context.
- validation_types = {'doc_id': <class 'str'>, 'document': None, 'environment': None, 'inactive_tags': <class 'set'>, 'label_fmts': <class 'dict'>, 'label_manager': <class 'disseminate.label_manager.label_manager.LabelManager'>, 'label_resets': <class 'dict'>, 'mtime': <class 'float'>, 'paths': <class 'list'>, 'process_context_tags': <class 'set'>, 'process_paragraphs': <class 'set'>, 'project_root': <class 'disseminate.paths.paths.SourcePath'>, 'src_filepath': <class 'disseminate.paths.paths.SourcePath'>, 'target_root': <class 'disseminate.paths.paths.TargetPath'>, 'targets': <class 'set'>}¶
Required entries in the document context dict to be a valid document context–as well as their matching type to be checked.