Skip to content

Commit

Permalink
Merge pull request #1171 from fishtown-analytics/feature/make-debug-g…
Browse files Browse the repository at this point in the history
…reat

Improve dbt debug [#1061]
  • Loading branch information
beckjake authored Dec 5, 2018
2 parents 65729c4 + 0f1520c commit 963fb84
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 33 deletions.
12 changes: 6 additions & 6 deletions dbt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def _credentials_from_profile(profile, profile_name, target_name):
return credentials

@staticmethod
def _pick_profile_name(args_profile_name, project_profile_name=None):
def pick_profile_name(args_profile_name, project_profile_name=None):
profile_name = project_profile_name
if args_profile_name is not None:
profile_name = args_profile_name
Expand Down Expand Up @@ -606,8 +606,8 @@ def from_credentials(cls, credentials, threads, profile_name, target_name,
return profile

@classmethod
def _render_profile(cls, raw_profile, profile_name, target_override,
cli_vars):
def render_profile(cls, raw_profile, profile_name, target_override,
cli_vars):
"""This is a containment zone for the hateful way we're rendering
profiles.
"""
Expand Down Expand Up @@ -664,7 +664,7 @@ def from_raw_profile_info(cls, raw_profile, profile_name, cli_vars,
"""
# user_cfg is not rendered since it only contains booleans.
# TODO: should it be, and the values coerced to bool?
target_name, profile_data = cls._render_profile(
target_name, profile_data = cls.render_profile(
raw_profile, profile_name, target_override, cli_vars
)

Expand Down Expand Up @@ -749,8 +749,8 @@ def from_args(cls, args, project_profile_name=None, cli_vars=None):
profiles_dir = getattr(args, 'profiles_dir', PROFILES_DIR)
target_override = getattr(args, 'target', None)
raw_profiles = read_profile(profiles_dir)
profile_name = cls._pick_profile_name(args.profile,
project_profile_name)
profile_name = cls.pick_profile_name(args.profile,
project_profile_name)

return cls.from_raw_profiles(
raw_profiles=raw_profiles,
Expand Down
25 changes: 25 additions & 0 deletions dbt/contracts/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ def type(self):
'type not implemented for base credentials class'
)

def connection_info(self):
"""Return an ordered iterator of key/value pairs for pretty-printing.
"""
for key in self._connection_keys():
if key in self._contents:
yield key, self._contents[key]

def _connection_keys(self):
"""The credential object keys that should be printed to users in
'dbt debug' output. This is specific to each adapter.
"""
raise NotImplementedError


class PostgresCredentials(Credentials):
SCHEMA = POSTGRES_CREDENTIALS_CONTRACT
Expand All @@ -214,6 +227,9 @@ def password(self):
# we can't access this as 'pass' since that's reserved
return self._contents['pass']

def _connection_keys(self):
return ('host', 'port', 'user', 'dbname', 'schema')


class RedshiftCredentials(PostgresCredentials):
SCHEMA = REDSHIFT_CREDENTIALS_CONTRACT
Expand All @@ -226,6 +242,9 @@ def __init__(self, *args, **kwargs):
def type(self):
return 'redshift'

def _connection_keys(self):
return ('host', 'port', 'user', 'dbname', 'schema', 'method')


class SnowflakeCredentials(Credentials):
SCHEMA = SNOWFLAKE_CREDENTIALS_CONTRACT
Expand All @@ -234,6 +253,9 @@ class SnowflakeCredentials(Credentials):
def type(self):
return 'snowflake'

def _connection_keys(self):
return ('account', 'user', 'database', 'schema', 'warehouse', 'role')


class BigQueryCredentials(Credentials):
SCHEMA = BIGQUERY_CREDENTIALS_CONTRACT
Expand All @@ -242,6 +264,9 @@ class BigQueryCredentials(Credentials):
def type(self):
return 'bigquery'

def _connection_keys(self):
return ('method', 'project', 'schema', 'location')


CREDENTIALS_MAPPING = {
'postgres': PostgresCredentials,
Expand Down
2 changes: 1 addition & 1 deletion dbt/links.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

ProfileConfigDocs = 'https://docs.getdbt.com/docs/configure-your-profile'
SnowflakeQuotingDocs = 'https://docs.getdbt.com/v0.10/docs/configuring-quoting'
5 changes: 3 additions & 2 deletions dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def run_from_args(parsed):
task = None
cfg = None

if parsed.which == 'init':
# bypass looking for a project file if we're running `dbt init`
if parsed.which in ('init', 'debug'):
# bypass looking for a project file if we're running `dbt init` or
# `dbt debug`
task = parsed.cls(args=parsed)
else:
nearest_project_dir = get_nearest_project_dir()
Expand Down
Loading

0 comments on commit 963fb84

Please sign in to comment.