Skip to content

Commit

Permalink
That was not fun.
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Feb 21, 2024
1 parent 7ff3ebd commit 91bc316
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
7 changes: 1 addition & 6 deletions pangeo_forge_runner/bakery/flink.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,7 @@ def bake(self, pipeline: Pipeline, meta: ExecutionMetadata) -> None:
@classmethod
def validate_bake_command(cls, bake_command: HasTraits) -> List[TraitError]:
errors = []
print("HERE, LOOK HERE.======================")
print(bake_command._trait_values)
print("====================================")
print(bake_command.container_image)
print("END, LOOK HERE.======================")
if not bake_command.container_image:
if not bake_command._trait_values["container_image"]:
errors.append(
TraitError(
"'container_image' is required when using the 'FlinkOperatorBakery' "
Expand Down
45 changes: 24 additions & 21 deletions pangeo_forge_runner/commands/bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ class Bake(BaseCommand):
""",
)

bakery_class = Type(
default_value=LocalDirectBakery,
klass=Bakery,
config=True,
help="""
The Bakery to bake this recipe in.
The Bakery (and its configuration) determine which Apache Beam
Runner is used, and how options for it are specified.
Defaults to LocalDirectBakery, which bakes the recipe using Apache
Beam's "DirectRunner". It doesn't use Docker or the cloud, and runs
everything locally. Useful only for testing!
""",
)

recipe_id = Unicode(
None,
allow_none=True,
Expand Down Expand Up @@ -88,23 +103,6 @@ class Bake(BaseCommand):
""",
)

# Note: This needs to be last, it appears, to ensure that other fields are set first.
# TODO: Terrible design. Rethink using traitlets if we can't defer to post-initialization.
bakery_class = Type(
default_value=LocalDirectBakery,
klass=Bakery,
config=True,
help="""
The Bakery to bake this recipe in.
The Bakery (and its configuration) determine which Apache Beam
Runner is used, and how options for it are specified.
Defaults to LocalDirectBakery, which bakes the recipe using Apache
Beam's "DirectRunner". It doesn't use Docker or the cloud, and runs
everything locally. Useful only for testing!
""",
)

@validate("job_name")
def _validate_job_name(self, proposal):
"""
Expand All @@ -123,8 +121,7 @@ def _validate_job_name(self, proposal):
)
return proposal.value

@validate("bakery_class")
def _bakery_impl_validation(self, proposal):
def bakery_impl_validation(self):
"""
Validates the 'bakery_class' trait using class-specific validation logic.
Expand All @@ -135,9 +132,12 @@ def _bakery_impl_validation(self, proposal):
Raises:
- TraitError: If multiple validation errors are encountered, a single TraitError
is raised containing a summary of all error messages.
Note: Traitlets has no convenient way to set initialization hooks (???) so we have
to run this manually.
"""
klass = proposal.value
if errors := klass.validate_bake_command(proposal.owner):
klass = self.bakery_class
if errors := klass.validate_bake_command(self):
if len(errors) == 1:
raise errors[0]
error_messages = "\n".join([str(error) for error in errors])
Expand Down Expand Up @@ -187,6 +187,9 @@ def start(self):
"""
Start the baking process
"""
# Validate bakery-specific requirements of this class. Yes, we have to do it here.
self.bakery_impl_validation()

if not "pangeo-forge-recipes" in [d.metadata["Name"] for d in distributions()]:
raise ValueError(
"To use the `bake` command, `pangeo-forge-recipes` must be installed."
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_job_name_validation(job_name, raises):
),
):
bake.job_name = job_name
bake.bakery_impl_validation()
else:
bake.job_name = job_name
assert bake.job_name == job_name
Expand All @@ -100,6 +101,7 @@ def test_container_image_validation(container_image, raises):
):
bake.bakery_class = "pangeo_forge_runner.bakery.flink.FlinkOperatorBakery"
bake.container_image = container_image
bake.bakery_impl_validation()
else:
bake.bakery_class = "pangeo_forge_runner.bakery.flink.FlinkOperatorBakery"
bake.container_image = container_image
Expand Down

0 comments on commit 91bc316

Please sign in to comment.