Skip to content

Commit

Permalink
[components] Move dagster_components.lib.test -> dagster_components_t…
Browse files Browse the repository at this point in the history
…ests.components
  • Loading branch information
smackesey committed Feb 27, 2025
1 parent 53cba88 commit 56af59b
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 95 deletions.
17 changes: 17 additions & 0 deletions python_modules/dagster-test/dagster_test/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import importlib.util

_has_dagster_components = importlib.util.find_spec("dagster_components") is not None

if not _has_dagster_components:
raise Exception("dagster-components is not installed")

from dagster_test.components.all_metadata_empty_asset import (
AllMetadataEmptyComponent as AllMetadataEmptyComponent,
)
from dagster_test.components.complex_schema_asset import (
ComplexAssetComponent as ComplexAssetComponent,
)
from dagster_test.components.simple_asset import SimpleAssetComponent as SimpleAssetComponent
from dagster_test.components.simple_pipes_script_asset import (
SimplePipesScriptComponent as SimplePipesScriptComponent,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from dagster._core.definitions.decorators.asset_decorator import asset
from dagster._core.definitions.definitions_class import Definitions
from dagster._core.execution.context.asset_execution_context import AssetExecutionContext

from dagster_components import Component, ComponentLoadContext
from dagster_components.core.component_scaffolder import DefaultComponentScaffolder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from dagster._core.definitions.decorators.asset_decorator import asset
from dagster._core.definitions.definitions_class import Definitions
from dagster._core.execution.context.asset_execution_context import AssetExecutionContext
from pydantic import Field

from dagster_components import Component, ComponentLoadContext
from dagster_components.core.component_scaffolder import DefaultComponentScaffolder
from dagster_components.core.schema.base import ResolvableSchema
Expand All @@ -16,6 +14,7 @@
OpSpecSchema,
PostProcessorFn,
)
from pydantic import Field


