dvt-core 1.11.0b4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dvt-core might be problematic. Click here for more details.

Files changed (261) hide show
  1. dvt/__init__.py +7 -0
  2. dvt/_pydantic_shim.py +26 -0
  3. dvt/adapters/__init__.py +16 -0
  4. dvt/adapters/multi_adapter_manager.py +268 -0
  5. dvt/artifacts/__init__.py +0 -0
  6. dvt/artifacts/exceptions/__init__.py +1 -0
  7. dvt/artifacts/exceptions/schemas.py +31 -0
  8. dvt/artifacts/resources/__init__.py +116 -0
  9. dvt/artifacts/resources/base.py +68 -0
  10. dvt/artifacts/resources/types.py +93 -0
  11. dvt/artifacts/resources/v1/analysis.py +10 -0
  12. dvt/artifacts/resources/v1/catalog.py +23 -0
  13. dvt/artifacts/resources/v1/components.py +275 -0
  14. dvt/artifacts/resources/v1/config.py +282 -0
  15. dvt/artifacts/resources/v1/documentation.py +11 -0
  16. dvt/artifacts/resources/v1/exposure.py +52 -0
  17. dvt/artifacts/resources/v1/function.py +53 -0
  18. dvt/artifacts/resources/v1/generic_test.py +32 -0
  19. dvt/artifacts/resources/v1/group.py +22 -0
  20. dvt/artifacts/resources/v1/hook.py +11 -0
  21. dvt/artifacts/resources/v1/macro.py +30 -0
  22. dvt/artifacts/resources/v1/metric.py +173 -0
  23. dvt/artifacts/resources/v1/model.py +146 -0
  24. dvt/artifacts/resources/v1/owner.py +10 -0
  25. dvt/artifacts/resources/v1/saved_query.py +112 -0
  26. dvt/artifacts/resources/v1/seed.py +42 -0
  27. dvt/artifacts/resources/v1/semantic_layer_components.py +72 -0
  28. dvt/artifacts/resources/v1/semantic_model.py +315 -0
  29. dvt/artifacts/resources/v1/singular_test.py +14 -0
  30. dvt/artifacts/resources/v1/snapshot.py +92 -0
  31. dvt/artifacts/resources/v1/source_definition.py +85 -0
  32. dvt/artifacts/resources/v1/sql_operation.py +10 -0
  33. dvt/artifacts/resources/v1/unit_test_definition.py +78 -0
  34. dvt/artifacts/schemas/__init__.py +0 -0
  35. dvt/artifacts/schemas/base.py +191 -0
  36. dvt/artifacts/schemas/batch_results.py +24 -0
  37. dvt/artifacts/schemas/catalog/__init__.py +12 -0
  38. dvt/artifacts/schemas/catalog/v1/__init__.py +0 -0
  39. dvt/artifacts/schemas/catalog/v1/catalog.py +60 -0
  40. dvt/artifacts/schemas/freshness/__init__.py +1 -0
  41. dvt/artifacts/schemas/freshness/v3/__init__.py +0 -0
  42. dvt/artifacts/schemas/freshness/v3/freshness.py +159 -0
  43. dvt/artifacts/schemas/manifest/__init__.py +2 -0
  44. dvt/artifacts/schemas/manifest/v12/__init__.py +0 -0
  45. dvt/artifacts/schemas/manifest/v12/manifest.py +212 -0
  46. dvt/artifacts/schemas/results.py +148 -0
  47. dvt/artifacts/schemas/run/__init__.py +2 -0
  48. dvt/artifacts/schemas/run/v5/__init__.py +0 -0
  49. dvt/artifacts/schemas/run/v5/run.py +184 -0
  50. dvt/artifacts/schemas/upgrades/__init__.py +4 -0
  51. dvt/artifacts/schemas/upgrades/upgrade_manifest.py +174 -0
  52. dvt/artifacts/schemas/upgrades/upgrade_manifest_dbt_version.py +2 -0
  53. dvt/artifacts/utils/validation.py +153 -0
  54. dvt/cli/__init__.py +1 -0
  55. dvt/cli/context.py +16 -0
  56. dvt/cli/exceptions.py +56 -0
  57. dvt/cli/flags.py +558 -0
  58. dvt/cli/main.py +971 -0
  59. dvt/cli/option_types.py +121 -0
  60. dvt/cli/options.py +79 -0
  61. dvt/cli/params.py +803 -0
  62. dvt/cli/requires.py +478 -0
  63. dvt/cli/resolvers.py +32 -0
  64. dvt/cli/types.py +40 -0
  65. dvt/clients/__init__.py +0 -0
  66. dvt/clients/checked_load.py +82 -0
  67. dvt/clients/git.py +164 -0
  68. dvt/clients/jinja.py +206 -0
  69. dvt/clients/jinja_static.py +245 -0
  70. dvt/clients/registry.py +192 -0
  71. dvt/clients/yaml_helper.py +68 -0
  72. dvt/compilation.py +833 -0
  73. dvt/compute/__init__.py +26 -0
  74. dvt/compute/base.py +288 -0
  75. dvt/compute/engines/__init__.py +13 -0
  76. dvt/compute/engines/duckdb_engine.py +368 -0
  77. dvt/compute/engines/spark_engine.py +273 -0
  78. dvt/compute/query_analyzer.py +212 -0
  79. dvt/compute/router.py +483 -0
  80. dvt/config/__init__.py +4 -0
  81. dvt/config/catalogs.py +95 -0
  82. dvt/config/compute_config.py +406 -0
  83. dvt/config/profile.py +411 -0
  84. dvt/config/profiles_v2.py +464 -0
  85. dvt/config/project.py +893 -0
  86. dvt/config/renderer.py +232 -0
  87. dvt/config/runtime.py +491 -0
  88. dvt/config/selectors.py +209 -0
  89. dvt/config/utils.py +78 -0
  90. dvt/connectors/.gitignore +6 -0
  91. dvt/connectors/README.md +306 -0
  92. dvt/connectors/catalog.yml +217 -0
  93. dvt/connectors/download_connectors.py +300 -0
  94. dvt/constants.py +29 -0
  95. dvt/context/__init__.py +0 -0
  96. dvt/context/base.py +746 -0
  97. dvt/context/configured.py +136 -0
  98. dvt/context/context_config.py +350 -0
  99. dvt/context/docs.py +82 -0
  100. dvt/context/exceptions_jinja.py +179 -0
  101. dvt/context/macro_resolver.py +195 -0
  102. dvt/context/macros.py +171 -0
  103. dvt/context/manifest.py +73 -0
  104. dvt/context/providers.py +2198 -0
  105. dvt/context/query_header.py +14 -0
  106. dvt/context/secret.py +59 -0
  107. dvt/context/target.py +74 -0
  108. dvt/contracts/__init__.py +0 -0
  109. dvt/contracts/files.py +413 -0
  110. dvt/contracts/graph/__init__.py +0 -0
  111. dvt/contracts/graph/manifest.py +1904 -0
  112. dvt/contracts/graph/metrics.py +98 -0
  113. dvt/contracts/graph/model_config.py +71 -0
  114. dvt/contracts/graph/node_args.py +42 -0
  115. dvt/contracts/graph/nodes.py +1806 -0
  116. dvt/contracts/graph/semantic_manifest.py +233 -0
  117. dvt/contracts/graph/unparsed.py +812 -0
  118. dvt/contracts/project.py +417 -0
  119. dvt/contracts/results.py +53 -0
  120. dvt/contracts/selection.py +23 -0
  121. dvt/contracts/sql.py +86 -0
  122. dvt/contracts/state.py +69 -0
  123. dvt/contracts/util.py +46 -0
  124. dvt/deprecations.py +347 -0
  125. dvt/deps/__init__.py +0 -0
  126. dvt/deps/base.py +153 -0
  127. dvt/deps/git.py +196 -0
  128. dvt/deps/local.py +80 -0
  129. dvt/deps/registry.py +131 -0
  130. dvt/deps/resolver.py +149 -0
  131. dvt/deps/tarball.py +121 -0
  132. dvt/docs/source/_ext/dbt_click.py +118 -0
  133. dvt/docs/source/conf.py +32 -0
  134. dvt/env_vars.py +64 -0
  135. dvt/event_time/event_time.py +40 -0
  136. dvt/event_time/sample_window.py +60 -0
  137. dvt/events/__init__.py +16 -0
  138. dvt/events/base_types.py +37 -0
  139. dvt/events/core_types_pb2.py +2 -0
  140. dvt/events/logging.py +109 -0
  141. dvt/events/types.py +2534 -0
  142. dvt/exceptions.py +1487 -0
  143. dvt/flags.py +89 -0
  144. dvt/graph/__init__.py +11 -0
  145. dvt/graph/cli.py +248 -0
  146. dvt/graph/graph.py +172 -0
  147. dvt/graph/queue.py +213 -0
  148. dvt/graph/selector.py +375 -0
  149. dvt/graph/selector_methods.py +976 -0
  150. dvt/graph/selector_spec.py +223 -0
  151. dvt/graph/thread_pool.py +18 -0
  152. dvt/hooks.py +21 -0
  153. dvt/include/README.md +49 -0
  154. dvt/include/__init__.py +3 -0
  155. dvt/include/global_project.py +4 -0
  156. dvt/include/starter_project/.gitignore +4 -0
  157. dvt/include/starter_project/README.md +15 -0
  158. dvt/include/starter_project/__init__.py +3 -0
  159. dvt/include/starter_project/analyses/.gitkeep +0 -0
  160. dvt/include/starter_project/dvt_project.yml +36 -0
  161. dvt/include/starter_project/macros/.gitkeep +0 -0
  162. dvt/include/starter_project/models/example/my_first_dbt_model.sql +27 -0
  163. dvt/include/starter_project/models/example/my_second_dbt_model.sql +6 -0
  164. dvt/include/starter_project/models/example/schema.yml +21 -0
  165. dvt/include/starter_project/seeds/.gitkeep +0 -0
  166. dvt/include/starter_project/snapshots/.gitkeep +0 -0
  167. dvt/include/starter_project/tests/.gitkeep +0 -0
  168. dvt/internal_deprecations.py +27 -0
  169. dvt/jsonschemas/__init__.py +3 -0
  170. dvt/jsonschemas/jsonschemas.py +309 -0
  171. dvt/jsonschemas/project/0.0.110.json +4717 -0
  172. dvt/jsonschemas/project/0.0.85.json +2015 -0
  173. dvt/jsonschemas/resources/0.0.110.json +2636 -0
  174. dvt/jsonschemas/resources/0.0.85.json +2536 -0
  175. dvt/jsonschemas/resources/latest.json +6773 -0
  176. dvt/links.py +4 -0
  177. dvt/materializations/__init__.py +0 -0
  178. dvt/materializations/incremental/__init__.py +0 -0
  179. dvt/materializations/incremental/microbatch.py +235 -0
  180. dvt/mp_context.py +8 -0
  181. dvt/node_types.py +37 -0
  182. dvt/parser/__init__.py +23 -0
  183. dvt/parser/analysis.py +21 -0
  184. dvt/parser/base.py +549 -0
  185. dvt/parser/common.py +267 -0
  186. dvt/parser/docs.py +52 -0
  187. dvt/parser/fixtures.py +51 -0
  188. dvt/parser/functions.py +30 -0
  189. dvt/parser/generic_test.py +100 -0
  190. dvt/parser/generic_test_builders.py +334 -0
  191. dvt/parser/hooks.py +119 -0
  192. dvt/parser/macros.py +137 -0
  193. dvt/parser/manifest.py +2204 -0
  194. dvt/parser/models.py +574 -0
  195. dvt/parser/partial.py +1179 -0
  196. dvt/parser/read_files.py +445 -0
  197. dvt/parser/schema_generic_tests.py +423 -0
  198. dvt/parser/schema_renderer.py +111 -0
  199. dvt/parser/schema_yaml_readers.py +936 -0
  200. dvt/parser/schemas.py +1467 -0
  201. dvt/parser/search.py +149 -0
  202. dvt/parser/seeds.py +28 -0
  203. dvt/parser/singular_test.py +20 -0
  204. dvt/parser/snapshots.py +44 -0
  205. dvt/parser/sources.py +557 -0
  206. dvt/parser/sql.py +63 -0
  207. dvt/parser/unit_tests.py +622 -0
  208. dvt/plugins/__init__.py +20 -0
  209. dvt/plugins/contracts.py +10 -0
  210. dvt/plugins/exceptions.py +2 -0
  211. dvt/plugins/manager.py +164 -0
  212. dvt/plugins/manifest.py +21 -0
  213. dvt/profiler.py +20 -0
  214. dvt/py.typed +1 -0
  215. dvt/runners/__init__.py +2 -0
  216. dvt/runners/exposure_runner.py +7 -0
  217. dvt/runners/no_op_runner.py +46 -0
  218. dvt/runners/saved_query_runner.py +7 -0
  219. dvt/selected_resources.py +8 -0
  220. dvt/task/__init__.py +0 -0
  221. dvt/task/base.py +504 -0
  222. dvt/task/build.py +197 -0
  223. dvt/task/clean.py +57 -0
  224. dvt/task/clone.py +162 -0
  225. dvt/task/compile.py +151 -0
  226. dvt/task/compute.py +366 -0
  227. dvt/task/debug.py +650 -0
  228. dvt/task/deps.py +280 -0
  229. dvt/task/docs/__init__.py +3 -0
  230. dvt/task/docs/generate.py +408 -0
  231. dvt/task/docs/index.html +250 -0
  232. dvt/task/docs/serve.py +28 -0
  233. dvt/task/freshness.py +323 -0
  234. dvt/task/function.py +122 -0
  235. dvt/task/group_lookup.py +46 -0
  236. dvt/task/init.py +374 -0
  237. dvt/task/list.py +237 -0
  238. dvt/task/printer.py +176 -0
  239. dvt/task/profiles.py +256 -0
  240. dvt/task/retry.py +175 -0
  241. dvt/task/run.py +1146 -0
  242. dvt/task/run_operation.py +142 -0
  243. dvt/task/runnable.py +802 -0
  244. dvt/task/seed.py +104 -0
  245. dvt/task/show.py +150 -0
  246. dvt/task/snapshot.py +57 -0
  247. dvt/task/sql.py +111 -0
  248. dvt/task/test.py +464 -0
  249. dvt/tests/fixtures/__init__.py +1 -0
  250. dvt/tests/fixtures/project.py +620 -0
  251. dvt/tests/util.py +651 -0
  252. dvt/tracking.py +529 -0
  253. dvt/utils/__init__.py +3 -0
  254. dvt/utils/artifact_upload.py +151 -0
  255. dvt/utils/utils.py +408 -0
  256. dvt/version.py +249 -0
  257. dvt_core-1.11.0b4.dist-info/METADATA +252 -0
  258. dvt_core-1.11.0b4.dist-info/RECORD +261 -0
  259. dvt_core-1.11.0b4.dist-info/WHEEL +5 -0
  260. dvt_core-1.11.0b4.dist-info/entry_points.txt +2 -0
  261. dvt_core-1.11.0b4.dist-info/top_level.txt +1 -0
