From 45bbaf2af1f67c79442390c17fa5052df57ab473 Mon Sep 17 00:00:00 2001 From: Michael Kaminsky Date: Tue, 9 Oct 2018 18:06:24 -0400 Subject: [PATCH 1/3] Allows the profile directory to be set with an environment var Passing the CLI flag (as in `dbt run --profiles-dir ~/path/to/profile`) should still work. Similarly, if no DBT_PROFILES_DIR environment variable is set, DBT will look for profiles in the default location. --- .gitignore | 3 +++ dbt/config.py | 11 ++++++++--- dbt/main.py | 6 +++--- dbt/task/debug.py | 2 +- dbt/task/init.py | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 7c364b7106b..462e7bf8eaf 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,6 @@ target/ *.sublime-* .python-version + +# Vim +*.sw* diff --git a/dbt/config.py b/dbt/config.py index 85cdf137b95..25d02bd3ea9 100644 --- a/dbt/config.py +++ b/dbt/config.py @@ -1,4 +1,5 @@ import os.path +import os from copy import deepcopy import hashlib import pprint @@ -23,6 +24,10 @@ DEFAULT_USE_COLORS = True DEFAULT_PROFILES_DIR = os.path.join(os.path.expanduser('~'), '.dbt') +if os.environ.get('DBT_PROFILES_DIR') is not None: + PROFILES_DIR = os.environ.get('DBT_PROFILES_DIR') +else: + PROFILES_DIR = DEFAULT_PROFILES_DIR INVALID_PROFILE_MESSAGE = """ dbt encountered an error while trying to read your profiles.yml file. @@ -41,7 +46,7 @@ defined in your profiles.yml file. You can find profiles.yml here: {profiles_file}/profiles.yml -""".format(profiles_file=DEFAULT_PROFILES_DIR) +""".format(profiles_file=PROFILES_DIR) def read_profile(profiles_dir): @@ -62,7 +67,7 @@ def read_profile(profiles_dir): def read_profiles(profiles_dir=None): """This is only used in main, for some error handling""" if profiles_dir is None: - profiles_dir = DEFAULT_PROFILES_DIR + profiles_dir = PROFILES_DIR raw_profiles = read_profile(profiles_dir) @@ -624,7 +629,7 @@ def from_args(cls, args, project_profile_name=None, cli_vars=None): threads_override = getattr(args, 'threads', None) # TODO(jeb): is it even possible for this to not be set? - profiles_dir = getattr(args, 'profiles_dir', DEFAULT_PROFILES_DIR) + 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, diff --git a/dbt/main.py b/dbt/main.py index 1f2ba98da53..57ec83189be 100644 --- a/dbt/main.py +++ b/dbt/main.py @@ -27,7 +27,7 @@ from dbt.utils import ExitCodes from dbt.config import Project, RuntimeConfig, DbtProjectError, \ - DbtProfileError, DEFAULT_PROFILES_DIR, read_config, \ + DbtProfileError, PROFILES_DIR, read_config, \ send_anonymous_usage_stats, colorize_output, read_profiles from dbt.exceptions import DbtProfileError, DbtProfileError, RuntimeException @@ -298,11 +298,11 @@ def parse_args(args): base_subparser.add_argument( '--profiles-dir', - default=DEFAULT_PROFILES_DIR, + default=PROFILES_DIR, type=str, help=""" Which directory to look in for the profiles.yml file. Default = {} - """.format(DEFAULT_PROFILES_DIR) + """.format(PROFILES_DIR) ) base_subparser.add_argument( diff --git a/dbt/task/debug.py b/dbt/task/debug.py index fe930997bb0..a575791f6ff 100644 --- a/dbt/task/debug.py +++ b/dbt/task/debug.py @@ -16,7 +16,7 @@ class DebugTask(BaseTask): def path_info(self): open_cmd = dbt.clients.system.open_dir_cmd() - profiles_dir = dbt.config.DEFAULT_PROFILES_DIR + profiles_dir = dbt.config.PROFILES_DIR message = PROFILE_DIR_MESSAGE.format( open_cmd=open_cmd, diff --git a/dbt/task/init.py b/dbt/task/init.py index 1146bb9e2d4..68b1bc2cf70 100644 --- a/dbt/task/init.py +++ b/dbt/task/init.py @@ -91,7 +91,7 @@ def get_addendum(self, project_name, profiles_path): def run(self): project_dir = self.args.project_name - profiles_dir = dbt.config.DEFAULT_PROFILES_DIR + profiles_dir = dbt.config.PROFILES_DIR profiles_file = os.path.join(profiles_dir, 'profiles.yml') self.create_profiles_dir(profiles_dir) From a54b5e39abb0e39b75ab117a491a3669e4b199d3 Mon Sep 17 00:00:00 2001 From: Michael Kaminsky Date: Fri, 12 Oct 2018 14:57:57 -0500 Subject: [PATCH 2/3] Shorter (and more pythonic) global variable setting --- dbt/config.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dbt/config.py b/dbt/config.py index 25d02bd3ea9..6e1191964c9 100644 --- a/dbt/config.py +++ b/dbt/config.py @@ -23,11 +23,7 @@ DEFAULT_SEND_ANONYMOUS_USAGE_STATS = True DEFAULT_USE_COLORS = True DEFAULT_PROFILES_DIR = os.path.join(os.path.expanduser('~'), '.dbt') - -if os.environ.get('DBT_PROFILES_DIR') is not None: - PROFILES_DIR = os.environ.get('DBT_PROFILES_DIR') -else: - PROFILES_DIR = DEFAULT_PROFILES_DIR +PROFILES_DIR = os.path.expanduser(os.environ.get('DBT_PROFILES_DIR', DEFAULT_PROFILES_DIR)) INVALID_PROFILE_MESSAGE = """ dbt encountered an error while trying to read your profiles.yml file. From e0de86ec8899ba20dad19c9accc57b4e55852ce0 Mon Sep 17 00:00:00 2001 From: Michael Kaminsky Date: Sat, 13 Oct 2018 08:45:09 -0500 Subject: [PATCH 3/3] Fix line length. Thanks Pep8! --- dbt/config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dbt/config.py b/dbt/config.py index 6e1191964c9..ccd6dc1cc30 100644 --- a/dbt/config.py +++ b/dbt/config.py @@ -23,7 +23,9 @@ DEFAULT_SEND_ANONYMOUS_USAGE_STATS = True DEFAULT_USE_COLORS = True DEFAULT_PROFILES_DIR = os.path.join(os.path.expanduser('~'), '.dbt') -PROFILES_DIR = os.path.expanduser(os.environ.get('DBT_PROFILES_DIR', DEFAULT_PROFILES_DIR)) +PROFILES_DIR = os.path.expanduser( + os.environ.get('DBT_PROFILES_DIR', DEFAULT_PROFILES_DIR) + ) INVALID_PROFILE_MESSAGE = """ dbt encountered an error while trying to read your profiles.yml file.