reportcompiler.plugins.source_parsers.base

base.py

This module includes the base plugin interface for context generators.

Classes

  • SourceParser: Plugin that implements the parsing for source files: the metadata
class reportcompiler.plugins.source_parsers.base.SourceParser

Plugin that implements the parsing for source files: the metadata retrieval and the context generation stages for a fragment.

Inheritance

Inheritance diagram of SourceParser
generate_context(doc_param, data, metadata)

Generates the dictionary context.

Parameters:
  • doc_param (OrderedDict) – Document variable
  • data (pandas.DataFrame) – Pandas dataframe (or list of dataframes) with the specified input data
  • metadata (dict) – Document metadata (overriden by fragment metadata when specified)
Returns:

Dictionary with context for the template rendering stage

Return type:

dict

classmethod raise_generator_exception(doc_param, data, context, exception=None, message=None)

Returns a context generation exception with the necessary info attached.

Parameters:
  • context (dict) – Context for fragment
  • exception (Exception) – Exception returned by context generation
  • message (str) – Optional message for exception
Raises:

ContextGenerationError – always

classmethod raise_retriever_exception(doc_param, context, exception=None, message=None)

Returns a metadata retrieval exception with the necessary info attached.

Parameters:
  • context (dict) – Context for fragment
  • exception (Exception) – Exception returned by metadata retrieval
  • message (str) – Optional message for exception
Raises:

MetadataRetrievalError – always

retrieve_fragment_metadata(doc_param, metadata)

Retrieves the metadata required to process the fragment.

Parameters:
  • doc_param (OrderedDict) – Document variable
  • metadata (dict) – Document metadata (overriden by fragment metadata when specified)
Returns:

Dictionary with metadata

Return type:

dict

setup_and_generate_context(doc_param, data, metadata)

Wraps the context generation with temporary file creation and hash checking to avoid unnecessary processing.

Parameters:
  • doc_param (OrderedDict) – Document variable
  • data (pandas.DataFrame) – Dataframe (or list of dataframes) with the specified input data
  • metadata (dict) – Document metadata (overriden by fragment metadata when specified)
Returns:

Dictionary with context for the template rendering stage

Return type:

dict