Skip to content

Commit

Permalink
File and test refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeng817 committed Dec 18, 2024
1 parent d4250b7 commit 0f54413
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from dagster._core.definitions.load_assets_from_modules import load_assets_from_modules
from dagster._core.definitions.materialize import materialize
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
load_assets_from_modules,
)
from docs_snippets.guides.dagster.asset_tutorial import cereal
from docs_snippets.intro_tutorial.test_util import patch_cereal_requests

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from dagster._core.definitions.load_assets_from_modules import load_assets_from_modules
from dagster._core.definitions.materialize import materialize
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
load_assets_from_modules,
)
from docs_snippets.guides.dagster.asset_tutorial import serial_asset_graph
from docs_snippets.intro_tutorial.test_util import patch_cereal_requests

Expand Down
24 changes: 12 additions & 12 deletions python_modules/dagster/dagster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,6 @@
InputMapping as InputMapping,
)
from dagster._core.definitions.job_definition import JobDefinition as JobDefinition
from dagster._core.definitions.load_asset_checks_from_modules import (
load_asset_checks_from_current_module as load_asset_checks_from_current_module,
load_asset_checks_from_modules as load_asset_checks_from_modules,
load_asset_checks_from_package_module as load_asset_checks_from_package_module,
load_asset_checks_from_package_name as load_asset_checks_from_package_name,
)
from dagster._core.definitions.load_assets_from_modules import (
load_assets_from_current_module as load_assets_from_current_module,
load_assets_from_modules as load_assets_from_modules,
load_assets_from_package_module as load_assets_from_package_module,
load_assets_from_package_name as load_assets_from_package_name,
)
from dagster._core.definitions.logger_definition import (
LoggerDefinition as LoggerDefinition,
build_init_logger_context as build_init_logger_context,
Expand Down Expand Up @@ -309,6 +297,18 @@
TableRecord as TableRecord,
TableSchema as TableSchema,
)
from dagster._core.definitions.module_loaders.load_asset_checks_from_modules import (
load_asset_checks_from_current_module as load_asset_checks_from_current_module,
load_asset_checks_from_modules as load_asset_checks_from_modules,
load_asset_checks_from_package_module as load_asset_checks_from_package_module,
load_asset_checks_from_package_name as load_asset_checks_from_package_name,
)
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
load_assets_from_current_module as load_assets_from_current_module,
load_assets_from_modules as load_assets_from_modules,
load_assets_from_package_module as load_assets_from_package_module,
load_assets_from_package_name as load_assets_from_package_name,
)
from dagster._core.definitions.multi_asset_sensor_definition import (
MultiAssetSensorDefinition as MultiAssetSensorDefinition,
MultiAssetSensorEvaluationContext as MultiAssetSensorEvaluationContext,
Expand Down
4 changes: 3 additions & 1 deletion python_modules/dagster/dagster/_core/code_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def describe(self) -> str:


def _load_target_from_module(module: ModuleType, fn_name: str, error_suffix: str) -> object:
from dagster._core.definitions.load_assets_from_modules import load_assets_from_modules
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
load_assets_from_modules,
)
from dagster._core.workspace.autodiscovery import LOAD_ALL_ASSETS

if fn_name == LOAD_ALL_ASSETS:
Expand Down
10 changes: 5 additions & 5 deletions python_modules/dagster/dagster/_core/definitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@
)
from dagster._core.definitions.graph_definition import GraphDefinition as GraphDefinition
from dagster._core.definitions.job_definition import JobDefinition as JobDefinition
from dagster._core.definitions.load_assets_from_modules import (
from dagster._core.definitions.materialize import (
materialize as materialize,
materialize_to_memory as materialize_to_memory,
)
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
load_assets_from_current_module as load_assets_from_current_module,
load_assets_from_modules as load_assets_from_modules,
load_assets_from_package_module as load_assets_from_package_module,
load_assets_from_package_name as load_assets_from_package_name,
)
from dagster._core.definitions.materialize import (
materialize as materialize,
materialize_to_memory as materialize_to_memory,
)
from dagster._core.definitions.op_definition import OpDefinition as OpDefinition
from dagster._core.definitions.partition import (
DynamicPartitionsDefinition as DynamicPartitionsDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
check_opt_coercible_to_asset_key_prefix_param,
)
from dagster._core.definitions.assets import AssetsDefinition
from dagster._core.definitions.load_assets_from_modules import (
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
LoadedAssetsList,
find_modules_in_package,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from dagster import DagsterInvariantViolationError, GraphDefinition, RepositoryDefinition
from dagster._core.code_pointer import load_python_file, load_python_module
from dagster._core.definitions.definitions_class import Definitions
from dagster._core.definitions.load_assets_from_modules import load_assets_from_modules
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
load_assets_from_modules,
)

