Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dbt debug [#1061] #1171

Merged
merged 7 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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