Transformer - lottspot/mkproject GitHub Wiki
[[TOC]]
from mkproject.transformer import BaseTransformer
from mkproject.transformer import TransformerError
class MyTransformer(BaseTransformer):
name = 'myname'
@staticmethod
def transform(cfg, path, data, meta):
try:
# Use values from cfg and/or meta to perform transformations
# on any or all of data, path, and meta
return path, data, meta
except EnvironmentError:
raise TransformerErrorThis attribute must be defined in class implementations. This is the name
which assets should specify in their pipeline metadata property in order
to invoke this transformer.
BaseTransformer.transform(cfg, path, data, meta)
The purpose of transformers is to provide a method through which assets can be paramaterized/templatized, allowing outputs to be written with project specific values.
This method must be implemented as a static method, as transformer classes
are never instantiated. It takes as its parameters a dictionary
providing project level configuration data (cfg) and all of the properties
of an asset (path, data, and meta). This method can use any of the
information it is passed to transform any of the other information it is passed
(e.g., data might be a template which can be rendered using the values in cfg).
After the asset is transformed, the transformer must return all of the asset properties.
If the expected transformation of the asset fails for any reason, the transformer
is expected to raise TransformerError.