From 827eae2750e0ad0628fb76ac82ddb7de1edee19c Mon Sep 17 00:00:00 2001 From: Leopoldo Araujo <68853890+poloaraujo@users.noreply.github.com> Date: Mon, 11 Apr 2022 19:48:34 +0100 Subject: [PATCH] Added no-print flag (#4854) * Added no-print flag * Updated changelog * Updated changelog * Removed changes from CHANGELOG.md * Updated CHANGELOG.MD with changie * Update .changes/unreleased/Features-20220408-114118.yaml Co-authored-by: Emily Rockman Co-authored-by: Emily Rockman --- .changes/unreleased/Features-20220408-114118.yaml | 7 +++++++ core/dbt/context/base.py | 4 +++- core/dbt/flags.py | 6 +++++- core/dbt/main.py | 9 +++++++++ test/unit/test_flags.py | 7 +++++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Features-20220408-114118.yaml diff --git a/.changes/unreleased/Features-20220408-114118.yaml b/.changes/unreleased/Features-20220408-114118.yaml new file mode 100644 index 00000000000..d98727019b7 --- /dev/null +++ b/.changes/unreleased/Features-20220408-114118.yaml @@ -0,0 +1,7 @@ +kind: Features +body: Add `--no-print` global flag +time: 2022-04-08T11:41:18.934373+01:00 +custom: + Author: poloaraujo + Issue: "4710" + PR: "4854" diff --git a/core/dbt/context/base.py b/core/dbt/context/base.py index 99336655ad2..355937bb4fd 100644 --- a/core/dbt/context/base.py +++ b/core/dbt/context/base.py @@ -569,7 +569,9 @@ def print(msg: str) -> str: {{ print("Running some_macro: " ~ arg1 ~ ", " ~ arg2) }} {% endmacro %}" """ - print(msg) + + if not flags.NO_PRINT: + print(msg) return "" diff --git a/core/dbt/flags.py b/core/dbt/flags.py index e0e16244649..263b58c59f7 100644 --- a/core/dbt/flags.py +++ b/core/dbt/flags.py @@ -35,6 +35,7 @@ LOG_CACHE_EVENTS = None EVENT_BUFFER_SIZE = 100000 QUIET = None +NO_PRINT = None _NON_BOOLEAN_FLAGS = [ "LOG_FORMAT", @@ -67,6 +68,7 @@ "LOG_CACHE_EVENTS": False, "EVENT_BUFFER_SIZE": 100000, "QUIET": False, + "NO_PRINT": False, } @@ -116,7 +118,7 @@ def set_from_args(args, user_config): global STRICT_MODE, FULL_REFRESH, WARN_ERROR, USE_EXPERIMENTAL_PARSER, STATIC_PARSER global WRITE_JSON, PARTIAL_PARSE, USE_COLORS, STORE_FAILURES, PROFILES_DIR, DEBUG, LOG_FORMAT global INDIRECT_SELECTION, VERSION_CHECK, FAIL_FAST, SEND_ANONYMOUS_USAGE_STATS - global PRINTER_WIDTH, WHICH, LOG_CACHE_EVENTS, EVENT_BUFFER_SIZE, QUIET + global PRINTER_WIDTH, WHICH, LOG_CACHE_EVENTS, EVENT_BUFFER_SIZE, QUIET, NO_PRINT STRICT_MODE = False # backwards compatibility # cli args without user_config or env var option @@ -142,6 +144,7 @@ def set_from_args(args, user_config): LOG_CACHE_EVENTS = get_flag_value("LOG_CACHE_EVENTS", args, user_config) EVENT_BUFFER_SIZE = get_flag_value("EVENT_BUFFER_SIZE", args, user_config) QUIET = get_flag_value("QUIET", args, user_config) + NO_PRINT = get_flag_value("NO_PRINT", args, user_config) _set_overrides_from_env() @@ -222,4 +225,5 @@ def get_flag_dict(): "log_cache_events": LOG_CACHE_EVENTS, "event_buffer_size": EVENT_BUFFER_SIZE, "quiet": QUIET, + "no_print": NO_PRINT, } diff --git a/core/dbt/main.py b/core/dbt/main.py index fb926907b59..df35300651d 100644 --- a/core/dbt/main.py +++ b/core/dbt/main.py @@ -1088,6 +1088,15 @@ def parse_args(args, cls=DBTArgumentParser): """, ) + p.add_argument( + "--no-print", + action="store_true", + default=None, + help=""" + Suppress all {{ print() }} macro calls. + """, + ) + subs = p.add_subparsers(title="Available sub-commands") base_subparser = _build_base_subparser() diff --git a/test/unit/test_flags.py b/test/unit/test_flags.py index 8415540ffdd..a0f4ea8cc33 100644 --- a/test/unit/test_flags.py +++ b/test/unit/test_flags.py @@ -228,3 +228,10 @@ def test__flags(self): self.assertEqual(flags.QUIET, True) # cleanup self.user_config.quiet = None + + # no_print + self.user_config.no_print = True + flags.set_from_args(self.args, self.user_config) + self.assertEqual(flags.NO_PRINT, True) + # cleanup + self.user_config.no_print = None