Skip to content

Commit

Permalink
Moving pieces... breaking circularity...
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Feb 20, 2024
1 parent 99c6a81 commit 9247382
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions pangeo_forge_runner/bakery/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import List

from apache_beam.pipeline import Pipeline, PipelineOptions
from traitlets import TraitError
from traitlets import HasTraits, TraitError
from traitlets.config import LoggingConfigurable

from ..commands.bake import Bake, ExecutionMetadata
from .execution_metadata import ExecutionMetadata


class Bakery(LoggingConfigurable):
Expand Down Expand Up @@ -45,7 +45,7 @@ def bake(self, pipeline: Pipeline, meta: ExecutionMetadata) -> None:
)

@classmethod
def validate_bake_command(cls, bake_command: Bake) -> List[TraitError]:
def validate_bake_command(cls, bake_command: HasTraits) -> List[TraitError]:
"""
Validates the given bake_command and collects any validation errors.
Expand Down
17 changes: 17 additions & 0 deletions pangeo_forge_runner/bakery/execution_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from dataclasses import asdict, dataclass

@dataclass
class ExecutionMetadata:
"""
Holds metadata for an execution instance, including recipe and job names.
Attributes:
recipe_name (str): Name of the recipe being executed.
job_name (str): Unique name for the job execution.
"""

recipe_name: str
job_name: str

def to_dict(self) -> dict:
return asdict(self)
6 changes: 3 additions & 3 deletions pangeo_forge_runner/bakery/flink.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

import escapism
from apache_beam.pipeline import Pipeline, PipelineOptions
from traitlets import Bool, Dict, Integer, TraitError, Unicode
from traitlets import Bool, Dict, HasTraits, Integer, TraitError, Unicode

from ..commands.bake import Bake, ExecutionMetadata
from .base import Bakery
from .execution_metadata import ExecutionMetadata


# Copied from https://github.com/jupyterhub/kubespawner/blob/7d6d82c2be469dd76f770d6f6ed0d1dade6b24a7/kubespawner/utils.py#L8
Expand Down Expand Up @@ -386,7 +386,7 @@ def bake(self, pipeline: Pipeline, meta: ExecutionMetadata) -> None:
pipeline.run()

@classmethod
def validate_bake_command(cls, bake_command: Bake) -> List[TraitError]:
def validate_bake_command(cls, bake_command: HasTraits) -> List[TraitError]:
errors = []
if not bake_command.container_image:
errors.append(
Expand Down
2 changes: 1 addition & 1 deletion pangeo_forge_runner/bakery/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from apache_beam.pipeline import Pipeline, PipelineOptions
from traitlets import Integer

from ..commands.bake import ExecutionMetadata
from .base import Bakery
from .execution_metadata import ExecutionMetadata


class LocalDirectBakery(Bakery):
Expand Down
26 changes: 4 additions & 22 deletions pangeo_forge_runner/commands/bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import re
import string
import time
from dataclasses import asdict, dataclass
from importlib.metadata import distributions
from pathlib import Path

Expand All @@ -16,37 +15,20 @@
from traitlets import Bool, TraitError, Type, Unicode, validate

from .. import Feedstock
from ..bakery.base import Bakery
from ..bakery.execution_metadata import ExecutionMetadata
from ..bakery.local import LocalDirectBakery
from ..plugin import get_injections, get_injectionspecs_from_entrypoints
from ..storage import InputCacheStorage, TargetStorage
from ..stream_capture import redirect_stderr, redirect_stdout
from .base import BaseCommand, common_aliases, common_flags


@dataclass
class ExecutionMetadata:
"""
Holds metadata for an execution instance, including recipe and job names.
Attributes:
recipe_name (str): Name of the recipe being executed.
job_name (str): Unique name for the job execution.
"""

recipe_name: str
job_name: str

def to_dict(self) -> dict:
return asdict(self)


class Bake(BaseCommand):
"""
Command to bake a pangeo forge recipe in a given bakery
"""

from ..bakery.base import Bakery
from ..bakery.local import LocalDirectBakery

aliases = common_aliases
flags = common_flags | {
"prune": (
Expand Down Expand Up @@ -258,7 +240,7 @@ def start(self):
self.log.info(f"Baking only recipe_id='{self.recipe_id}'")
recipes = {k: r for k, r in recipes.items() if k == self.recipe_id}

bakery = self.bakery_class(parent=self)
bakery: Bakery = self.bakery_class(parent=self)

extra_options = {}

Expand Down

0 comments on commit 9247382

Please sign in to comment.