Skip to content

Commit

Permalink
Added no-print flag (#4854)
Browse files Browse the repository at this point in the history
* 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 <ebuschang@gmail.com>

Co-authored-by: Emily Rockman <ebuschang@gmail.com>
  • Loading branch information
poloaraujo and emmyoop committed Apr 11, 2022
1 parent 3a3bedc commit 827eae2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20220408-114118.yaml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 3 additions & 1 deletion core/dbt/context/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""


Expand Down
6 changes: 5 additions & 1 deletion core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
LOG_CACHE_EVENTS = None
EVENT_BUFFER_SIZE = 100000
QUIET = None
NO_PRINT = None

_NON_BOOLEAN_FLAGS = [
"LOG_FORMAT",
Expand Down Expand Up @@ -67,6 +68,7 @@
"LOG_CACHE_EVENTS": False,
"EVENT_BUFFER_SIZE": 100000,
"QUIET": False,
"NO_PRINT": False,
}


Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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,
}
9 changes: 9 additions & 0 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions test/unit/test_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 827eae2

Please sign in to comment.