Skip to content

Commit

Permalink
[components] Generate logic for DefinitionsComponent (#26657)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Adding basic scaffolding logic for this one. Want to discuss what the right testing harness is for stuff because it is potentially a huge pain.

## How I Tested These Changes

Manual
  • Loading branch information
schrockn authored Dec 21, 2024
1 parent ea2977b commit 4a9ffa6
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Optional
from typing import Any, Optional

from dagster._core.definitions.definitions_class import Definitions
from dagster._core.definitions.module_loaders.load_defs_from_module import (
Expand All @@ -11,6 +11,7 @@
from typing_extensions import Self

from dagster_components import Component, ComponentGenerateRequest, ComponentLoadContext, component
from dagster_components.generate import generate_component_yaml


class DefinitionsGenerateParams(BaseModel):
Expand Down Expand Up @@ -43,7 +44,21 @@ def build_defs(self, context: ComponentLoadContext) -> Definitions:
return load_definitions_from_module(module)

@classmethod
def generate_files(
cls, request: ComponentGenerateRequest, params: DefinitionsGenerateParams
) -> None:
raise NotImplementedError("Not implemented")
def generate_files(cls, request: ComponentGenerateRequest, params: Any) -> None:
generate_params = (
params if isinstance(params, DefinitionsGenerateParams) else DefinitionsGenerateParams()
)

with pushd(str(request.component_instance_root_path)):
Path(
generate_params.definitions_path
if generate_params.definitions_path
else "definitions.py"
).touch(exist_ok=True)

generate_component_yaml(
request,
{"definitions_path": generate_params.definitions_path}
if generate_params.definitions_path
else {},
)

0 comments on commit 4a9ffa6

Please sign in to comment.