dvt/config/profile.py ADDED
@@ -0,0 +1,411 @@
1
+ import os
2
+ from dataclasses import dataclass
3
+ from typing import Any, Dict, Optional, Tuple
4
+
5
+ from dvt.clients.yaml_helper import load_yaml_text
6
+ from dvt.contracts.project import ProfileConfig
7
+ from dvt.events.types import MissingProfileTarget
8
+ from dvt.exceptions import (
9
+ CompilationError,
10
+ DbtProfileError,
11
+ DbtProjectError,
12
+ DbtRuntimeError,
13
+ ProfileConfigError,
14
+ )
15
+ from dvt.flags import get_flags
16
+
17
+ from dbt.adapters.contracts.connection import Credentials, HasCredentials
18
+ from dbt_common.clients.system import load_file_contents
19
+ from dbt_common.dataclass_schema import ValidationError
20
+ from dbt_common.events.functions import fire_event
21
+ from dbt_common.exceptions import DbtValidationError
22
+
23
+ from .renderer import ProfileRenderer
24
+
25
+ DEFAULT_THREADS = 1
26
+
27
+ INVALID_PROFILE_MESSAGE = """
28
+ dbt encountered an error while trying to read your profiles.yml file.
29
+
30
+ {error_string}
31
+ """
32
+
33
+
34
+ def read_profile(profiles_dir: str) -> Dict[str, Any]:
35
+ path = os.path.join(profiles_dir, "profiles.yml")
36
+
37
+ contents = None
38
+ if os.path.isfile(path):
39
+ try:
40
+ contents = load_file_contents(path, strip=False)
41
+ yaml_content = load_yaml_text(contents)
42
+ if not yaml_content:
43
+ msg = f"The profiles.yml file at {path} is empty"
44
+ raise DbtProfileError(INVALID_PROFILE_MESSAGE.format(error_string=msg))
45
+ return yaml_content
46
+ except DbtValidationError as e:
47
+ msg = INVALID_PROFILE_MESSAGE.format(error_string=e)
48
+ raise DbtValidationError(msg) from e
49
+
50
+ return {}
51
+
52
+
53
+ # The Profile class is included in RuntimeConfig, so any attribute
54
+ # additions must also be set where the RuntimeConfig class is created
55
+ # `init=False` is a workaround for https://bugs.python.org/issue45081
56
+ @dataclass(init=False)
57
+ class Profile(HasCredentials):
58
+ profile_name: str
59
+ target_name: str
60
+ threads: int
61
+ credentials: Credentials
62
+ profile_env_vars: Dict[str, Any]
63
+ log_cache_events: bool
64
+
65
+ def __init__(
66
+ self,
67
+ profile_name: str,
68
+ target_name: str,
69
+ threads: int,
70
+ credentials: Credentials,
71
+ ) -> None:
72
+ """
73
+ TODO: Is this no longer needed now that 3.9 is no longer supported?
74
+ Explicitly defining `__init__` to work around bug in Python 3.9.7
75
+ https://bugs.python.org/issue45081
76
+ """
77
+ self.profile_name = profile_name
78
+ self.target_name = target_name
79
+ self.threads = threads
80
+ self.credentials = credentials
81
+ self.profile_env_vars = {} # never available on init
82
+ self.log_cache_events = (
83
+ get_flags().LOG_CACHE_EVENTS
84
+ ) # never available on init, set for adapter instantiation via AdapterRequiredConfig
85
+
86
+ def to_profile_info(self, serialize_credentials: bool = False) -> Dict[str, Any]:
87
+ """Unlike to_project_config, this dict is not a mirror of any existing
88
+ on-disk data structure. It's used when creating a new profile from an
89
+ existing one.
90
+
91
+ :param serialize_credentials bool: If True, serialize the credentials.
92
+ Otherwise, the Credentials object will be copied.
93
+ :returns dict: The serialized profile.
94
+ """
95
+ result = {
96
+ "profile_name": self.profile_name,
97
+ "target_name": self.target_name,
98
+ "threads": self.threads,
99
+ "credentials": self.credentials,
100
+ }
101
+ if serialize_credentials:
102
+ result["credentials"] = self.credentials.to_dict(omit_none=True)
103
+ return result
104
+
105
+ def to_target_dict(self) -> Dict[str, Any]:
106
+ target = dict(self.credentials.connection_info(with_aliases=True))
107
+ target.update(
108
+ {
109
+ "type": self.credentials.type,
110
+ "threads": self.threads,
111
+ "name": self.target_name,
112
+ "target_name": self.target_name,
113
+ "profile_name": self.profile_name,
114
+ }
115
+ )
116
+ return target
117
+
118
+ def __eq__(self, other: object) -> bool:
119
+ if not (isinstance(other, self.__class__) and isinstance(self, other.__class__)):
120
+ return NotImplemented
121
+ return self.to_profile_info() == other.to_profile_info()
122
+
123
+ def validate(self):
124
+ try:
125
+ if self.credentials:
126
+ dct = self.credentials.to_dict(omit_none=True)
127
+ self.credentials.validate(dct)
128
+ dct = self.to_profile_info(serialize_credentials=True)
129
+ ProfileConfig.validate(dct)
130
+ except ValidationError as exc:
131
+ raise ProfileConfigError(exc) from exc
132
+
133
+ @staticmethod
134
+ def _credentials_from_profile(
135
+ profile: Dict[str, Any], profile_name: str, target_name: str
136
+ ) -> Credentials:
137
+ # avoid an import cycle
138
+ from dbt.adapters.factory import load_plugin
139
+
140
+ # credentials carry their 'type' in their actual type, not their
141
+ # attributes. We do want this in order to pick our Credentials class.
142
+ if "type" not in profile:
143
+ raise DbtProfileError(
144
+ 'required field "type" not found in profile {} and target {}'.format(
145
+ profile_name, target_name
146
+ )
147
+ )
148
+
149
+ typename = profile.pop("type")
150
+ try:
151
+ cls = load_plugin(typename)
152
+ data = cls.translate_aliases(profile)
153
+ cls.validate(data)
154
+ credentials = cls.from_dict(data)
155
+ except (DbtRuntimeError, ValidationError) as e:
156
+ msg = str(e) if isinstance(e, DbtRuntimeError) else e.message
157
+ raise DbtProfileError(
158
+ 'Credentials in profile "{}", target "{}" invalid: {}'.format(
159
+ profile_name, target_name, msg
160
+ )
161
+ ) from e
162
+
163
+ return credentials
164
+
165
+ @staticmethod
166
+ def pick_profile_name(
167
+ args_profile_name: Optional[str],
168
+ project_profile_name: Optional[str] = None,
169
+ ) -> str:
170
+ # TODO: Duplicating this method as direct copy of the implementation in dbt.cli.resolvers
171
+ # dbt.cli.resolvers implementation can't be used because it causes a circular dependency.
172
+ # This should be removed and use a safe default access on the Flags module when
173
+ # https://github.com/dbt-labs/dbt-core/issues/6259 is closed.
174
+ def default_profiles_dir():
175
+ from pathlib import Path
176
+
177
+ return Path.cwd() if (Path.cwd() / "profiles.yml").exists() else Path.home() / ".dbt"
178
+
179
+ profile_name = project_profile_name
180
+ if args_profile_name is not None:
181
+ profile_name = args_profile_name
182
+ if profile_name is None:
183
+ NO_SUPPLIED_PROFILE_ERROR = """\
184
+ dbt cannot run because no profile was specified for this dbt project.
185
+ To specify a profile for this project, add a line like the this to
186
+ your dbt_project.yml file:
187
+
188
+ profile: [profile name]
189
+
190
+ Here, [profile name] should be replaced with a profile name
191
+ defined in your profiles.yml file. You can find profiles.yml here:
192
+
193
+ {profiles_file}/profiles.yml
194
+ """.format(
195
+ profiles_file=default_profiles_dir()
196
+ )
197
+ raise DbtProjectError(NO_SUPPLIED_PROFILE_ERROR)
198
+ return profile_name
199
+
200
+ @staticmethod
201
+ def _get_profile_data(
202
+ profile: Dict[str, Any], profile_name: str, target_name: str
203
+ ) -> Dict[str, Any]:
204
+ if "outputs" not in profile:
205
+ raise DbtProfileError("outputs not specified in profile '{}'".format(profile_name))
206
+ outputs = profile["outputs"]
207
+
208
+ if target_name not in outputs:
209
+ outputs = "\n".join(" - {}".format(output) for output in outputs)
210
+ msg = (
211
+ "The profile '{}' does not have a target named '{}'. The "
212
+ "valid target names for this profile are:\n{}".format(
213
+ profile_name, target_name, outputs
214
+ )
215
+ )
216
+ raise DbtProfileError(msg, result_type="invalid_target")
217
+ profile_data = outputs[target_name]
218
+
219
+ if not isinstance(profile_data, dict):
220
+ msg = (
221
+ f"output '{target_name}' of profile '{profile_name}' is "
222
+ f"misconfigured in profiles.yml"
223
+ )
224
+ raise DbtProfileError(msg, result_type="invalid_target")
225
+
226
+ return profile_data
227
+
228
+ @classmethod
229
+ def from_credentials(
230
+ cls,
231
+ credentials: Credentials,
232
+ threads: int,
233
+ profile_name: str,
234
+ target_name: str,
235
+ ) -> "Profile":
236
+ """Create a profile from an existing set of Credentials and the
237
+ remaining information.
238
+
239
+ :param credentials: The credentials dict for this profile.
240
+ :param threads: The number of threads to use for connections.
241
+ :param profile_name: The profile name used for this profile.
242
+ :param target_name: The target name used for this profile.
243
+ :raises DbtProfileError: If the profile is invalid.
244
+ :returns: The new Profile object.
245
+ """
246
+
247
+ profile = cls(
248
+ profile_name=profile_name,
249
+ target_name=target_name,
250
+ threads=threads,
251
+ credentials=credentials,
252
+ )
253
+ profile.validate()
254
+ return profile
255
+
256
+ @classmethod
257
+ def render_profile(
258
+ cls,
259
+ raw_profile: Dict[str, Any],
260
+ profile_name: str,
261
+ target_override: Optional[str],
262
+ renderer: ProfileRenderer,
263
+ ) -> Tuple[str, Dict[str, Any]]:
264
+ """This is a containment zone for the hateful way we're rendering
265
+ profiles.
266
+ """
267
+ # rendering profiles is a bit complex. Two constraints cause trouble:
268
+ # 1) users should be able to use environment/cli variables to specify
269
+ # the target in their profile.
270
+ # 2) Missing environment/cli variables in profiles/targets that don't
271
+ # end up getting selected should not cause errors.
272
+ # so first we'll just render the target name, then we use that rendered
273
+ # name to extract a profile that we can render.
274
+ if target_override is not None:
275
+ target_name = target_override
276
+ elif "target" in raw_profile:
277
+ # render the target if it was parsed from yaml
278
+ target_name = renderer.render_value(raw_profile["target"])
279
+ else:
280
+ target_name = "default"
281
+ fire_event(MissingProfileTarget(profile_name=profile_name, target_name=target_name))
282
+
283
+ raw_profile_data = cls._get_profile_data(raw_profile, profile_name, target_name)
284
+
285
+ try:
286
+ profile_data = renderer.render_data(raw_profile_data)
287
+ except CompilationError as exc:
288
+ raise DbtProfileError(str(exc)) from exc
289
+ return target_name, profile_data
290
+
291
+ @classmethod
292
+ def from_raw_profile_info(
293
+ cls,
294
+ raw_profile: Dict[str, Any],
295
+ profile_name: str,
296
+ renderer: ProfileRenderer,
297
+ target_override: Optional[str] = None,
298
+ threads_override: Optional[int] = None,
299
+ ) -> "Profile":
300
+ """Create a profile from its raw profile information.
301
+
302
+ (this is an intermediate step, mostly useful for unit testing)
303
+
304
+ :param raw_profile: The profile data for a single profile, from
305
+ disk as yaml and its values rendered with jinja.
306
+ :param profile_name: The profile name used.
307
+ :param renderer: The config renderer.
308
+ :param target_override: The target to use, if provided on
309
+ the command line.
310
+ :param threads_override: The thread count to use, if
311
+ provided on the command line.
312
+ :raises DbtProfileError: If the profile is invalid or missing, or the
313
+ target could not be found
314
+ :returns: The new Profile object.
315
+ """
316
+ # TODO: should it be, and the values coerced to bool?
317
+ target_name, profile_data = cls.render_profile(
318
+ raw_profile, profile_name, target_override, renderer
319
+ )
320
+
321
+ # valid connections never include the number of threads, but it's
322
+ # stored on a per-connection level in the raw configs
323
+ threads = profile_data.pop("threads", DEFAULT_THREADS)
324
+ if threads_override is not None:
325
+ threads = threads_override
326
+
327
+ credentials: Credentials = cls._credentials_from_profile(
328
+ profile_data, profile_name, target_name
329
+ )
330
+
331
+ return cls.from_credentials(
332
+ credentials=credentials,
333
+ profile_name=profile_name,
334
+ target_name=target_name,
335
+ threads=threads,
336
+ )
337
+
338
+ @classmethod
339
+ def from_raw_profiles(
340
+ cls,
341
+ raw_profiles: Dict[str, Any],
342
+ profile_name: str,
343
+ renderer: ProfileRenderer,
344
+ target_override: Optional[str] = None,
345
+ threads_override: Optional[int] = None,
346
+ ) -> "Profile":
347
+ """
348
+ :param raw_profiles: The profile data, from disk as yaml.
349
+ :param profile_name: The profile name to use.
350
+ :param renderer: The config renderer.
351
+ :param target_override: The target to use, if provided on the command
352
+ line.
353
+ :param threads_override: The thread count to use, if provided on the
354
+ command line.
355
+ :raises DbtProjectError: If there is no profile name specified in the
356
+ project or the command line arguments
357
+ :raises DbtProfileError: If the profile is invalid or missing, or the
358
+ target could not be found
359
+ :returns: The new Profile object.
360
+ """
361
+ if profile_name not in raw_profiles:
362
+ raise DbtProjectError("Could not find profile named '{}'".format(profile_name))
363
+
364
+ # First, we've already got our final decision on profile name, and we
365
+ # don't render keys, so we can pluck that out
366
+ raw_profile = raw_profiles[profile_name]
367
+ if not raw_profile:
368
+ msg = f"Profile {profile_name} in profiles.yml is empty"
369
+ raise DbtProfileError(INVALID_PROFILE_MESSAGE.format(error_string=msg))
370
+
371
+ return cls.from_raw_profile_info(
372
+ raw_profile=raw_profile,
373
+ profile_name=profile_name,
374
+ renderer=renderer,
375
+ target_override=target_override,
376
+ threads_override=threads_override,
377
+ )
378
+
379
+ @classmethod
380
+ def render(
381
+ cls,
382
+ renderer: ProfileRenderer,
383
+ project_profile_name: Optional[str],
384
+ profile_name_override: Optional[str] = None,
385
+ target_override: Optional[str] = None,
386
+ threads_override: Optional[int] = None,
387
+ ) -> "Profile":
388
+ """Given the raw profiles as read from disk and the name of the desired
389
+ profile if specified, return the profile component of the runtime
390
+ config.
391
+
392
+ :param args argparse.Namespace: The arguments as parsed from the cli.
393
+ :param project_profile_name Optional[str]: The profile name, if
394
+ specified in a project.
395
+ :raises DbtProjectError: If there is no profile name specified in the
396
+ project or the command line arguments, or if the specified profile
397
+ is not found
398
+ :raises DbtProfileError: If the profile is invalid or missing, or the
399
+ target could not be found.
400
+ :returns Profile: The new Profile object.
401
+ """
402
+ flags = get_flags()
403
+ raw_profiles = read_profile(flags.PROFILES_DIR)
404
+ profile_name = cls.pick_profile_name(profile_name_override, project_profile_name)
405
+ return cls.from_raw_profiles(
406
+ raw_profiles=raw_profiles,
407
+ profile_name=profile_name,
408
+ renderer=renderer,
409
+ target_override=target_override,
410
+ threads_override=threads_override,
411
+ )