Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/openjd/model/_internal/_create_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def instantiate_model( # noqa: C901
errors = list[InitErrorDetails]()
instantiated_fields = dict[str, Any]()

# Apply pre-transform if defined
if model._job_creation_metadata.transform is not None:
model = model._job_creation_metadata.transform(model)

# Determine the target model to create as
target_model = model.__class__
if model._job_creation_metadata.create_as is not None:
Expand Down
4 changes: 2 additions & 2 deletions src/openjd/model/_internal/_validator_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def validate_int_fmtstring_field(
ge: Optional[int] = None,
*,
context: Optional[ModelParsingContextInterface],
) -> Union[int, float, Decimal, FormatString]:
) -> Union[int, FormatString]:
"""Validates a field that is allowed to be either an integer, a string containing an integer,
or a string containing expressions that resolve to an integer."""
value_type_wrong_msg = "Value must be an integer or a string containing an integer."
Expand Down Expand Up @@ -57,7 +57,7 @@ def validate_float_fmtstring_field(
ge: Optional[Decimal] = None,
*,
context: Optional[ModelParsingContextInterface],
) -> Union[int, float, Decimal, FormatString]:
) -> Union[Decimal, FormatString]:
"""Validates a field that is allowed to be either an float, a string containing an float,
or a string containing expressions that resolve to a float."""
value_type_wrong_msg = "Value must be a float or a string containing a float."
Expand Down
7 changes: 7 additions & 0 deletions src/openjd/model/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ class JobCreationMetadata:
"""This instructs the instantiation code to rename the given fields.
"""

transform: Optional[Callable[["OpenJDModel"], "OpenJDModel"]] = field(default=None)
"""A callable that transforms the source model before field processing.
arg0 - The model to transform.
returns - The transformed model (can be the same instance or a new one).
Use-case: Resolving syntax sugar on StepTemplate before creating Step.
"""


class OpenJDModel(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True)
Expand Down
6 changes: 6 additions & 0 deletions src/openjd/model/v2023_09/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
EmbeddedFiles,
EmbeddedFileText,
EmbeddedFileTypes,
EndOfLine,
Environment,
EnvironmentActions,
EnvironmentName,
Expand Down Expand Up @@ -64,6 +65,8 @@
PathTaskParameterDefinition,
RangeExpressionTaskParameterDefinition,
RangeListTaskParameterDefinition,
ScriptInterpreter,
SimpleAction,
Step,
StepActions,
StepEnvironmentList,
Expand Down Expand Up @@ -113,6 +116,7 @@
"EmbeddedFiles",
"EmbeddedFileText",
"EmbeddedFileTypes",
"EndOfLine",
"Environment",
"EnvironmentActions",
"EnvironmentScript",
Expand Down Expand Up @@ -148,6 +152,8 @@
"PathTaskParameterDefinition",
"RangeExpressionTaskParameterDefinition",
"RangeListTaskParameterDefinition",
"ScriptInterpreter",
"SimpleAction",
"Step",
"StepActions",
"StepEnvironmentList",
Expand Down
Loading
Loading