From c79d9eb6cb7c8246966751d23ec317b36c1a473d Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 24 Jul 2023 09:33:03 -0500 Subject: [PATCH 1/2] allow create_path to accept any Path arg --- dbt_meshify/cli.py | 2 +- dbt_meshify/main.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dbt_meshify/cli.py b/dbt_meshify/cli.py index 9a765ca..f4b9f46 100644 --- a/dbt_meshify/cli.py +++ b/dbt_meshify/cli.py @@ -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.", ) diff --git a/dbt_meshify/main.py b/dbt_meshify/main.py index 6787435..da7ccaf 100644 --- a/dbt_meshify/main.py +++ b/dbt_meshify/main.py @@ -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() From ed66dbe1fe4ea21dd6279d05a40e88806b75b9b7 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 24 Jul 2023 09:45:25 -0500 Subject: [PATCH 2/2] update test case --- tests/integration/test_split_command.py | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/integration/test_split_command.py b/tests/integration/test_split_command.py index 3c96374..d154e27 100644 --- a/tests/integration/test_split_command.py +++ b/tests/integration/test_split_command.py @@ -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")