class ComplexAssetSchema(ResolvableSchema["ComplexAssetComponent"]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from dagster._core.definitions.decorators.asset_decorator import asset
from dagster._core.definitions.definitions_class import Definitions
from dagster._core.execution.context.asset_execution_context import AssetExecutionContext
from pydantic import BaseModel

from dagster_components import Component, ComponentLoadContext
from dagster_components.core.component_scaffolder import (
ComponentScaffolder,
DefaultComponentScaffolder,
)
from pydantic import BaseModel


class SimpleAssetSchema(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
from dagster._core.definitions.definitions_class import Definitions
from dagster._core.execution.context.asset_execution_context import AssetExecutionContext
from dagster._core.pipes.subprocess import PipesSubprocessClient
from pydantic import BaseModel

from dagster_components import Component, ComponentLoadContext
from dagster_components.core.component_scaffolder import (
ComponentScaffolder,
ComponentScaffoldRequest,
)
from dagster_components.scaffold import scaffold_component_yaml
from pydantic import BaseModel


# Same schema used for file generation and defs generation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import importlib.util
import os

from dagster import Field, In, String, graph, op, resource

_has_pyspark = importlib.util.find_spec("pyspark") is not None
if not _has_pyspark:
raise Exception("This example requires the pyspark package")

from pyspark.sql import SparkSession, Window
from pyspark.sql.functions import (
col,
Expand Down
7 changes: 6 additions & 1 deletion python_modules/dagster-test/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
python_requires=">=3.9,<3.13",
install_requires=[
"dagster",
"pyspark",
"dagster-components",
"rich",
],
extras_require={
# Eventually we sholud remove this as an extra and just include it in the main package
"components": ["dagster-components"],
"pyspark": ["pyspark"],
},
zip_safe=False,
)
3 changes: 2 additions & 1 deletion python_modules/dagster-test/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ deps =
-e ../dagster[test]
-e ../dagster-pipes
-e ../dagster-graphql
-e ../libraries/dagster-components
-e ../libraries/dagster-pandas
-e ../libraries/dagster-aws
-e ../libraries/dagster-gcp
Expand All @@ -24,7 +25,7 @@ deps =
-e ../libraries/dagster-celery-k8s
-e ../libraries/dagster-celery-docker
-e ../libraries/dagstermill
-e .
-e .[pyspark]
allowlist_externals =
/bin/bash
uv
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ def test_list_components_types_from_module():
# Now check what we get when we load directly from the test component library. This has stable
# results.
result = runner.invoke(
cli, ["list", "component-types", "--no-entry-points", "dagster_components.lib.test"]
cli, ["list", "component-types", "--no-entry-points", "dagster_test.components"]
)
assert result.exit_code == 0
result = json.loads(result.output)
assert len(result) > 1

assert list(result.keys()) == [
"dagster_components.lib.test.AllMetadataEmptyComponent",
"dagster_components.lib.test.ComplexAssetComponent",
"dagster_components.lib.test.SimpleAssetComponent",
"dagster_components.lib.test.SimplePipesScriptComponent",
"dagster_test.components.AllMetadataEmptyComponent",
"dagster_test.components.ComplexAssetComponent",
"dagster_test.components.SimpleAssetComponent",
"dagster_test.components.SimplePipesScriptComponent",
]

assert result["dagster_components.lib.test.SimpleAssetComponent"] == {
assert result["dagster_test.components.SimpleAssetComponent"] == {
"name": "SimpleAssetComponent",
"namespace": "dagster_components.lib.test",
"namespace": "dagster_test.components",
"summary": "A simple asset that returns a constant string value.",
"description": "A simple asset that returns a constant string value.",
"scaffold_params_schema": None,
Expand All @@ -73,9 +73,9 @@ def test_list_components_types_from_module():
"type": "object",
}

assert result["dagster_components.lib.test.SimplePipesScriptComponent"] == {
assert result["dagster_test.components.SimplePipesScriptComponent"] == {
"name": "SimplePipesScriptComponent",
"namespace": "dagster_components.lib.test",
"namespace": "dagster_test.components",
"summary": "A simple asset that runs a Python script with the Pipes subprocess client.",
"description": "A simple asset that runs a Python script with the Pipes subprocess client.\n\nBecause it is a pipes asset, no value is returned.",
"scaffold_params_schema": pipes_script_params_schema,
Expand Down Expand Up @@ -156,7 +156,13 @@ def test_all_components_schema_command():
runner = CliRunner()

result = runner.invoke(
cli, ["list", "all-components-schema", "--no-entry-points", "dagster_components.lib.test"]
cli,
[
"list",
"all-components-schema",
"--no-entry-points",
"dagster_test.components",
],
)
assert_runner_result(result)
result = json.loads(result.output)
Expand All @@ -178,25 +184,25 @@ def test_all_components_schema_command():
assert "type" in component_type_schema_def["properties"]
assert (
component_type_schema_def["properties"]["type"]["default"]
== f"dagster_components.lib.test.{component_type_key}"
== f"dagster_test.components.{component_type_key}"
)
assert (
component_type_schema_def["properties"]["type"]["const"]
== f"dagster_components.lib.test.{component_type_key}"
== f"dagster_test.components.{component_type_key}"
)
assert "attributes" in component_type_schema_def["properties"]

top_level_component_validator = Draft202012Validator(schema=result)
top_level_component_validator.validate(
{
"type": "dagster_components.lib.test.SimpleAssetComponent",
"type": "dagster_test.components.SimpleAssetComponent",
"attributes": {"asset_key": "my_asset", "value": "my_value"},
}
)
with pytest.raises(ValidationError):
top_level_component_validator.validate(
{
"type": "dagster_components.lib.test.SimpleAssetComponent",
"type": "dagster_test.components.SimpleAssetComponent",
"attributes": {"asset_key": "my_asset", "value": "my_value"},
"extra_key": "extra_value",
}
Expand All @@ -212,7 +218,7 @@ def test_scaffold_component_command():
[
"scaffold",
"component",
"dagster_components.lib.test.SimplePipesScriptComponent",
"dagster_test.components.SimplePipesScriptComponent",
"bar/components/qux",
"--json-params",
'{"asset_key": "my_asset", "filename": "my_asset.py"}',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type: dagster_components.lib.test.SimpleAssetComponent
type: dagster_components_tests.lib.SimpleAssetComponent

attributes:
asset_key: "test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

_COMPONENT_LIBRARY_MODULES = [
"dagster_components.lib",
"dagster_components.lib.test",
"dagster_test.components",
]


Expand Down
2 changes: 1 addition & 1 deletion python_modules/libraries/dagster-components/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def get_version() -> str:
extras_require={
"sling": ["dagster-sling"],
"dbt": ["dagster-dbt"],
"test": ["dbt-duckdb", "dagster-dg", "tomlkit", "jsonschema"],
"test": ["dagster-test", "dbt-duckdb", "dagster-dg", "tomlkit", "jsonschema"],
},
)
16 changes: 10 additions & 6 deletions python_modules/libraries/dagster-dg/dagster_dg/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections.abc import Iterable, Mapping
from functools import cached_property
from pathlib import Path
from typing import Final, Optional
from typing import Final, Optional, Union

import tomlkit
import tomlkit.items
Expand Down Expand Up @@ -205,7 +205,8 @@ def cache(self) -> DgCache:
def has_cache(self) -> bool:
return self._cache is not None

def get_cache_key(self, data_type: CachableDataType) -> tuple[str, str, str]:
# Allowing open-ended str data_type for now so we can do module names
def get_cache_key(self, data_type: Union[CachableDataType, str]) -> tuple[str, str, str]:
path_parts = [str(part) for part in self.root_path.parts if part != self.root_path.anchor]
paths_to_hash = [
self.root_path / "uv.lock",
Expand All @@ -215,10 +216,13 @@ def get_cache_key(self, data_type: CachableDataType) -> tuple[str, str, str]:
return ("_".join(path_parts), env_hash, data_type)

def get_cache_key_for_module(self, module_name: str) -> tuple[str, str, str]:
path = self.get_path_for_module(module_name)
env_hash = hash_paths([path], includes=["*.py"])
path_parts = [str(part) for part in path.parts if part != "/"]
return ("_".join(path_parts), env_hash, "local_component_registry")
if module_name.startswith(self.root_module_name):
path = self.get_path_for_module(module_name)
env_hash = hash_paths([path], includes=["*.py"])
path_parts = [str(part) for part in path.parts if part != "/"]
return ("_".join(path_parts), env_hash, "local_component_registry")
else:
return self.get_cache_key(module_name)

# ########################
# ##### WORKSPACE METHODS
Expand Down
1 change: 1 addition & 0 deletions python_modules/libraries/dagster-dg/dagster_dg/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"dagster",
"dagster-pipes",
"dagster-components",
"dagster-test[components]", # we include dagster-test for testing purposes
)
EDITABLE_DAGSTER_DEV_DEPENDENCIES = ("dagster-webserver", "dagster-graphql")
PYPI_DAGSTER_DEPENDENCIES = ("dagster-components",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_dynamic_subcommand_help_message():
result = runner.invoke(
"scaffold",
"component",
"dagster_components.lib.test.SimplePipesScriptComponent",
"dagster_test.components.SimplePipesScriptComponent",
"--help",
)
assert_runner_result(result)
Expand All @@ -189,8 +189,9 @@ def test_dynamic_subcommand_help_message():
assert match_terminal_box_output(
output.strip(),
textwrap.dedent("""
Usage: dg scaffold component [GLOBAL OPTIONS] dagster_components.lib.test.SimplePipesScriptComponent
[OPTIONS] COMPONENT_INSTANCE_NAME
Usage: dg scaffold component [GLOBAL OPTIONS] dagster_test.components.SimplePipesScriptComponent [OPTIONS]
COMPONENT_INSTANCE_NA
ME
╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ * component_instance_name TEXT [required] │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def test_docs_component_type_success():
with ProxyRunner.test() as runner, isolated_components_venv(runner):
result = runner.invoke(
"docs", "component-type", "dagster_components.lib.test.SimpleAssetComponent"
"docs", "component-type", "dagster_test.components.SimpleAssetComponent"
)
assert_runner_result(result)

Expand All @@ -30,7 +30,7 @@ def test_docs_component_type_success_output_console():
result = runner.invoke(
"docs",
"component-type",
"dagster_components.lib.test.ComplexAssetComponent",
"dagster_test.components.ComplexAssetComponent",
"--output",
"cli",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def to_cli_args(self) -> tuple[str, ...]:
return (*self.command, *self.args)


DEFAULT_COMPONENT_TYPE = "dagster_components.lib.test.SimpleAssetComponent"
DEFAULT_COMPONENT_TYPE = "dagster_test.components.SimpleAssetComponent"

NO_REQUIRED_CONTEXT_COMMANDS = [
CommandSpec(("scaffold", "project"), "foo"),
Expand Down
Loading

0 comments on commit 56af59b

Please sign in to comment.