-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allows the profile directory to be set with an environment var #1049
Merged
drewbanin
merged 3 commits into
dbt-labs:dev/guion-bluford
from
mikekaminsky:feature/profile-env-var
Oct 17, 2018
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,6 @@ target/ | |
*.sublime-* | ||
|
||
.python-version | ||
|
||
# Vim | ||
*.sw* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. D'oh! Will fix. |
||
|
||
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the way this code works, the supplied env var won't have the
~
expanded. That means that quoted vars won't be expanded, whereas unquoted vars will be expanded.In the former case, I think dbt will choke on the tilde. Maybe that's just caveat emptor, and a certain amount of bash knowledge is required to use env vars anyway. Alternatively, we could do something like:
I don't feel super strongly about this, but wanted to raise the topic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good point! Combining our two suggestions:
PROFILES_DIR = os.path.expanduser(os.environ.get('DBT_PROFILES_DIR', DEFAULT_PROFILES_DIR))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ that's a little funky because we'll be expanding the tilde twice when no env var is present, but I don't think it would be an issue, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only way it would be possible to have a problem is if there were a posix system where the home directory started with a literal
~
, in which case the user will have bigger problems.