Skip to content

[components] Explicit glob in definitions #27945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import glob
import importlib
from pathlib import Path
from typing import Optional

from dagster._core.definitions.definitions_class import Definitions
from dagster._core.definitions.module_loaders.load_defs_from_module import (
load_definitions_from_module,
load_definitions_from_modules,
)
from dagster._utils import pushd
from pydantic import Field
Expand Down Expand Up @@ -49,12 +50,17 @@ def build_defs(self, context: ComponentLoadContext) -> Definitions:
]
component_module_name = ".".join([context.module_name, *component_module_relative_path])

defs_file_path = (
Path(self.definitions_path) if self.definitions_path else Path("definitions.py")
).absolute()
if defs_file_path.name != "__init__.py":
component_module_name = f"{component_module_name}.{defs_file_path.stem}"
defs_file_glob = self.definitions_path if self.definitions_path else "definitions.py"

module = importlib.import_module(component_module_name)
files = glob.glob(defs_file_glob)

return load_definitions_from_module(module)
module_names = []
for file in files:
module_names.append(f"{component_module_name}.{Path(file).stem}")

modules = []
for module_name in module_names:
module = importlib.import_module(module_name)
modules.append(module)

return load_definitions_from_modules(modules)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type: definitions@dagster_components

params:
definitions_path: "*.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dagster import asset


@asset
def file_one_asset() -> None: ...
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ def test_definitions_component_validation_error() -> None:
load_test_component_defs("definitions/validation_error_file")

assert "component.yaml:4" in str(e.value)


def test_definitions_explicit_glob() -> None:
defs = load_test_component_defs("definitions/explicit_glob")
assert {spec.key for spec in defs.get_all_asset_specs()} == {
AssetKey("file_one_asset"),
}
Loading