4848from functools import lru_cache
4949from textwrap import dedent
5050from threading import Event
51- from typing import Annotated , Any , Literal , Optional , Union
51+ from typing import Annotated , Any , Optional , Union
5252
5353from ddeutil .core import freeze_args
5454from pydantic import BaseModel , Discriminator , Field , SecretStr , Tag
55+ from pydantic .functional_serializers import field_serializer
5556from pydantic .functional_validators import field_validator , model_validator
5657from typing_extensions import Self
5758
@@ -263,24 +264,20 @@ class BaseRunsOn(BaseModel): # pragma: no cov
263264 object and override execute method.
264265 """
265266
266- type : RunsOn = Field ( description = "A runs-on type." )
267+ type : RunsOn = LOCAL
267268 args : DictData = Field (
268269 default_factory = dict ,
269- alias = "with" ,
270270 description = (
271271 "An argument that pass to the runs-on execution function. This "
272272 "args will override by this child-model with specific args model."
273273 ),
274+ alias = "with" ,
274275 )
275276
276277
277278class OnLocal (BaseRunsOn ): # pragma: no cov
278279 """Runs-on local."""
279280
280- type : Literal [RunsOn .LOCAL ] = Field (
281- default = RunsOn .LOCAL , validate_default = True
282- )
283-
284281
285282class SelfHostedArgs (BaseModel ):
286283 """Self-Hosted arguments."""
@@ -292,9 +289,7 @@ class SelfHostedArgs(BaseModel):
292289class OnSelfHosted (BaseRunsOn ): # pragma: no cov
293290 """Runs-on self-hosted."""
294291
295- type : Literal [RunsOn .SELF_HOSTED ] = Field (
296- default = RunsOn .SELF_HOSTED , validate_default = True
297- )
292+ type : RunsOn = SELF_HOSTED
298293 args : SelfHostedArgs = Field (alias = "with" )
299294
300295
@@ -310,9 +305,7 @@ class AzBatchArgs(BaseModel):
310305
311306class OnAzBatch (BaseRunsOn ): # pragma: no cov
312307
313- type : Literal [RunsOn .AZ_BATCH ] = Field (
314- default = RunsOn .AZ_BATCH , validate_default = True
315- )
308+ type : RunsOn = AZ_BATCH
316309 args : AzBatchArgs = Field (alias = "with" )
317310
318311
@@ -331,23 +324,21 @@ class DockerArgs(BaseModel):
331324class OnDocker (BaseRunsOn ): # pragma: no cov
332325 """Runs-on Docker container."""
333326
334- type : Literal [RunsOn .DOCKER ] = Field (
335- default = RunsOn .DOCKER , validate_default = True
336- )
337- args : DockerArgs = Field (alias = "with" , default_factory = DockerArgs )
327+ type : RunsOn = DOCKER
328+ args : DockerArgs = Field (default_factory = DockerArgs , alias = "with" )
338329
339330
340331def get_discriminator_runs_on (model : dict [str , Any ]) -> RunsOn :
341332 """Get discriminator of the RunsOn models."""
342333 t : str = model .get ("type" )
343- return RunsOn (t ) if t else RunsOn . LOCAL
334+ return RunsOn (t ) if t else LOCAL
344335
345336
346337RunsOnModel = Annotated [
347338 Union [
348- Annotated [OnSelfHosted , Tag (RunsOn . SELF_HOSTED )],
349- Annotated [OnDocker , Tag (RunsOn . DOCKER )],
350- Annotated [OnLocal , Tag (RunsOn . LOCAL )],
339+ Annotated [OnSelfHosted , Tag (SELF_HOSTED )],
340+ Annotated [OnDocker , Tag (DOCKER )],
341+ Annotated [OnLocal , Tag (LOCAL )],
351342 ],
352343 Discriminator (get_discriminator_runs_on ),
353344]
@@ -490,6 +481,10 @@ def __validate_job_id__(self) -> Self:
490481
491482 return self
492483
484+ @field_serializer ("runs_on" )
485+ def __serialize_runs_on (self , value : RunsOnModel ):
486+ return value .model_dump (by_alias = True )
487+
493488 def stage (self , stage_id : str ) -> Stage :
494489 """Return stage instance that exists in this job via passing an input
495490 stage ID.
0 commit comments