-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from palmetto/release/v0.7.0
v0.7.0 release
- Loading branch information
Showing
11 changed files
with
153 additions
and
49 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
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
@click.group() | ||
def cli(): | ||
"""DBT model tools""" | ||
"""dbt model tools""" | ||
pass | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,42 +1,99 @@ | ||
import click | ||
from typing import Optional, Tuple | ||
from palm.plugins.dbt.dbt_palm_utils import dbt_env_vars | ||
import sys | ||
|
||
|
||
@click.command('test') | ||
@click.option( | ||
"--clean", is_flag=True, help="drop the test schema after the run is complete" | ||
"--clean", is_flag=True, help="Drop the test schema after the run is complete" | ||
) | ||
@click.option("--models", multiple=True, help="see dbt docs on models flag") | ||
@click.option("--select", multiple=True, help="see dbt docs on select flag") | ||
@click.option("--exclude", multiple=True, help="see dbt docs on exclude flag") | ||
@click.option("--no-fail-fast", is_flag=True, help="will run all tests if one fails") | ||
@click.pass_context | ||
@click.option("--models", "-m", multiple=True, help="See dbt docs on models flag") | ||
@click.option("--select", "-s", multiple=True, help="See dbt docs on select flag") | ||
@click.option("--exclude", "-e", multiple=True, help="See dbt docs on exclude flag") | ||
@click.option("--defer", "-d", is_flag=True, help="See dbt docs on defer flag") | ||
@click.option( | ||
"--no-fail-fast", "-nx", is_flag=True, help="Runs all tests even if one fails" | ||
) | ||
@click.pass_obj | ||
def cli( | ||
ctx, | ||
environment, | ||
clean: bool, | ||
no_fail_fast: bool, | ||
defer: bool, | ||
models: Optional[Tuple] = tuple(), | ||
select: Optional[Tuple] = tuple(), | ||
exclude: Optional[Tuple] = tuple(), | ||
): | ||
"""Tests the DBT repo""" | ||
"""Tests the dbt repo""" | ||
|
||
if defer: | ||
click.secho("Running 'palm prod-artifacts'...", fg='yellow') | ||
exit_code, _, _ = environment.run_on_host("palm prod-artifacts") | ||
if exit_code == 2: | ||
click.secho( | ||
"'palm prod-artifacts' not implemented. Can't use --defer without it!", | ||
fg='red', | ||
) | ||
sys.exit(1) | ||
elif exit_code != 0: | ||
click.secho( | ||
"Something went wrong while pulling the prod artifacts.", fg='red' | ||
) | ||
sys.exit(1) | ||
|
||
env_vars = set_env_vars(environment, defer) | ||
|
||
cmd = ['dbt', 'test'] | ||
if select: | ||
# --select and --models are interchangeable on dbt >= v1, combine the lists of selections | ||
targets = list(set(models + select)) | ||
|
||
run_cmd = build_test_command( | ||
no_fail_fast=no_fail_fast, | ||
targets=targets, | ||
exclude=exclude, | ||
defer=defer, | ||
) | ||
success, msg = environment.run_in_docker(run_cmd, env_vars) | ||
click.secho(msg, fg="green" if success else "red") | ||
|
||
if clean: | ||
success, msg = environment.run_in_docker( | ||
"dbt run-operation drop_branch_schemas", env_vars | ||
) | ||
click.secho(msg, fg="green" if success else "red") | ||
|
||
|
||
def build_test_command( | ||
defer: bool = False, | ||
no_fail_fast: bool = False, | ||
targets: Optional[list] = None, | ||
exclude: Optional[Tuple] = None, | ||
) -> str: | ||
cmd = [] | ||
|
||
cmd.append(f"dbt test") | ||
if targets: | ||
cmd.append('--select') | ||
cmd.extend(select) | ||
if models: | ||
cmd.append('--models') | ||
cmd.extend(models) | ||
cmd.extend(targets) | ||
if exclude: | ||
cmd.append('--exclude') | ||
cmd.extend(exclude) | ||
if not no_fail_fast: | ||
cmd.append('--fail-fast') | ||
if clean: | ||
cmd.append('&& dbt run-operation drop_branch_schemas') | ||
if defer: | ||
if not targets: | ||
cmd.extend(["--select", "state:new", "state:modified+"]) | ||
cmd.append("--defer") | ||
|
||
env_vars = dbt_env_vars(ctx.obj.palm.branch) | ||
success, msg = ctx.obj.run_in_docker(" ".join(cmd), env_vars) | ||
click.secho(msg, fg="green" if success else "red") | ||
return " ".join(cmd) | ||
|
||
|
||
def set_env_vars(environment, defer: bool = False) -> dict: | ||
plugin_config = environment.plugin_config('dbt') | ||
env_vars = dbt_env_vars(environment.palm.branch) | ||
if defer: | ||
env_vars['DBT_DEFER_TO_STATE'] = 'true' | ||
env_vars['DBT_ARTIFACT_STATE_PATH'] = plugin_config.dbt_artifacts_prod | ||
else: | ||
env_vars['DBT_ARTIFACT_STATE_PATH'] = plugin_config.dbt_artifacts_local | ||
return env_vars |
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