Skip to content

Commit

Permalink
[components] Rename components dir to defs (#28108)
Browse files Browse the repository at this point in the history
## Summary & Motivation

This renames the default component generation dir to `defs` from
`components`.

## How I Tested These Changes

Existing test suite.
  • Loading branch information
smackesey authored Feb 27, 2025
1 parent b0ac0ea commit 12c4625
Show file tree
Hide file tree
Showing 78 changed files with 117 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ directory_type = "project"

[tool.dg.project]
root_module = "my_existing_project"
components_module = "my_existing_project.components"
components_module = "my_existing_project.defs"

[tool.dagster]
module_name = "my_existing_project.definitions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ tree jaffle_platform

jaffle_platform
├── __init__.py
├── components
├── definitions.py
├── defs
│   └── ingest_files
│   ├── component.yaml
│   └── replication.yaml
├── definitions.py
└── lib
└── __init__.py

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dg scaffold component dagster_components.lib.DbtProjectComponent jdbt --project-path dbt/jdbt

Creating a Dagster component instance folder at /.../jaffle-platform/jaffle_platform/components/jdbt.
Creating a Dagster component instance folder at /.../jaffle-platform/jaffle_platform/defs/jdbt.
Using /.../jaffle-platform/.venv/bin/dagster-components
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dg check yaml

/.../jaffle-platform/jaffle_platform/components/jdbt/component.yaml:7 - Unable to parse YAML: while scanning a quoted scalar, found unexpected end of stream
/.../jaffle-platform/jaffle_platform/defs/jdbt/component.yaml:7 - Unable to parse YAML: while scanning a quoted scalar, found unexpected end of stream
|
6 | asset_attributes:
7 | key: "target/main/{{ node.name }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cd jaffle-platform && tree
.
├── jaffle_platform
│   ├── __init__.py
│   ├── components
│   ├── definitions.py
│   ├── defs
│   └── lib
│   └── __init__.py
├── jaffle_platform.egg-info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from dagster_components import build_component_defs

defs = build_component_defs(components_root=Path(__file__).parent / "components")
defs = build_component_defs(components_root=Path(__file__).parent / "defs")
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dg scaffold component 'dagster_components.lib.SlingReplicationCollectionComponent' ingest_files

Creating a Dagster component instance folder at /.../jaffle-platform/jaffle_platform/components/ingest_files.
Creating a Dagster component instance folder at /.../jaffle-platform/jaffle_platform/defs/ingest_files.
Using /.../jaffle-platform/.venv/bin/dagster-components
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ tree
│   │   ├── __init__.py
│   │   ├── assets.py
│   │   └── jobs.py
│   ├── components
│   ├── definitions.py
│   ├── defs
│   └── elt
│   ├── __init__.py
│   ├── assets.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import dagster_components as dg_components

defs = dg_components.build_component_defs(Path(__file__).parent / "components")
defs = dg_components.build_component_defs(Path(__file__).parent / "defs")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dg scaffold component 'dagster_components.lib.DefinitionsComponent' elt-definitions

Using /.../my-existing-project/.venv/bin/dagster-components
Creating a Dagster component instance folder at /.../my-existing-project/my_existing_project/components/elt-definitions.
Creating a Dagster component instance folder at /.../my-existing-project/my_existing_project/defs/elt-definitions.
Using /.../my-existing-project/.venv/bin/dagster-components
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mv my_existing_project/elt/* my_existing_project/components/elt-definitions
mv my_existing_project/elt/* my_existing_project/defs/elt-definitions
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
jobs=[regenerate_analytics_job],
schedules=[regenerate_analytics_hourly_schedule],
),
dg_components.build_component_defs(Path(__file__).parent / "components"),
dg_components.build_component_defs(Path(__file__).parent / "defs"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ tree
│   │   ├── __init__.py
│   │   ├── assets.py
│   │   └── jobs.py
│   ├── components
│   │   └── elt-definitions
│   │   ── __init__.py
│   │   ├── assets.py
│   │   ├── component.yaml
│   │   ├── definitions.py
│   │   ── jobs.py
│   └── definitions.py
│   ├── definitions.py
│   └── defs
│   ── elt-definitions
│   ├── __init__.py
│   ├── assets.py
│   ├── component.yaml
│   ── definitions.py
│   └── jobs.py
├── pyproject.toml
└── uv.lock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ tree
├── README.md
├── my_existing_project
│   ├── __init__.py
│   ├── components
│   │   ├── analytics-definitions
│   │   │   ├── __init__.py
│   │   │   ├── assets.py
│   │   │   ├── component.yaml
│   │   │   ├── definitions.py
│   │   │   ── jobs.py
│   │   └── elt-definitions
│   │   ── __init__.py
│   │   ├── assets.py
│   │   ├── component.yaml
│   │   ├── definitions.py
│   │   ── jobs.py
│   └── definitions.py
│   ├── definitions.py
│   ── defs
│   ├── analytics-definitions
│   │   ├── __init__.py
│   │   ├── assets.py
│   │   ├── component.yaml
│   │   ── definitions.py
│   │   └── jobs.py
│   ── elt-definitions
│   ├── __init__.py
│   ├── assets.py
│   ├── component.yaml
│   ── definitions.py
│   └── jobs.py
├── pyproject.toml
└── uv.lock

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dg scaffold component 'my_component_library.lib.ShellCommand' my_shell_command

Using /.../my-component-library/.venv/bin/dagster-components
Creating a Dagster component instance folder at /.../my-component-library/my_component_library/components/my_shell_command.
Creating a Dagster component instance folder at /.../my-component-library/my_component_library/defs/my_shell_command.
Using /.../my-component-library/.venv/bin/dagster-components
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cd dagster-workspace && tree
│   └── project-1
│   ├── project_1
│   │   ├── __init__.py
│   │   ├── components
│   │   ├── definitions.py
│   │   ├── defs
│   │   └── lib
│   │   └── __init__.py
│   ├── project_1_tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def next_snip_no():
custom_comparison_fn=compare_tree_output,
)
check_file(
Path("jaffle_platform") / "components" / "ingest_files" / "component.yaml",
Path("jaffle_platform") / "defs" / "ingest_files" / "component.yaml",
COMPONENTS_SNIPPETS_DIR / f"{next_snip_no()}-component.yaml",
update_snippets=update_snippets,
)
Expand Down Expand Up @@ -193,7 +193,7 @@ def next_snip_no():
)
create_file(
file_path=Path("jaffle_platform")
/ "components"
/ "defs"
/ "ingest_files"
/ "replication.yaml",
snippet_path=COMPONENTS_SNIPPETS_DIR
Expand Down Expand Up @@ -258,14 +258,14 @@ def next_snip_no():
snippet_replace_regex=[MASK_JAFFLE_PLATFORM],
)
check_file(
Path("jaffle_platform") / "components" / "jdbt" / "component.yaml",
Path("jaffle_platform") / "defs" / "jdbt" / "component.yaml",
COMPONENTS_SNIPPETS_DIR / f"{next_snip_no()}-component-jdbt.yaml",
update_snippets=update_snippets,
)

# Update component file, with error, check and fix
create_file(
Path("jaffle_platform") / "components" / "jdbt" / "component.yaml",
Path("jaffle_platform") / "defs" / "jdbt" / "component.yaml",
snippet_path=COMPONENTS_SNIPPETS_DIR
/ f"{next_snip_no()}-project-jdbt-incorrect.yaml",
contents=format_multiline("""
Expand All @@ -290,7 +290,7 @@ def next_snip_no():
)

create_file(
Path("jaffle_platform") / "components" / "jdbt" / "component.yaml",
Path("jaffle_platform") / "defs" / "jdbt" / "component.yaml",
snippet_path=COMPONENTS_SNIPPETS_DIR
/ f"{next_snip_no()}-project-jdbt.yaml",
contents=format_multiline("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,15 @@ def test_components_docs_index(

check_file(
Path("my_component_library")
/ "components"
/ "defs"
/ "my_shell_command"
/ "component.yaml",
COMPONENTS_SNIPPETS_DIR
/ f"{get_next_snip_number()}-scaffolded-component.yaml",
update_snippets=update_snippets,
)
check_file(
Path("my_component_library")
/ "components"
/ "my_shell_command"
/ "script.sh",
Path("my_component_library") / "defs" / "my_shell_command" / "script.sh",
COMPONENTS_SNIPPETS_DIR
/ f"{get_next_snip_number()}-scaffolded-component-script.sh",
update_snippets=update_snippets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_components_docs_index(update_snippets: bool) -> None:
[tool.dg.project]
root_module = "my_existing_project"
components_module = "my_existing_project.components"
components_module = "my_existing_project.defs"
""")
pyproject_contents = pyproject_contents.replace(
"[tool.dagster]", f"{tool_dg_section}\n\n[tool.dagster]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ directory_type = "project"

[tool.dg.project]
root_module = "my_existing_project"
components_module = "my_existing_project.components"
components_module = "my_existing_project.defs"

[tool.dagster]
module_name = "my_existing_project.definitions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_components_docs_migrating_definitions(update_snippets: bool) -> None:
_run_command(
r"find . -type d -name my_existing_project.egg-info -exec rm -r {} \+"
)
_run_command("mkdir -p my_existing_project/components")
_run_command("mkdir -p my_existing_project/defs")

run_command_and_snippet_output(
cmd="tree",
Expand Down Expand Up @@ -69,17 +69,14 @@ def test_components_docs_migrating_definitions(update_snippets: bool) -> None:
)

run_command_and_snippet_output(
cmd="mv my_existing_project/elt/* my_existing_project/components/elt-definitions",
cmd="mv my_existing_project/elt/* my_existing_project/defs/elt-definitions",
snippet_path=COMPONENTS_SNIPPETS_DIR / f"{get_next_snip_number()}-mv.txt",
update_snippets=update_snippets,
)
_run_command("rm -rf my_existing_project/elt")

create_file(
Path("my_existing_project")
/ "components"
/ "elt-definitions"
/ "definitions.py",
Path("my_existing_project") / "defs" / "elt-definitions" / "definitions.py",
format_multiline("""
import dagster as dg
Expand All @@ -97,10 +94,7 @@ def test_components_docs_migrating_definitions(update_snippets: bool) -> None:
)

create_file(
Path("my_existing_project")
/ "components"
/ "elt-definitions"
/ "component.yaml",
Path("my_existing_project") / "defs" / "elt-definitions" / "component.yaml",
format_multiline("""
type: dagster_components.lib.DefinitionsComponent
Expand Down Expand Up @@ -130,7 +124,7 @@ def test_components_docs_migrating_definitions(update_snippets: bool) -> None:
jobs=[regenerate_analytics_job],
schedules=[regenerate_analytics_hourly_schedule],
),
dg_components.build_component_defs(Path(__file__).parent / "components"),
dg_components.build_component_defs(Path(__file__).parent / "defs"),
)
"""),
COMPONENTS_SNIPPETS_DIR / f"{get_next_snip_number()}-definitions-after.py",
Expand Down Expand Up @@ -159,11 +153,11 @@ def test_components_docs_migrating_definitions(update_snippets: bool) -> None:
cmd="dg scaffold component 'dagster_components.lib.DefinitionsComponent' analytics-definitions",
)
_run_command(
cmd="mv my_existing_project/analytics/* my_existing_project/components/analytics-definitions && rm -rf my_existing_project/analytics",
cmd="mv my_existing_project/analytics/* my_existing_project/defs/analytics-definitions && rm -rf my_existing_project/analytics",
)
create_file(
Path("my_existing_project")
/ "components"
/ "defs"
/ "analytics-definitions"
/ "definitions.py",
format_multiline("""
Expand All @@ -181,7 +175,7 @@ def test_components_docs_migrating_definitions(update_snippets: bool) -> None:
)
create_file(
Path("my_existing_project")
/ "components"
/ "defs"
/ "analytics-definitions"
/ "component.yaml",
format_multiline("""
Expand Down Expand Up @@ -211,7 +205,7 @@ def test_components_docs_migrating_definitions(update_snippets: bool) -> None:
import dagster_components as dg_components
defs = dg_components.build_component_defs(Path(__file__).parent / "components")
defs = dg_components.build_component_defs(Path(__file__).parent / "defs")
"""),
COMPONENTS_SNIPPETS_DIR
/ f"{get_next_snip_number()}-definitions-after-all.py",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def build_defs(self, context: ComponentLoadContext) -> Definitions:
In a typical setup you end up with module names such as "a_project.components.my_component.my_python_file".
This handles "__init__.py" files by ending the module name at the parent directory
(e.g "a_project.components.my_component") if the file resides at "a_project/components/my_component/__init__.py".
(e.g "a_project.components.my_component") if the file resides at "a_project/defs/my_component/__init__.py".
This calls importlib.import_module with that module name, going through the python module import system.
Expand All @@ -281,7 +281,7 @@ def build_defs(self, context: ComponentLoadContext) -> Definitions:
# Problematic
# See https://linear.app/dagster-labs/issue/BUILD-736/highly-suspect-hardcoding-of-components-string-is-component-relative
component_module_relative_path = abs_context_path.parts[
abs_context_path.parts.index("components") + 2 :
abs_context_path.parts.index("defs") + 2 :
]
component_module_name = ".".join([self.module_name, *component_module_relative_path])
if abs_file_path.name != "__init__.py":
Expand Down
Loading

1 comment on commit 12c4625

@github-actions
Copy link

@github-actions github-actions bot commented on 12c4625 Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for dagster-docs ready!

✅ Preview
https://dagster-docs-azsmdjstq-elementl.vercel.app

Built with commit 12c4625.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.