1313
1414from copy import deepcopy
1515from textwrap import dedent
16- from typing import Any , Dict , List , Optional , Union
17-
18- import msgspec
16+ from typing import Any , Dict , List , Literal , Optional , Union
1917
2018from taskgraph .transforms .base import TransformSequence
2119from taskgraph .util .attributes import attrmatch
2220from taskgraph .util .dependencies import GROUP_BY_MAP , get_dependencies
2321from taskgraph .util .schema import Schema , validate_schema
2422from taskgraph .util .set_name import SET_NAME_MAP
2523
24+ SetNameType = Literal ["strip-kind" , "retain-kind" ]
25+ GroupByType = Literal ["single" , "all" , "attribute" ]
2626
27- class FetchEntry (Schema , rename = None ):
28- """A fetch entry for an artifact."""
29-
30- artifact : str
31- dest : Optional [str ] = None
3227
33-
34- class FromDepsConfig (Schema ):
28+ class FromDepsChildSchema (Schema ):
3529 # Optional fields
3630 # Limit dependencies to specified kinds (defaults to all kinds in
3731 # `kind-dependencies`).
@@ -40,16 +34,17 @@ class FromDepsConfig(Schema):
4034 # dependency of this kind will be used to derive the label
4135 # and copy attributes (if `copy-attributes` is True).
4236 kinds : Optional [List [str ]] = None
43- # UPDATE ME AND DOCS
44- set_name : Optional [Union [str , bool , Dict [str , Any ]]] = None
37+ # Set the task name using the specified function. Can be False to
38+ # disable name setting, or a string/dict specifying the function to use.
39+ set_name : Optional [Union [SetNameType , bool , Dict [SetNameType , Any ]]] = None
4540 # Limit dependencies to tasks whose attributes match
4641 # using :func:`~taskgraph.util.attributes.attrmatch`.
4742 with_attributes : Optional [Dict [str , Union [List [Any ], str ]]] = None
4843 # Group cross-kind dependencies using the given group-by
4944 # function. One task will be created for each group. If not
5045 # specified, the 'single' function will be used which creates
5146 # a new task for each individual dependency.
52- group_by : Optional [Union [str , Dict [str , Any ]]] = None
47+ group_by : Optional [Union [GroupByType , Dict [GroupByType , Any ]]] = None
5348 # If True, copy attributes from the dependency matching the
5449 # first kind in the `kinds` list (whether specified explicitly
5550 # or taken from `kind-dependencies`).
@@ -64,35 +59,12 @@ class FromDepsConfig(Schema):
6459 # `fetches` entry.
6560 fetches : Optional [Dict [str , List [Union [str , Dict [str , str ]]]]] = None
6661
67- def __post_init__ (self ):
68- # Validate set_name
69- if self .set_name is not None and self .set_name is not False :
70- if isinstance (self .set_name , str ) and self .set_name not in SET_NAME_MAP :
71- raise msgspec .ValidationError (f"Invalid set-name: { self .set_name } " )
72- elif isinstance (self .set_name , dict ):
73- keys = list (self .set_name .keys ())
74- if len (keys ) != 1 or keys [0 ] not in SET_NAME_MAP :
75- raise msgspec .ValidationError (
76- f"Invalid set-name dict: { self .set_name } "
77- )
78-
79- # Validate group_by
80- if self .group_by is not None :
81- if isinstance (self .group_by , str ) and self .group_by not in GROUP_BY_MAP :
82- raise msgspec .ValidationError (f"Invalid group-by: { self .group_by } " )
83- elif isinstance (self .group_by , dict ):
84- keys = list (self .group_by .keys ())
85- if len (keys ) != 1 or keys [0 ] not in GROUP_BY_MAP :
86- raise msgspec .ValidationError (
87- f"Invalid group-by dict: { self .group_by } "
88- )
89-
90-
91- #: Schema for from_deps transforms
62+
63+ # Schema for from_deps transforms
9264class FromDepsSchema (Schema , forbid_unknown_fields = False ):
9365 """Schema for from_deps transforms."""
9466
95- from_deps : FromDepsConfig
67+ from_deps : FromDepsChildSchema
9668
9769
9870transforms = TransformSequence ()
0 commit comments