77import re
88import string
99import time
10- from dataclasses import asdict , dataclass
1110from importlib .metadata import distributions
1211from pathlib import Path
1312
1716
1817from .. import Feedstock
1918from ..bakery .base import Bakery
19+ from ..bakery .execution_metadata import ExecutionMetadata
2020from ..bakery .local import LocalDirectBakery
2121from ..plugin import get_injections , get_injectionspecs_from_entrypoints
2222from ..storage import InputCacheStorage , TargetStorage
2323from ..stream_capture import redirect_stderr , redirect_stdout
2424from .base import BaseCommand , common_aliases , common_flags
2525
2626
27- @dataclass
28- class ExecutionMetadata :
29- """
30- Holds metadata for an execution instance, including recipe and job names.
31-
32- Attributes:
33- recipe_name (str): Name of the recipe being executed.
34- job_name (str): Unique name for the job execution.
35- """
36-
37- recipe_name : str
38- job_name : str
39-
40- def to_dict (self ) -> dict :
41- return asdict (self )
42-
43-
4427class Bake (BaseCommand ):
4528 """
4629 Command to bake a pangeo forge recipe in a given bakery
@@ -138,8 +121,7 @@ def _validate_job_name(self, proposal):
138121 )
139122 return proposal .value
140123
141- @validate ("bakery_class" )
142- def _bakery_impl_validation (self , proposal ):
124+ def bakery_impl_validation (self ):
143125 """
144126 Validates the 'bakery_class' trait using class-specific validation logic.
145127
@@ -150,8 +132,11 @@ def _bakery_impl_validation(self, proposal):
150132 Raises:
151133 - TraitError: If multiple validation errors are encountered, a single TraitError
152134 is raised containing a summary of all error messages.
135+
136+ Note: Traitlets has no convenient way to set initialization hooks (???) so we have
137+ to run this manually.
153138 """
154- klass = proposal [ "value" ]
139+ klass = self . bakery_class
155140 if errors := klass .validate_bake_command (self ):
156141 if len (errors ) == 1 :
157142 raise errors [0 ]
@@ -202,6 +187,9 @@ def start(self):
202187 """
203188 Start the baking process
204189 """
190+ # Validate bakery-specific requirements of this class. Yes, we have to do it here.
191+ self .bakery_impl_validation ()
192+
205193 if not "pangeo-forge-recipes" in [d .metadata ["Name" ] for d in distributions ()]:
206194 raise ValueError (
207195 "To use the `bake` command, `pangeo-forge-recipes` must be installed."
0 commit comments