Skip to content

Commit ee8ec98

Browse files
authored
Merge pull request #191 from analyst-collective/release/0.5.2
Release/0.5.2
2 parents 4739be2 + 9ab4f32 commit ee8ec98

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

dbt/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def handle(args):
5252
subs = p.add_subparsers()
5353

5454
base_subparser = argparse.ArgumentParser(add_help=False)
55-
base_subparser.add_argument('--profile', default=["user"], nargs='+', type=str, help='Which profile to load')
55+
base_subparser.add_argument('--profile', required=False, type=str, help='Which profile to load (overrides profile setting in dbt_project.yml file)')
5656
base_subparser.add_argument('--target', default=None, type=str, help='Which run-target to load for the given profile')
5757

5858
sub = subs.add_parser('init', parents=[base_subparser])
@@ -105,7 +105,7 @@ def handle(args):
105105

106106
elif os.path.isfile('dbt_project.yml'):
107107
try:
108-
proj = project.read_project('dbt_project.yml', validate=False).with_profiles(parsed.profile)
108+
proj = project.read_project('dbt_project.yml', validate=False, profile_to_load=parsed.profile)
109109
proj.validate()
110110
except project.DbtProjectError as e:
111111
print("Encountered an error while reading the project:")
@@ -123,7 +123,7 @@ def handle(args):
123123
proj.cfg['run-target'] = parsed.target
124124
else:
125125
print("Encountered an error while reading the project:")
126-
print(" ERROR Specified target {} is not a valid option for profile {}".format(parsed.target, parsed.profile))
126+
print(" ERROR Specified target {} is not a valid option for profile {}".format(parsed.target, proj.profile_to_load))
127127
print("Valid targets are: {}".format(targets))
128128
dbt.tracking.track_invalid_invocation(project=proj, args=parsed, result_type="invalid_target", result="target not found")
129129
return None

dbt/project.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@
2424
'user': {}
2525
}
2626

27-
default_active_profiles = ['user']
28-
2927
class DbtProjectError(Exception):
3028
def __init__(self, message, project):
3129
self.project = project
3230
super(DbtProjectError, self).__init__(message)
3331

34-
class Project:
32+
class Project(object):
3533

36-
def __init__(self, cfg, profiles, active_profile_names=[]):
34+
def __init__(self, cfg, profiles, profile_to_load=None):
3735
self.cfg = default_project_cfg.copy()
3836
self.cfg.update(cfg)
3937
self.profiles = default_profiles.copy()
4038
self.profiles.update(profiles)
41-
self.active_profile_names = active_profile_names
39+
self.profile_to_load = profile_to_load
40+
41+
# load profile from dbt_config.yml if cli arg isn't supplied
42+
if self.profile_to_load is None and self.cfg['profile'] is not None:
43+
self.profile_to_load = self.cfg['profile']
4244

43-
# load profile from dbt_config.yml
44-
if self.cfg['profile'] is not None:
45-
self.active_profile_names.append(self.cfg['profile'])
45+
if self.profile_to_load is None:
46+
self.profile_to_load = 'user'
4647

47-
for profile_name in active_profile_names:
48-
if profile_name in self.profiles:
49-
self.cfg.update(self.profiles[profile_name])
50-
else:
51-
raise DbtProjectError("Could not find profile named '{}'".format(profile_name), self)
48+
if self.profile_to_load in self.profiles:
49+
self.cfg.update(self.profiles[self.profile_to_load])
50+
else:
51+
raise DbtProjectError("Could not find profile named '{}'".format(self.profile_to_load), self)
5252

5353
def __str__(self):
5454
return pprint.pformat({'project': self.cfg, 'profiles': self.profiles})
@@ -78,11 +78,11 @@ def context(self):
7878
filtered_target.pop('pass', None)
7979
return {'env': filtered_target}
8080

81-
def with_profiles(self, profiles=[]):
81+
def with_profiles(self, profile):
8282
return Project(
8383
copy.deepcopy(self.cfg),
8484
copy.deepcopy(self.profiles),
85-
profiles)
85+
profile)
8686

8787
def validate(self):
8888
target_cfg = self.run_environment()
@@ -122,12 +122,12 @@ def read_profiles():
122122

123123
return profiles
124124

125-
def read_project(filename, validate=True):
125+
def read_project(filename, validate=True, profile_to_load=None):
126126
with open(filename, 'r') as f:
127127
project_cfg = yaml.safe_load(f)
128128
project_cfg['project-root'] = os.path.dirname(os.path.abspath(filename))
129129
profiles = read_profiles()
130-
proj = Project(project_cfg, profiles, default_active_profiles)
130+
proj = Project(project_cfg, profiles, profile_to_load)
131131

132132
if validate:
133133
proj.validate()

0 commit comments

Comments
 (0)