Skip to content

Commit

Permalink
Revert to target_path, rename on_load by ensure_prepared
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Jun 20, 2024
1 parent 77ba16e commit a8cd258
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
Binary file modified docs/content/api/modules.json.gz
Binary file not shown.
Binary file modified docs/content/api/searchindex.json.gz
Binary file not shown.
Binary file modified docs/content/api/sections.json.gz
Binary file not shown.
29 changes: 15 additions & 14 deletions python_modules/libraries/dagster-dbt/dagster_dbt/dbt_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def using_dagster_dev() -> bool:
class DbtManifestPreparer:
"""A dbt manifest represented by DbtProject."""

def on_load(self, project: "DbtProject") -> None:
def ensure_prepared(self, project: "DbtProject") -> None:
"""Invoked when DbtProject is instantiated with this preparer."""

def prepare(self, project: "DbtProject") -> None:
Expand Down Expand Up @@ -55,7 +55,7 @@ def __init__(
"""
self._generate_cli_args = generate_cli_args or ["parse", "--quiet"]

def on_load(self, project: "DbtProject"):
def ensure_prepared(self, project: "DbtProject"):
if self.using_dagster_dev() or self.parse_on_load_opt_in():
self.prepare(project)
if not project.manifest_path.exists():
Expand Down Expand Up @@ -91,7 +91,7 @@ def _prepare_packages(self, project: "DbtProject") -> None:

(
DbtCliResource(project_dir=project)
.cli(["deps", "--quiet"], target_path=project.output_path)
.cli(["deps", "--quiet"], target_path=project.target_path)
.wait()
)

Expand All @@ -102,7 +102,7 @@ def _prepare_manifest(self, project: "DbtProject") -> None:
DbtCliResource(project_dir=project)
.cli(
self._generate_cli_args,
target_path=project.output_path,
target_path=project.target_path,
)
.wait()
)
Expand All @@ -111,23 +111,24 @@ def _prepare_manifest(self, project: "DbtProject") -> None:
@experimental
@dagster_model_custom
class DbtProject(IHaveNew):
"""Representation of a dbt project and related settings that assist with managing manifest.json preparation.
"""Representation of a dbt project and related settings that assist with managing the project preparation.
By default, using this helps achieve a setup where:
* during development, reload the manifest at run time to pick up any changes.
By default, using this helps achieve a setup where the dbt manifest file
and dbt dependencies are available and up-to-date:
* during development, pull the dependencies and reload the manifest at run time to pick up any changes.
* when deployed, expect a manifest that was created at build time to reduce start-up time.
The cli ``dagster-dbt project prepare-for-deployment`` can be used as part of the deployment process to
handle manifest.json preparation.
handle the project preparation.
This object can be passed directly to :py:class:`~dagster_dbt.DbtCliResource`.
Args:
project_dir (Union[str, Path]):
The directory of the dbt project.
output_path (Union[str, Path]):
target_path (Union[str, Path]):
The path, relative to the project directory, to output artifacts.
In a dbt project, it corresponds to the target path.
It corresponds to the target path in dbt.
Default: "target"
target (Optional[str]):
The target from your dbt `profiles.yml` to use for execution, if it should be explicitly set.
Expand Down Expand Up @@ -181,7 +182,7 @@ def get_env():
"""

project_dir: Path
output_path: Path
target_path: Path
target: Optional[str]
manifest_path: Path
packaged_project_dir: Optional[Path]
Expand All @@ -193,7 +194,7 @@ def __new__(
cls,
project_dir: Union[Path, str],
*,
output_path: Union[Path, str] = Path("target"),
target_path: Union[Path, str] = Path("target"),
target: Optional[str] = None,
packaged_project_dir: Optional[Union[Path, str]] = None,
state_path: Optional[Union[Path, str]] = None,
Expand All @@ -207,7 +208,7 @@ def __new__(
if not using_dagster_dev() and packaged_project_dir and packaged_project_dir.exists():
project_dir = packaged_project_dir

manifest_path = project_dir.joinpath(output_path, "manifest.json")
manifest_path = project_dir.joinpath(target_path, "manifest.json")

dependencies_path = project_dir.joinpath("dependencies.yml")
packages_path = project_dir.joinpath("packages.yml")
Expand All @@ -231,7 +232,7 @@ def __new__(
return super().__new__(
cls,
project_dir=project_dir,
output_path=output_path,
target_path=target_path,
target=target,
manifest_path=manifest_path,
state_path=project_dir.joinpath(state_path) if state_path else None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def test_dbt_cli_defer_args(monkeypatch: pytest.MonkeyPatch, testrun_uid: str) -
project = DbtProject(project_dir=test_jaffle_shop_path, state_path=Path("state", testrun_uid))
dbt = DbtCliResource(project_dir=project)

dbt.cli(["--quiet", "parse"], target_path=project.output_path).wait()
dbt.cli(["--quiet", "parse"], target_path=project.target_path).wait()

@dbt_assets(manifest=project.ensure_prepared().manifest_path)
def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
Expand Down

0 comments on commit a8cd258

Please sign in to comment.