Skip to content

Commit

Permalink
Merge pull request #1459 from fishtown-analytics/feature/printer-widt…
Browse files Browse the repository at this point in the history
…h-tests

Make printer width configurable
  • Loading branch information
drewbanin committed May 15, 2019
2 parents 0a2e4f7 + efdb837 commit 7b022f3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 6 additions & 2 deletions core/dbt/config/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ def read_profile(profiles_dir):


class UserConfig(object):
def __init__(self, send_anonymous_usage_stats, use_colors):
def __init__(self, send_anonymous_usage_stats, use_colors, printer_width):
self.send_anonymous_usage_stats = send_anonymous_usage_stats
self.use_colors = use_colors
self.printer_width = printer_width

@classmethod
def from_dict(cls, cfg=None):
Expand All @@ -75,7 +76,10 @@ def from_dict(cls, cfg=None):
'use_colors',
DEFAULT_USE_COLORS
)
return cls(send_anonymous_usage_stats, use_colors)
printer_width = cfg.get(
'printer_width'
)
return cls(send_anonymous_usage_stats, use_colors, printer_width)

def to_dict(self):
return {
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def initialize_config_values(parsed):
if cfg.use_colors:
dbt.ui.printer.use_colors()

if cfg.printer_width:
dbt.ui.printer.printer_width(cfg.printer_width)


def handle_and_check(args):
parsed = parse_args(args)
Expand Down
14 changes: 11 additions & 3 deletions core/dbt/ui/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
COLOR_FG_YELLOW = dbt.ui.colors.COLORS['yellow']
COLOR_RESET_ALL = dbt.ui.colors.COLORS['reset_all']

PRINTER_WIDTH = 80


def use_colors():
global USE_COLORS
USE_COLORS = True


def printer_width(printer_width):
global PRINTER_WIDTH
PRINTER_WIDTH = printer_width


def get_timestamp():
return time.strftime("%H:%M:%S")

Expand Down Expand Up @@ -60,9 +67,10 @@ def print_fancy_output_line(msg, status, index, total, execution_time=None,
progress=progress,
message=msg)

justified = prefix.ljust(80, ".")
if truncate and len(justified) > 77:
justified = justified[:77] + '...'
truncate_width = PRINTER_WIDTH - 3
justified = prefix.ljust(PRINTER_WIDTH, ".")
if truncate and len(justified) > truncate_width:
justified = justified[:truncate_width] + '...'

if execution_time is None:
status_time = ""
Expand Down
2 changes: 2 additions & 0 deletions test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,14 @@ def test_config_override(self):
def test_partial_config_override(self):
self.default_profile_data['config'] = {
'send_anonymous_usage_stats': False,
'printer_width': 60
}
profile = self.from_raw_profiles()
self.assertEqual(profile.profile_name, 'default')
self.assertEqual(profile.target_name, 'postgres')
self.assertFalse(profile.config.send_anonymous_usage_stats)
self.assertTrue(profile.config.use_colors)
self.assertEqual(profile.config.printer_width, 60)

def test_missing_type(self):
del self.default_profile_data['default']['outputs']['postgres']['type']
Expand Down

0 comments on commit 7b022f3

Please sign in to comment.