Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create path #103

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dbt_meshify/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

create_path = click.option(
"--create-path",
type=click.Path(exists=True),
type=click.Path(exists=False),
default=None,
help="The path to create the new dbt project. Defaults to the name argument supplied.",
)
Expand Down
9 changes: 5 additions & 4 deletions dbt_meshify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ def split(ctx, project_name, select, exclude, project_path, selector, create_pat
project_name=project_name, select=select, exclude=exclude, selector=selector
)
logger.info(f"Selected {len(subproject.resources)} resources: {subproject.resources}")
target_directory = Path(create_path) if create_path else None
subproject_creator = DbtSubprojectCreator(
subproject=subproject, target_directory=target_directory
)
if create_path:
create_path = Path(create_path).expanduser().resolve()
create_path.parent.mkdir(parents=True, exist_ok=True)

subproject_creator = DbtSubprojectCreator(subproject=subproject, target_directory=create_path)
logger.info(f"Creating subproject {subproject.name}...")
try:
subproject_creator.initialize()
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/test_split_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,29 @@ def test_split_one_model_one_source_custom_macro(self):
child_sql = (Path(dest_project_path) / "models" / "marts" / "orders.sql").read_text()
assert x_proj_ref in child_sql
teardown_test_project(dest_project_path)

def test_split_one_model_create_path(self):
setup_test_project(src_project_path, dest_project_path)
runner = CliRunner()
result = runner.invoke(
split,
[
"my_new_project",
"--project-path",
dest_project_path,
"--select",
"stg_orders",
"--create-path",
"test-projects/split/ham_sandwich",
],
)

assert result.exit_code == 0
assert (
Path("test-projects/split/ham_sandwich") / "models" / "staging" / "stg_orders.sql"
).exists()
x_proj_ref = "{{ ref('my_new_project', 'stg_orders') }}"
child_sql = (Path(dest_project_path) / "models" / "marts" / "orders.sql").read_text()
assert x_proj_ref in child_sql
teardown_test_project(dest_project_path)
teardown_test_project("test-projects/split/ham_sandwich")