-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor LoadMethod.LOCAL to use symlinks instead of copying directory (
#660) This PR refactors the `create_symlinks` function that was previously used in load via dbt ls so that it can be used in `DbtLocalBaseOperator.run_command` instead of copying the entire directory. Closes: #614 (cherry picked from commit 5d23758)
- Loading branch information
Showing
11 changed files
with
46 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pathlib import Path | ||
import os | ||
from cosmos.constants import ( | ||
DBT_LOG_DIR_NAME, | ||
DBT_TARGET_DIR_NAME, | ||
) | ||
|
||
|
||
def create_symlinks(project_path: Path, tmp_dir: Path) -> None: | ||
"""Helper function to create symlinks to the dbt project files.""" | ||
ignore_paths = (DBT_LOG_DIR_NAME, DBT_TARGET_DIR_NAME, "dbt_packages", "profiles.yml") | ||
for child_name in os.listdir(project_path): | ||
if child_name not in ignore_paths: | ||
os.symlink(project_path / child_name, tmp_dir / child_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pathlib import Path | ||
from cosmos.dbt.project import create_symlinks | ||
|
||
DBT_PROJECTS_ROOT_DIR = Path(__file__).parent.parent.parent / "dev/dags/dbt" | ||
|
||
|
||
def test_create_symlinks(tmp_path): | ||
"""Tests that symlinks are created for expected files in the dbt project directory.""" | ||
tmp_dir = tmp_path / "dbt-project" | ||
tmp_dir.mkdir() | ||
|
||
create_symlinks(DBT_PROJECTS_ROOT_DIR / "jaffle_shop", tmp_dir) | ||
for child in tmp_dir.iterdir(): | ||
assert child.is_symlink() | ||
assert child.name not in ("logs", "target", "profiles.yml", "dbt_packages") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters