From 07203f22e6a54bdafa267abac78dc29770953c91 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Mon, 23 Aug 2021 11:03:54 -0400 Subject: [PATCH] [#3210] Make --models and --select synonyms, except for 'ls' --- core/dbt/main.py | 17 ++---- .../test_graph_selection.py | 52 +++++++++---------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/core/dbt/main.py b/core/dbt/main.py index be620f2c383..baea1a0a95a 100644 --- a/core/dbt/main.py +++ b/core/dbt/main.py @@ -615,17 +615,10 @@ def _add_common_selector_arguments(sub): ) -def _add_selection_arguments(*subparsers, **kwargs): - models_name = kwargs.get('models_name', 'models') +def _add_selection_arguments(*subparsers): for sub in subparsers: - if models_name == 'models': - _add_models_argument(sub) - elif models_name == 'select': - # these still get stored in 'models', so they present the same - # interface to the task - _add_select_argument(sub) - else: - raise InternalException(f'Unknown models style {models_name}') + _add_models_argument(sub) + _add_select_argument(sub) _add_common_selector_arguments(sub) @@ -1075,8 +1068,8 @@ def parse_args(args, cls=DBTArgumentParser): rpc_sub, seed_sub, parse_sub, build_sub) # --models, --exclude # list_sub sets up its own arguments. - _add_selection_arguments(build_sub, run_sub, compile_sub, generate_sub, test_sub) - _add_selection_arguments(snapshot_sub, seed_sub, models_name='select') + _add_selection_arguments( + build_sub, run_sub, compile_sub, generate_sub, test_sub, snapshot_sub, seed_sub) # --defer _add_defer_argument(run_sub, test_sub, build_sub) # --full-refresh diff --git a/test/integration/007_graph_selection_tests/test_graph_selection.py b/test/integration/007_graph_selection_tests/test_graph_selection.py index e7069ae1a38..9cc771554ab 100644 --- a/test/integration/007_graph_selection_tests/test_graph_selection.py +++ b/test/integration/007_graph_selection_tests/test_graph_selection.py @@ -44,7 +44,7 @@ def assert_correct_schemas(self): def test__postgres__specific_model(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', 'users']) + results = self.run_dbt(['run', '--select', 'users']) self.assertEqual(len(results), 1) self.assertTablesEqual("seed", "users") @@ -80,7 +80,7 @@ def test__postgres__tags(self): def test__postgres__tags_and_children(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', 'tag:base+']) + results = self.run_dbt(['run', '--select', 'tag:base+']) self.assertEqual(len(results), 5) created_models = self.get_models_in_schema() @@ -96,7 +96,7 @@ def test__postgres__tags_and_children(self): def test__postgres__tags_and_children_limited(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', 'tag:base+2']) + results = self.run_dbt(['run', '--select', 'tag:base+2']) self.assertEqual(len(results), 4) created_models = self.get_models_in_schema() @@ -113,7 +113,7 @@ def test__postgres__tags_and_children_limited(self): def test__snowflake__specific_model(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', 'users']) + results = self.run_dbt(['run', '--select', 'users']) self.assertEqual(len(results), 1) self.assertTablesEqual("SEED", "USERS") @@ -127,7 +127,7 @@ def test__snowflake__specific_model(self): def test__postgres__specific_model_and_children(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', 'users+']) + results = self.run_dbt(['run', '--select', 'users+']) self.assertEqual(len(results), 4) self.assertTablesEqual("seed", "users") @@ -143,7 +143,7 @@ def test__postgres__specific_model_and_children(self): def test__snowflake__specific_model_and_children(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', 'users+']) + results = self.run_dbt(['run', '--select', 'users+']) self.assertEqual(len(results), 4) self.assertManyTablesEqual( @@ -158,7 +158,7 @@ def test__snowflake__specific_model_and_children(self): def test__postgres__specific_model_and_children_limited(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', 'users+1']) + results = self.run_dbt(['run', '--select', 'users+1']) self.assertEqual(len(results), 3) self.assertTablesEqual("seed", "users") @@ -174,7 +174,7 @@ def test__postgres__specific_model_and_children_limited(self): def test__postgres__specific_model_and_parents(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', '+users_rollup']) + results = self.run_dbt(['run', '--select', '+users_rollup']) self.assertEqual(len(results), 2) self.assertTablesEqual("seed", "users") @@ -188,7 +188,7 @@ def test__postgres__specific_model_and_parents(self): def test__snowflake__specific_model_and_parents(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', '+users_rollup']) + results = self.run_dbt(['run', '--select', '+users_rollup']) self.assertEqual(len(results), 2) self.assertManyTablesEqual( @@ -204,7 +204,7 @@ def test__snowflake__specific_model_and_parents(self): def test__postgres__specific_model_and_parents_limited(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', '1+users_rollup']) + results = self.run_dbt(['run', '--select', '1+users_rollup']) self.assertEqual(len(results), 2) self.assertTablesEqual("seed", "users") @@ -219,7 +219,7 @@ def test__postgres__specific_model_with_exclusion(self): self.run_sql_file("seed.sql") results = self.run_dbt( - ['run', '--models', '+users_rollup', '--exclude', 'models/users_rollup.sql'] + ['run', '--select', '+users_rollup', '--exclude', 'models/users_rollup.sql'] ) self.assertEqual(len(results), 1) @@ -235,7 +235,7 @@ def test__snowflake__specific_model_with_exclusion(self): self.run_sql_file("seed.sql") results = self.run_dbt( - ['run', '--models', '+users_rollup', '--exclude', 'users_rollup'] + ['run', '--select', '+users_rollup', '--exclude', 'users_rollup'] ) self.assertEqual(len(results), 1) @@ -247,7 +247,7 @@ def test__snowflake__specific_model_with_exclusion(self): @use_profile('postgres') def test__postgres__locally_qualified_name(self): - results = self.run_dbt(['run', '--models', 'test.subdir']) + results = self.run_dbt(['run', '--select', 'test.subdir']) self.assertEqual(len(results), 2) created_models = self.get_models_in_schema() @@ -258,7 +258,7 @@ def test__postgres__locally_qualified_name(self): self.assertIn('nested_users', created_models) self.assert_correct_schemas() - results = self.run_dbt(['run', '--models', 'models/test/subdir*']) + results = self.run_dbt(['run', '--select', 'models/test/subdir*']) self.assertEqual(len(results), 2) created_models = self.get_models_in_schema() @@ -272,14 +272,14 @@ def test__postgres__locally_qualified_name(self): @use_profile('postgres') def test__postgres__locally_qualified_name_model_with_dots(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', 'alternative.users']) + results = self.run_dbt(['run', '--select', 'alternative.users']) self.assertEqual(len(results), 1) created_models = self.get_models_in_schema() self.assertIn('alternative.users', created_models) self.assert_correct_schemas() - results = self.run_dbt(['run', '--models', 'models/alternative.*']) + results = self.run_dbt(['run', '--select', 'models/alternative.*']) self.assertEqual(len(results), 1) created_models = self.get_models_in_schema() @@ -289,7 +289,7 @@ def test__postgres__locally_qualified_name_model_with_dots(self): @use_profile('postgres') def test__postgres__childrens_parents(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', '@base_users']) + results = self.run_dbt(['run', '--select', '@base_users']) self.assertEqual(len(results), 5) created_models = self.get_models_in_schema() @@ -301,7 +301,7 @@ def test__postgres__childrens_parents(self): self.assertNotIn('nested_users', created_models) results = self.run_dbt( - ['test', '--models', 'test_name:not_null'], + ['test', '--select', 'test_name:not_null'], ) self.assertEqual(len(results), 1) assert results[0].node.name == 'not_null_emails_email' @@ -309,7 +309,7 @@ def test__postgres__childrens_parents(self): @use_profile('postgres') def test__postgres__more_childrens_parents(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', '@users']) + results = self.run_dbt(['run', '--select', '@users']) # users, emails_alt, users_rollup, users_rollup_dependency, but not base_users (ephemeral) self.assertEqual(len(results), 4) @@ -321,7 +321,7 @@ def test__postgres__more_childrens_parents(self): self.assertNotIn('nested_users', created_models) results = self.run_dbt( - ['test', '--models', 'test_name:unique'], + ['test', '--select', 'test_name:unique'], ) self.assertEqual(len(results), 2) assert sorted([r.node.name for r in results]) == ['unique_users_id', 'unique_users_rollup_gender'] @@ -330,12 +330,12 @@ def test__postgres__more_childrens_parents(self): @use_profile('snowflake') def test__snowflake__skip_intermediate(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', '@models/users.sql']) + results = self.run_dbt(['run', '--select', '@models/users.sql']) # base_users, emails, users_rollup, users_rollup_dependency self.assertEqual(len(results), 4) # now re-run, skipping users_rollup - results = self.run_dbt(['run', '--models', '@users', '--exclude', 'users_rollup']) + results = self.run_dbt(['run', '--select', '@users', '--exclude', 'users_rollup']) self.assertEqual(len(results), 3) # make sure that users_rollup_dependency and users don't interleave @@ -351,7 +351,7 @@ def test__snowflake__skip_intermediate(self): @use_profile('postgres') def test__postgres__concat(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', '@emails_alt', 'users_rollup']) + results = self.run_dbt(['run', '--select', '@emails_alt', 'users_rollup']) # users, emails_alt, users_rollup self.assertEqual(len(results), 3) @@ -365,7 +365,7 @@ def test__postgres__concat(self): @use_profile('postgres') def test__postgres__concat_exclude(self): self.run_sql_file("seed.sql") - results = self.run_dbt(['run', '--models', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt']) + results = self.run_dbt(['run', '--select', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt']) # users, users_rollup self.assertEqual(len(results), 2) @@ -380,7 +380,7 @@ def test__postgres__concat_exclude(self): def test__postgres__concat_exclude_concat(self): self.run_sql_file("seed.sql") results = self.run_dbt( - ['run', '--models', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt', 'users_rollup'] + ['run', '--select', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt', 'users_rollup'] ) # users self.assertEqual(len(results), 1) @@ -394,7 +394,7 @@ def test__postgres__concat_exclude_concat(self): self.assertNotIn('nested_users', created_models) results = self.run_dbt( - ['test', '--models', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt', 'users_rollup'] + ['test', '--select', '@emails_alt', 'users_rollup', '--exclude', 'emails_alt', 'users_rollup'] ) self.assertEqual(len(results), 1) assert results[0].node.name == 'unique_users_id'