ScriptValidator (autotransform.validator.script)

The implementation for the ScriptValidator.

class autotransform.validator.script.ScriptValidator(*, args: List[str], script: str, failure_level: ValidationResultLevel = ValidationResultLevel.ERROR, per_item: bool = False, run_on_changes: bool = False)

Bases: Validator

Runs a script with the supplied arguments to perform validation. If the per_item flag is set to True, the script will be invoked on each Item. If run_on_changes is set to True, the script will replace the Batch Items with FileItems for each changed file. The failure_level indicates the result level if the script returns a non-zero exit code. Sentinel values can be used in args to provide custom arguments for a run. The available sentinel values for args are:

<<KEY>>: A json encoded list of the Items for a Batch. If the per_item flag is set

this will simply be the key of an Item.

<<EXTRA_DATA>>: A JSON encoded mapping from Item key to that Item’s extra_data. If the

per_item flag is set, this will simply be a JSON encoding of the Item’s extra_data. If extra_data is not present for an item, it is treated as an empty Dict.

<<METADATA>>: A JSON encoded version of the Batch’s metadata.

_FILE can be appended to any of these (i.e. <<KEY_FILE>>) and the arg will instead be replaced

with a path to a file containing the value.

args

The arguments to supply to the script.

Type

List[str]

script

The script to run.

Type

str

failure_level

The result level to use if validation fails. Defaults to ValidationResultLevel.ERROR.

Type

ValidationResultLevel, optional

per_item

Whether to run the script on each item. Defaults to False.

Type

bool, optional

run_on_changes

Whether to replace the Items in the batch with FileItems for the changed files. Defaults to False.

Type

bool, optional

name

The name of the Component.

Type

ClassVar[ValidatorName]

args: List[str]
check(batch: Batch, _transform_data: Optional[Mapping[str, Any]]) ValidationResult

Runs the script validation against the Batch, either on each item individually or on the entire Batch, based on the per_item flag. If the script returns a non-zero exit code, the failure_level will be in the result.

Parameters
  • batch (Batch) – The transformed Batch to validate.

  • _transform_data (Optional[Mapping[str, Any]]) – Data from the transformation. Unused.

Returns

The result of the validation check indicating the severity of any

validation failures as well as an associated message

Return type

ValidationResult

failure_level: ValidationResultLevel
name: ClassVar[ValidatorName] = 'script'
per_item: bool
run_on_changes: bool
script: str