|
24 | 24 | 'user': {}
|
25 | 25 | }
|
26 | 26 |
|
27 |
| -default_active_profiles = ['user'] |
28 |
| - |
29 | 27 | class DbtProjectError(Exception):
|
30 | 28 | def __init__(self, message, project):
|
31 | 29 | self.project = project
|
32 | 30 | super(DbtProjectError, self).__init__(message)
|
33 | 31 |
|
34 |
| -class Project: |
| 32 | +class Project(object): |
35 | 33 |
|
36 |
| - def __init__(self, cfg, profiles, active_profile_names=[]): |
| 34 | + def __init__(self, cfg, profiles, profile_to_load=None): |
37 | 35 | self.cfg = default_project_cfg.copy()
|
38 | 36 | self.cfg.update(cfg)
|
39 | 37 | self.profiles = default_profiles.copy()
|
40 | 38 | 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'] |
42 | 44 |
|
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' |
46 | 47 |
|
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) |
52 | 52 |
|
53 | 53 | def __str__(self):
|
54 | 54 | return pprint.pformat({'project': self.cfg, 'profiles': self.profiles})
|
@@ -78,11 +78,11 @@ def context(self):
|
78 | 78 | filtered_target.pop('pass', None)
|
79 | 79 | return {'env': filtered_target}
|
80 | 80 |
|
81 |
| - def with_profiles(self, profiles=[]): |
| 81 | + def with_profiles(self, profile): |
82 | 82 | return Project(
|
83 | 83 | copy.deepcopy(self.cfg),
|
84 | 84 | copy.deepcopy(self.profiles),
|
85 |
| - profiles) |
| 85 | + profile) |
86 | 86 |
|
87 | 87 | def validate(self):
|
88 | 88 | target_cfg = self.run_environment()
|
@@ -122,12 +122,12 @@ def read_profiles():
|
122 | 122 |
|
123 | 123 | return profiles
|
124 | 124 |
|
125 |
| -def read_project(filename, validate=True): |
| 125 | +def read_project(filename, validate=True, profile_to_load=None): |
126 | 126 | with open(filename, 'r') as f:
|
127 | 127 | project_cfg = yaml.safe_load(f)
|
128 | 128 | project_cfg['project-root'] = os.path.dirname(os.path.abspath(filename))
|
129 | 129 | profiles = read_profiles()
|
130 |
| - proj = Project(project_cfg, profiles, default_active_profiles) |
| 130 | + proj = Project(project_cfg, profiles, profile_to_load) |
131 | 131 |
|
132 | 132 | if validate:
|
133 | 133 | proj.validate()
|
|
0 commit comments