|
2 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | 4 |
|
5 | | - |
6 | 5 | import logging |
7 | 6 | import os |
8 | 7 | import sys |
|
28 | 27 |
|
29 | 28 | class WorkerAlias(Schema): |
30 | 29 | """Worker alias configuration.""" |
31 | | - |
32 | | - provisioner: Union[str, dict] # Can be keyed-by level |
| 30 | + provisioner: optionally_keyed_by("level", str) # type: ignore |
33 | 31 | implementation: str |
34 | 32 | os: str |
35 | | - worker_type: Union[str, dict] # Can be keyed-by level, maps from "worker-type" |
36 | | - |
37 | | - def __post_init__(self): |
38 | | - """Validate keyed-by fields.""" |
39 | | - # Validate provisioner can be keyed-by level |
40 | | - if isinstance(self.provisioner, dict): |
41 | | - validator = optionally_keyed_by("level", str) |
42 | | - # Just validate - it will raise an error if invalid |
43 | | - validator(self.provisioner) |
44 | | - |
45 | | - # Validate worker_type can be keyed-by level |
46 | | - if isinstance(self.worker_type, dict): |
47 | | - validator = optionally_keyed_by("level", str) |
48 | | - # Just validate - it will raise an error if invalid |
49 | | - validator(self.worker_type) |
| 33 | + worker_type: optionally_keyed_by("level", str) # type: ignore |
50 | 34 |
|
51 | 35 |
|
52 | 36 | class Workers(Schema, rename=None): |
@@ -94,49 +78,17 @@ class GraphConfigSchema(Schema): |
94 | 78 |
|
95 | 79 | # Required fields first |
96 | 80 | trust_domain: str # Maps from "trust-domain" |
97 | | - task_priority: Union[ |
98 | | - TaskPriority, dict |
99 | | - ] # Maps from "task-priority", can be keyed-by project or level |
| 81 | + task_priority: optionally_keyed_by("project", "level", TaskPriority) # type: ignore |
100 | 82 | workers: Workers |
101 | 83 | taskgraph: TaskGraphConfig |
102 | 84 |
|
103 | 85 | # Optional fields |
104 | 86 | docker_image_kind: Optional[str] = None # Maps from "docker-image-kind" |
105 | | - task_deadline_after: Optional[Union[str, dict]] = ( |
106 | | - None # Maps from "task-deadline-after", can be keyed-by project |
107 | | - ) |
| 87 | + task_deadline_after: Optional[optionally_keyed_by("project", str)] = None # type: ignore |
108 | 88 | task_expires_after: Optional[str] = None # Maps from "task-expires-after" |
109 | 89 | # Allow extra fields for flexibility |
110 | 90 | __extras__: Dict[str, Any] = msgspec.field(default_factory=dict) |
111 | 91 |
|
112 | | - def __post_init__(self): |
113 | | - """Validate keyed-by fields.""" |
114 | | - # Validate task_priority can be keyed-by project or level |
115 | | - if isinstance(self.task_priority, dict): |
116 | | - # Create a validator that accepts TaskPriority values |
117 | | - def validate_priority(x): |
118 | | - valid_priorities = [ |
119 | | - "highest", |
120 | | - "very-high", |
121 | | - "high", |
122 | | - "medium", |
123 | | - "low", |
124 | | - "very-low", |
125 | | - "lowest", |
126 | | - ] |
127 | | - if x not in valid_priorities: |
128 | | - raise ValueError(f"Invalid task priority: {x}") |
129 | | - return x |
130 | | - |
131 | | - validator = optionally_keyed_by("project", "level", validate_priority) |
132 | | - # Just validate - it will raise an error if invalid |
133 | | - validator(self.task_priority) |
134 | | - |
135 | | - # Validate task_deadline_after can be keyed-by project |
136 | | - if self.task_deadline_after and isinstance(self.task_deadline_after, dict): |
137 | | - validator = optionally_keyed_by("project", str) |
138 | | - # Just validate - it will raise an error if invalid |
139 | | - validator(self.task_deadline_after) |
140 | 92 |
|
141 | 93 |
|
142 | 94 | # Msgspec schema is now the main schema |
|
0 commit comments