From b809c9e6fd6cc75bbcc4318b3e04b70b6f4d55aa Mon Sep 17 00:00:00 2001 From: aescay Date: Thu, 8 Oct 2020 16:13:31 -0400 Subject: [PATCH 1/5] rename show_upstream and show_downstream --- core/main.py | 28 +++++++++++++++++++++++----- core/show_dependencies.py | 4 ++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/core/main.py b/core/main.py index 77e5f0d..f3fdfc4 100644 --- a/core/main.py +++ b/core/main.py @@ -9,6 +9,9 @@ import core.find as find_task import core.retry_failed as retry_failed_task +import utils.ui +from utils.logging import logger + from dbt.config import PROFILES_DIR from dbt.version import get_installed_version @@ -121,22 +124,23 @@ def parse_args(args): ) upstream_depencies_sub = subs.add_parser( - "show_upstream", + "show-upstream", parents=[base_subparser], help="Show upstream dependencies for a model", ) upstream_depencies_sub.set_defaults( - cls=show_dependencies_task.ShowDependenciesTask, which="show_upstream" + cls=show_dependencies_task.ShowDependenciesTask, which="show-upstream" ) upstream_depencies_sub.add_argument("model_name") downstream_depencies_sub = subs.add_parser( - "show_downstream", + "show-downstream", + aliases=['show_downstream'], parents=[base_subparser], help="Show downstream dependencies for a model", ) downstream_depencies_sub.set_defaults( - cls=show_dependencies_task.ShowDependenciesTask, which="show_downstream" + cls=show_dependencies_task.ShowDependenciesTask, which="show-downstream" ) downstream_depencies_sub.add_argument("model_name") @@ -232,8 +236,22 @@ def handle(args): if parsed.command == "compare": task = compare_task.CompareTask(parsed) results = task.run() - + if parsed.command in ("show_upstream", "show_downstream"): + logger.info( + utils.ui.yellow( + "Deprecation Warning: \n" + "show_upstream and show_downstream will be deprecated in \n" + "a future version of dbt-helper in favor of the more \n" + "consistent show-upstream and show-downstream syntax." + ) + ) + if parsed.command == "show_upstream": + parsed.command = "show-upstream" + else: + parsed.command = "show-downstream" + + if parsed.command in ("show-upstream", "show-downstream"): task = show_dependencies_task.ShowDependenciesTask(parsed) results = task.run(parsed) diff --git a/core/show_dependencies.py b/core/show_dependencies.py index b96e20f..c96c1af 100644 --- a/core/show_dependencies.py +++ b/core/show_dependencies.py @@ -8,9 +8,9 @@ class ShowDependenciesTask: def __init__(self, args): self.args = args - if self.args.command == "show_upstream": + if self.args.command == "show-upstream": self.direction = "upstream" - elif self.args.command == "show_downstream": + elif self.args.command == "show-downstream": self.direction = "downstream" else: raise From 4eae6ede3f72bdc19a3014f13dba978412fb51cf Mon Sep 17 00:00:00 2001 From: aescay Date: Thu, 8 Oct 2020 16:13:38 -0400 Subject: [PATCH 2/5] update tests --- .../test_dependency_viewer.py | 10 +++++----- .../006_source_schema_test/test_source_schemas.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/integration/005_dependency_viewer_test/test_dependency_viewer.py b/test/integration/005_dependency_viewer_test/test_dependency_viewer.py index 34d4593..873a253 100644 --- a/test/integration/005_dependency_viewer_test/test_dependency_viewer.py +++ b/test/integration/005_dependency_viewer_test/test_dependency_viewer.py @@ -4,16 +4,16 @@ class DependencyTest(DBTIntegrationTest): def test_dependencies(self): self.run_dbt(["run"]) - results = self.run_dbthelper(["show_upstream", "d"]) + results = self.run_dbthelper(["show-upstream", "d"]) self.assertTrue(len(results) == 4) - results = self.run_dbthelper(["show_downstream", "d"]) + results = self.run_dbthelper(["show-downstream", "d"]) self.assertTrue(len(results) == 1) - results = self.run_dbthelper(["show_upstream", "c"]) + results = self.run_dbthelper(["show-upstream", "c"]) self.assertTrue(len(results) == 3) - results = self.run_dbthelper(["show_downstream", "c"]) + results = self.run_dbthelper(["show-downstream", "c"]) self.assertTrue(len(results) == 2) def test_bad_model_arg(self): self.run_dbt(["run"]) - results = self.run_dbthelper(["show_downstream", "non_existent_model"]) + results = self.run_dbthelper(["show-downstream", "non_existent_model"]) self.assertTrue(len(results) == 0) diff --git a/test/integration/006_source_schema_test/test_source_schemas.py b/test/integration/006_source_schema_test/test_source_schemas.py index f725fd6..3077d8b 100644 --- a/test/integration/006_source_schema_test/test_source_schemas.py +++ b/test/integration/006_source_schema_test/test_source_schemas.py @@ -4,13 +4,13 @@ class SourceSchemaTest(DBTIntegrationTest): def test_dependencies(self): self.run_dbt(["run"]) - results = self.run_dbthelper(["show_upstream", "d"]) + results = self.run_dbthelper(["show-upstream", "d"]) self.assertTrue(len(results) == 5) - results = self.run_dbthelper(["show_downstream", "d"]) + results = self.run_dbthelper(["show-downstream", "d"]) self.assertTrue(len(results) == 1) - results = self.run_dbthelper(["show_upstream", "c"]) + results = self.run_dbthelper(["show-upstream", "c"]) self.assertTrue(len(results) == 4) - results = self.run_dbthelper(["show_downstream", "c"]) + results = self.run_dbthelper(["show-downstream", "c"]) self.assertTrue(len(results) == 2) def test_compare(self): From a8f1fdd4fb990d962082248a81eaee56a5d81ba3 Mon Sep 17 00:00:00 2001 From: aescay Date: Thu, 8 Oct 2020 16:14:48 -0400 Subject: [PATCH 3/5] update readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index da65908..4c41303 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ NOTE: dbt-helper may not work with dbt when dbt is installed via homebrew. We ar * Note: `dbt-helper compare` will compare all schemas that are impacted by models in the `models/` directory. There is (currently) no way to specify a single schema to compare. * `bootstrap`: Create starter "`schema.yml`" files for your project. This function helpfully generates boilerplate dbt-model files for you so you don't have to go through the copy/paste when you're developing a new model. * Note: this command will not over-write existing `schema.yml` files. It will default to printing templates to the console, but you can create new files by using the `--write-files` flag. -* `show_upstream`: Inspect the dbt graph and show the relations that are "upstream" from (i.e., the "parents" of) the selected relation. Print to the terminal. -* `show_downstream`: The same as `show_upstream` but in the other direction -- show dependents 'downstream' from (i.e., the "children" of) the selected relation +* `show-upstream`: Inspect the dbt graph and show the relations that are "upstream" from (i.e., the "parents" of) the selected relation. Print to the terminal. +* `show-downstream`: The same as `show-upstream` but in the other direction -- show dependents 'downstream' from (i.e., the "children" of) the selected relation * `find`: Find the compiled `.sql` file for a model by providing the model name only. You can also find the source or run `.sql` files for a model by using the appropriate flag. Useful when working in large dbt projects and you want to find files quickly wihout having to navigate a file tree. * `open`: Open the compiled `.sql` file for a model by providing the model name only. Works the same as find, but directly opens the file in your text editor. * `retry-failed`: Rerun models that errored or were skipped on your previous dbt run. @@ -78,9 +78,9 @@ models: description: 'TODO: Replace me' ``` -#### `show_upstream` +#### `show-upstream` ```bash -$ dbt-helper show_upstream d +$ dbt-helper show-upstream d -------------------------------------------------------------------------------- downstream.d @@ -89,8 +89,8 @@ $ dbt-helper show_upstream d -------------------------------------------------------------------------------- ``` -#### `show_downstream` -_see `show_upstream`_ +#### `show-downstream` +_see `show-upstream`_ #### `find` From 9a10788b341456908fe0a780df2c9c519620995a Mon Sep 17 00:00:00 2001 From: aescay Date: Thu, 8 Oct 2020 16:30:34 -0400 Subject: [PATCH 4/5] run black formatter --- core/bootstrap.py | 5 ++++- core/find.py | 2 +- core/main.py | 19 ++++++++++--------- core/retry_failed.py | 5 ++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/bootstrap.py b/core/bootstrap.py index 7911cbb..f7ce06c 100644 --- a/core/bootstrap.py +++ b/core/bootstrap.py @@ -81,7 +81,10 @@ def generate_catalog_dict(self, manifest, columns): """ nodes, sources = Catalog(columns).make_unique_id_map(manifest) result = CatalogResults( - nodes=nodes, sources=sources, generated_at=datetime.utcnow(), errors=None, + nodes=nodes, + sources=sources, + generated_at=datetime.utcnow(), + errors=None, ) return result.to_dict(omit_none=False)["nodes"] diff --git a/core/find.py b/core/find.py index cdd7dce..2904cfe 100644 --- a/core/find.py +++ b/core/find.py @@ -36,7 +36,7 @@ def _get_manifest(self): ) def _get_model_files(self): - """ Return a dictionary of the form: + """Return a dictionary of the form: { 'source': 'models/path/to/model', 'compiled': 'target/compiled/path/to/model', diff --git a/core/main.py b/core/main.py index f3fdfc4..575069b 100644 --- a/core/main.py +++ b/core/main.py @@ -68,7 +68,8 @@ def parse_args(args): ), ) base_subparser.add_argument( - "--project-dir", help="Project directory specification", + "--project-dir", + help="Project directory specification", ) base_subparser.add_argument( "--profile", @@ -135,7 +136,7 @@ def parse_args(args): downstream_depencies_sub = subs.add_parser( "show-downstream", - aliases=['show_downstream'], + aliases=["show_downstream"], parents=[base_subparser], help="Show downstream dependencies for a model", ) @@ -236,16 +237,16 @@ def handle(args): if parsed.command == "compare": task = compare_task.CompareTask(parsed) results = task.run() - + if parsed.command in ("show_upstream", "show_downstream"): logger.info( - utils.ui.yellow( - "Deprecation Warning: \n" - "show_upstream and show_downstream will be deprecated in \n" - "a future version of dbt-helper in favor of the more \n" - "consistent show-upstream and show-downstream syntax." - ) + utils.ui.yellow( + "Deprecation Warning: \n" + "show_upstream and show_downstream will be deprecated in \n" + "a future version of dbt-helper in favor of the more \n" + "consistent show-upstream and show-downstream syntax." ) + ) if parsed.command == "show_upstream": parsed.command = "show-upstream" else: diff --git a/core/retry_failed.py b/core/retry_failed.py index 2b9506e..9ce5023 100644 --- a/core/retry_failed.py +++ b/core/retry_failed.py @@ -27,8 +27,7 @@ def _get_run_results(self): raise Exception("Could not find {} file.".format(RUN_RESULTS_FILE)) def get_models_to_retry(self): - """ Return a list of errored and skipped models - """ + """Return a list of errored and skipped models""" models = [] for result in self.run_results.get("results"): if result["status"] == "ERROR" or result["skip"]: @@ -36,7 +35,7 @@ def get_models_to_retry(self): return models def get_run_flags(self): - """ This is a janky function that takes the args and puts them back + """This is a janky function that takes the args and puts them back into a list of strings.""" flags = [] if self.args.profiles_dir: From 3147f98771a8989af8999c2cc03ef1bf3fd8cb62 Mon Sep 17 00:00:00 2001 From: Andrew Escay <36305243+aescay@users.noreply.github.com> Date: Sat, 10 Oct 2020 19:10:40 -0400 Subject: [PATCH 5/5] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 042c3bd..0f21476 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ package_name = "dbt-helper" -VERSION = "0.4.1" +VERSION = "0.5.0" description = """dbt-helper is a command line tool to help ease dbt development and database management"""