Transforms

class helix.transform.Transform(*args, **kwargs)

A common base class for all transforms.

TYPE_SOURCE = 'source'

A source-to-source transformation.

Setting Transform.type to TYPE_SOURCE indicates to Blueprints that this Transform should be fed source files and should produce modified source files.

TYPE_ARTIFACT = 'artifact'

An artifact-to-artifact transformation.

Setting Transform.type to TYPE_ARTIFACT indicates to Blueprints that this Transform should be fed built artifacts and should produce modified built artifacts.

property configuration

Parsed configuration parameters.

This is populated by the configure method, controlled by the options parameter. If this has not yet been configured, this raises a NotConfigured exception.

configure(**kwargs)

Parse configuration data passed as kwargs.

Configuration values taken from options will be passed to this function as kwargs. This function is responsible for parsing and storing those configuration options and storing them in configuration.

Parameters

**kwargs – Arbitrary keyword arguments corresponding to fields in options

Note

Although it is possible to pass values of varying types to this method, it is recommended that code which makes use of configuration parameters assumed that they are a string, since configuration parameters parsed from command line arguments and configuration files will be passed as strings.

property configured

Indicates if this has been configured.

This attribute is set True by the configure method. Components are reconfigurable, so configure may still be called if configured is True.

A Configurable with no configuration options is considered to be already configured.

dependencies = []

A list of external dependencies which must be installed.

This list is optional, but must consist of zero or more instances of Dependency (or subclasses) which may be installed by users.

abstract property description
classmethod install(verbose=False)

Install all dependencies.

This reruns dependency installation regardless of if it has been installed already. This should be safe because of the requirement that dependency installation methods be repeatable but can be inefficient. Users can check the installed() method to determine if the installation should be rerun.

Parameters

verbose (bool) – Verbosity.

classmethod installed()

Check if all dependencies have been installed.

Returns

True if all dependencies have been installed already, and False otherwise.

abstract property name

A simple name.

Names should consist of [a-z-]. Make use of the verbose_name property if you would like a pretty-printable version of this name.

options = {}

A dictionary of configurable options and default values.

This defines which options which may be edited with a call to configure.

Example

A subclass with both required and default parameters may be defined as:

options = {
    "server": {},
    "port": {"default": 1337}
}
classmethod string()
supported(source)

Check if the given source is supported.

This method is optional - the default behavior is to assume all sources are suppored.

Parameters

source (str) – The source material for this tranformation.

Returns

True if the target is supported by this transform, False otherwise.

tags = ()

An optional iterable of human-readable tag tuples.

Tags may represent family or component groupings and are fairly loosely defined.

Example

An APT29/SEDINT sample may be defined as (("family", "APT29"), ("sample", "SEDINT"))

abstract property type

A short type descriptor.

This should be set to some constant (a short string) defined in some common location.

validate_configuration()

Custom option validation code.

This optional method may be implemented on subclasses to provide custom configuration validation and is called by the configure method. If invalid configuration is detected, this method should raise ConfigurationError. Parsed configuration values are stored in configuration by the time this is called.

abstract property verbose_name

Verbose name for pretty printing.

abstract property version

A version number.

This should be a string using Semantic Versioning.

abstract transform(source, destination)

Apply this transform.

Applies this transform to the given source and writes the output to destination. If this transform expects configuration, this method should raise exceptions if configured is False when this is called.

Parameters
  • source (str) – The source material for this tranformation.

  • destination (str) – The destination to write the output of this transformation.