AutoTransformSchema (autotransform.schema.schema)

The heart of AutoTransform, AutoTransformSchemas represent all information required to fully execute a change.

class autotransform.schema.schema.AutoTransformSchema(*, input: ~autotransform.input.base.Input, batcher: ~autotransform.batcher.base.Batcher, transformer: ~autotransform.transformer.base.Transformer, config: ~autotransform.schema.config.SchemaConfig, filters: ~typing.List[~autotransform.filter.base.Filter] = <factory>, validators: ~typing.List[~autotransform.validator.base.Validator] = <factory>, commands: ~typing.List[~autotransform.command.base.Command] = <factory>, repo: ~autotransform.repo.base.Repo | None = None)

Bases: ComponentModel

The heart of AutoTransform, pulls together all components required to execute a transformation.

input

The Input which gets Items.

Type:

Input

batcher

The Batcher which batches filtered Items in to logical groups.

Type:

Batcher

transformer

The Transformer which actually modifies files.

Type:

Transformer

config

Any configuration needed by the schema so that it can run.

Type:

SchemaConfig

filters

A list of Filters to apply to Items. Defaults to [].

Type:

List[Filter], optional

validators

A list of Validators to ensure the changes did not break anything. Defaults to [].

Type:

List[Validator], optional

commands

A list of Commands that run post-processing on the changes. Defaults to [].

Type:

List[Command], optional

repo

A Repo to control submission of changes to version control or code review systems. Defaults to None.

Type:

Optional[Repo], optional

batcher: Batcher
commands: List[Command]
config: SchemaConfig
execute_batch(batch: Batch, change: Change | None = None) bool

Executes changes for a batch, including setting up the Repo, running the Transformer, checking all Validators, running Commands, submitting changes if present, and rewinding the Repo if changes are submitted. Note: this function is not thread safe.

Parameters:
  • batch (Batch) – The Batch to execute.

  • change (Optional[Change]) – An associated Change that is being updated.

Raises:

ValidationError – If one of the Schema’s Validators fails raises an exception.

Returns:

Whether the batch triggered a submission.

Return type:

bool

filters: List[Filter]
static from_console(prev_schema: AutoTransformSchema | None = None) AutoTransformSchema

Gets a AutoTransformSchema using console inputs.

Parameters:

prev_schema (Optional[AutoTransformSchema], optional) – A previously input AutoTransformSchema. Defaults to None.

Returns:

The input AutoTransformSchema.

Return type:

AutoTransformSchema

static from_data(data: Dict[str, Any]) AutoTransformSchema

Takes data from a source like JSON and produces the associated Schema.

Parameters:

data (Dict[str, Any]) – The data representing the Schema.

Returns:

The Schema represented by the data.

Return type:

AutoTransformSchema

get_batches(items: List[Item]) List[Batch]

Runs the Input to get eligible Items, filters them, then batches them. Note: this function is not thread safe.

Parameters:

items (List[Item]) – The Items to batch.

Returns:

The Batches for the change

Return type:

List[Batch]

get_items() List[Item]

Runs the Input to get eligible Items and filters them. Note: this function is not thread safe.

Returns:

The valid Items for the Schema.

Return type:

List[Item]

input: Input
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

repo: Repo | None
run()

Fully run a given Schema including getting and executing all Batches. Note: this function is not thread safe.

transformer: Transformer
validators: List[Validator]