LOAD_ALL_ASSETS = "<<LOAD_ALL_ASSETS>>"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from dagster._core.definitions.decorators.asset_check_decorator import asset_check
from dagster._core.definitions.dependency import NodeHandle, NodeInvocation
from dagster._core.definitions.executor_definition import in_process_executor
from dagster._core.definitions.load_assets_from_modules import prefix_assets
from dagster._core.definitions.module_loaders.load_assets_from_modules import prefix_assets
from dagster._core.errors import DagsterInvalidSubsetError
from dagster._core.execution.api import execute_run_iterator
from dagster._core.snap import DependencyStructureIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from dagster._core.definitions import asset, multi_asset
from dagster._core.definitions.decorators.hook_decorator import failure_hook, success_hook
from dagster._core.definitions.definitions_class import Definitions
from dagster._core.definitions.load_assets_from_modules import prefix_assets
from dagster._core.definitions.module_loaders.load_assets_from_modules import prefix_assets
from dagster._core.definitions.partition import (
StaticPartitionsDefinition,
static_partitioned_config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

# importing this makes it show up twice when we collect everything
from dagster_tests.asset_defs_tests.asset_package.asset_subpackage.another_module_with_assets import (
from dagster_tests.definitions_tests.module_loader_tests.asset_package.asset_subpackage.another_module_with_assets import (
miles_davis,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@


def test_load_asset_checks_from_modules():
from dagster_tests.definitions_tests.asset_check_tests import checks_module
from dagster_tests.definitions_tests.asset_check_tests.checks_module import asset_check_1
from dagster_tests.definitions_tests.module_loader_tests import checks_module
from dagster_tests.definitions_tests.module_loader_tests.checks_module import asset_check_1

checks = load_asset_checks_from_modules([checks_module])
assert len(checks) == 1
Expand All @@ -47,7 +47,7 @@ def test_load_asset_checks_from_modules():


def test_load_asset_checks_from_modules_prefix():
from dagster_tests.definitions_tests.asset_check_tests import checks_module
from dagster_tests.definitions_tests.module_loader_tests import checks_module

checks = load_asset_checks_from_modules([checks_module], asset_key_prefix="foo")
assert len(checks) == 1
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_load_asset_checks_from_current_module():
],
)
def test_load_asset_checks_from_package(load_fns):
from dagster_tests.definitions_tests.asset_check_tests import checks_module
from dagster_tests.definitions_tests.module_loader_tests import checks_module

assets_load_fn, checks_load_fn = load_fns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_source_asset_with_key(


def test_load_assets_from_package_name():
from dagster_tests.asset_defs_tests import asset_package
from dagster_tests.definitions_tests.module_loader_tests import asset_package

assets_defs = load_assets_from_package_name(asset_package.__name__)
assert len(assets_defs) == 11
Expand All @@ -113,7 +113,7 @@ def test_load_assets_from_package_name():


def test_load_assets_from_package_module():
from dagster_tests.asset_defs_tests import asset_package
from dagster_tests.definitions_tests.module_loader_tests import asset_package

assets_1 = load_assets_from_package_module(asset_package)
assert len(assets_1) == 11
Expand All @@ -138,8 +138,8 @@ def test_load_assets_from_package_module():


def test_load_assets_from_modules(monkeypatch):
from dagster_tests.asset_defs_tests import asset_package
from dagster_tests.asset_defs_tests.asset_package import module_with_assets
from dagster_tests.definitions_tests.module_loader_tests import asset_package
from dagster_tests.definitions_tests.module_loader_tests.asset_package import module_with_assets

collection_1 = load_assets_from_modules([asset_package, module_with_assets])

Expand Down Expand Up @@ -204,8 +204,8 @@ def test_load_assets_from_current_module():


def test_load_assets_from_modules_with_group_name():
from dagster_tests.asset_defs_tests import asset_package
from dagster_tests.asset_defs_tests.asset_package import module_with_assets
from dagster_tests.definitions_tests.module_loader_tests import asset_package
from dagster_tests.definitions_tests.module_loader_tests.asset_package import module_with_assets

assets = load_assets_from_modules(
[asset_package, module_with_assets], group_name="my_cool_group"
Expand All @@ -226,8 +226,8 @@ def test_respect_existing_groups():


def test_load_assets_with_freshness_policy():
from dagster_tests.asset_defs_tests import asset_package
from dagster_tests.asset_defs_tests.asset_package import module_with_assets
from dagster_tests.definitions_tests.module_loader_tests import asset_package
from dagster_tests.definitions_tests.module_loader_tests.asset_package import module_with_assets

assets = load_assets_from_modules(
[asset_package, module_with_assets],
Expand All @@ -242,8 +242,8 @@ def test_load_assets_with_freshness_policy():


def test_load_assets_with_auto_materialize_policy():
from dagster_tests.asset_defs_tests import asset_package
from dagster_tests.asset_defs_tests.asset_package import module_with_assets
from dagster_tests.definitions_tests.module_loader_tests import asset_package
from dagster_tests.definitions_tests.module_loader_tests.asset_package import module_with_assets

assets = load_assets_from_modules(
[asset_package, module_with_assets], auto_materialize_policy=AutoMaterializePolicy.eager()
Expand All @@ -265,8 +265,8 @@ def test_load_assets_with_auto_materialize_policy():
],
)
def test_prefix(prefix):
from dagster_tests.asset_defs_tests import asset_package
from dagster_tests.asset_defs_tests.asset_package import module_with_assets
from dagster_tests.definitions_tests.module_loader_tests import asset_package
from dagster_tests.definitions_tests.module_loader_tests.asset_package import module_with_assets

assets = load_assets_from_modules([asset_package, module_with_assets], key_prefix=prefix)
assert_assets_have_prefix(prefix, assets) # pyright: ignore[reportArgumentType]
Expand All @@ -276,7 +276,7 @@ def test_prefix(prefix):


def _load_assets_from_module_with_assets(**kwargs):
from dagster_tests.asset_defs_tests.asset_package import module_with_assets
from dagster_tests.definitions_tests.module_loader_tests.asset_package import module_with_assets

return load_assets_from_modules([module_with_assets], **kwargs)

Expand All @@ -286,7 +286,7 @@ def _load_assets_from_module_with_assets(**kwargs):
[
_load_assets_from_module_with_assets,
lambda **kwargs: load_assets_from_package_name(
"dagster_tests.asset_defs_tests.asset_package", **kwargs
"dagster_tests.definitions_tests.module_loader_tests.asset_package", **kwargs
),
],
)
Expand Down Expand Up @@ -339,7 +339,7 @@ def test_source_key_prefix(load_fn):
)
def test_load_assets_cacheable(load_fn, prefix):
"""Tests the load-from-module and load-from-package-name functinos with cacheable assets."""
from dagster_tests.asset_defs_tests import asset_package_with_cacheable
from dagster_tests.definitions_tests.module_loader_tests import asset_package_with_cacheable

assets_defs = load_fn(asset_package_with_cacheable)
assert len(assets_defs) == 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def __repr__(self) -> str:


def get_registered_components_in_module(module: ModuleType) -> Iterable[Type[Component]]:
from dagster._core.definitions.load_assets_from_modules import find_subclasses_in_module
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
find_subclasses_in_module,
)

for component in find_subclasses_in_module(module, (Component,)):
if is_registered_component(component):
Expand Down
4 changes: 3 additions & 1 deletion python_modules/libraries/dagster-dbt/dagster_dbt/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import yaml
from dagster._cli.project import check_if_pypi_package_conflict_exists
from dagster._core.code_pointer import load_python_file
from dagster._core.definitions.load_assets_from_modules import find_objects_in_module_of_types
from dagster._core.definitions.module_loaders.load_assets_from_modules import (
find_objects_in_module_of_types,
)
from jinja2 import Environment, FileSystemLoader
from rich.console import Console
from rich.syntax import Syntax
Expand Down

0 comments on commit 0f54413

Please sign in to comment.