-
Notifications
You must be signed in to change notification settings - Fork 220
MyPy support in OSS #990
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
MyPy support in OSS #990
Changes from all commits
d3e6f25
8beca3d
6a8a103
2f02c49
33f7356
4b07653
dc47a7a
7aab97b
433d8b5
bf8d9f1
0aa2516
7e29263
dad9a74
bf26b2b
7c2b588
47835e8
481d551
a0785ec
fb2dbbb
89a6254
462a7d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| recursive-include elementary *.py *.sql *.yml *.html *.md .gitkeep .gitignore | ||
| recursive-include elementary *.py *.sql *.yml *.html *.md .gitkeep .gitignore py.typed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,10 @@ | |
| import json | ||
| import os | ||
| from pathlib import Path | ||
| from typing import Any, Dict, Optional, Union | ||
| from typing import Any, Dict, Optional, Union, cast | ||
|
|
||
| import dbt.adapters.factory | ||
| from dbt.adapters.base import BaseAdapter, BaseConnectionManager | ||
| from packaging import version | ||
|
|
||
| # IMPORTANT: This must be kept before the rest of the dbt imports | ||
|
|
@@ -82,10 +83,12 @@ def __init__( | |
| **kwargs, | ||
| ): | ||
| super().__init__(project_dir, profiles_dir, target, vars, secret_vars) | ||
| self.config = None | ||
| self.adapter = None | ||
| self.adapter_name = None | ||
| self.project_parser = None | ||
|
|
||
| self.config: Optional[RuntimeConfig] = None | ||
| self.adapter: Optional[BaseAdapter] = None | ||
| self.adapter_name: Optional[str] = None | ||
| self.connections_manager: Optional[BaseConnectionManager] = None | ||
| self.project_parser: Optional[ManifestLoader] = None | ||
| self.manifest = None | ||
|
|
||
| def _load_runner( | ||
|
|
@@ -126,23 +129,41 @@ def _load_config(self): | |
| self.config = RuntimeConfig.from_args(self.args) | ||
|
|
||
| def _load_adapter(self): | ||
| if not self.config: | ||
| raise Exception("Config not loaded") | ||
|
|
||
| register_adapter(self.config) | ||
| self.adapter_name = self.config.credentials.type | ||
| self.adapter = get_adapter_class_by_name(self.adapter_name)(self.config) | ||
| self.adapter.connections.set_connection_name() | ||
| self.config.adapter = self.adapter | ||
| self.adapter = cast( | ||
| BaseAdapter, get_adapter_class_by_name(self.adapter_name)(self.config) | ||
| ) | ||
|
elongl marked this conversation as resolved.
|
||
|
|
||
| self.connections_manager = cast(BaseConnectionManager, self.adapter.connections) | ||
| self.connections_manager.set_connection_name() | ||
|
|
||
| self.config.adapter = self.adapter # type: ignore[attr-defined] | ||
|
|
||
| def _load_manifest(self): | ||
| if not self.config: | ||
| raise Exception("Config not loaded") | ||
| if not self.adapter or not self.connections_manager: | ||
| raise Exception("Adapter not loaded") | ||
|
|
||
| self.project_parser = ManifestLoader( | ||
| self.config, | ||
| self.config.load_dependencies(), | ||
| self.adapter.connections.set_query_header, | ||
| self.connections_manager.set_query_header, | ||
| ) | ||
| self.manifest = self.project_parser.load() | ||
| if self.manifest is None: | ||
| raise Exception("Failed to load manifest!") | ||
| self.manifest.build_flat_graph() | ||
| self.project_parser.save_macros_to_adapter(self.adapter) | ||
|
|
||
| def _execute_macro(self, macro_name, **kwargs): | ||
| if not self.adapter: | ||
| raise Exception("Adapter not loaded") | ||
|
|
||
| if "." in macro_name: | ||
| package_name, actual_macro_name = macro_name.split(".", 1) | ||
| else: | ||
|
|
@@ -157,18 +178,24 @@ def _execute_macro(self, macro_name, **kwargs): | |
| ) | ||
|
|
||
| def close_connection(self): | ||
| self.adapter.connections.cleanup_all() | ||
| if self.connections_manager: | ||
| self.connections_manager.cleanup_all() | ||
|
|
||
| def run_operation( | ||
| self, | ||
| macro_name: str, | ||
| capture_output: bool = True, | ||
| macro_args: dict = dict(), | ||
| macro_args: Optional[dict] = None, | ||
| log_errors: bool = True, | ||
| vars: Optional[dict] = None, | ||
| quiet: bool = False, | ||
| **kwargs, | ||
| ) -> list: | ||
| if self.profiles_dir is None: | ||
|
Contributor
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. Doesn't it use dbt's default in this case?
Collaborator
Author
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. I recall this was broken in dbt 1.5 |
||
| raise Exception("profiles_dir must be passed to SlimDbtRunner") | ||
|
|
||
| macro_args = macro_args or {} | ||
|
|
||
| all_vars = self._get_all_vars(vars) | ||
| self._load_runner( | ||
| project_dir=self.project_dir, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
| from elementary.monitor.fetchers.alerts.normalized_alert import CHANNEL_KEY | ||
| from elementary.utils.json_utils import ( | ||
| list_of_lists_of_strings_to_comma_delimited_unique_strings, | ||
| try_load_json, | ||
| ) | ||
| from elementary.utils.models import get_shortened_model_name | ||
|
|
||
|
|
@@ -109,7 +108,7 @@ def _fill_components_to_alerts(self): | |
| test_errors = [] | ||
| test_warnings = [] | ||
| test_failures = [] | ||
| model_errors = [] | ||
| model_errors: List[Alert] = [] | ||
| for alert in self.alerts: | ||
| if isinstance(alert, ModelAlert): | ||
| model_errors.append(alert) | ||
|
|
@@ -164,14 +163,14 @@ def to_slack(self) -> SlackMessageSchema: | |
| f":{TestErrorComponent.emoji_in_summary}: {TestErrorComponent.name_in_summary}: {len(alert_list)}" | ||
| ) | ||
| title_blocks.append(self._message_builder.create_context_block(fields_summary)) | ||
| self._message_builder._add_title_to_slack_alert(title_blocks=title_blocks) | ||
| self._message_builder.add_title_to_slack_alert(title_blocks=title_blocks) | ||
|
|
||
| # attention required : tags, owners, subscribers | ||
| preview_blocks = [ | ||
| self._message_builder.create_text_section_block(block) | ||
| for block in self._attention_required_blocks() | ||
| ] + [self._message_builder.create_empty_section_block()] | ||
| self._message_builder._add_preview_to_slack_alert(preview_blocks=preview_blocks) | ||
| self._message_builder.add_preview_to_slack_alert(preview_blocks=preview_blocks) | ||
|
|
||
| details_blocks = [] | ||
| for component, alerts_list in self._components_to_alerts.items(): | ||
|
|
@@ -237,7 +236,7 @@ def _get_model_error_block_body(self) -> str: | |
| return "" | ||
|
|
||
| def _attention_required_blocks(self): | ||
| preview_blocks = [f"*{self._db}.{self._schema}.{self._model}*"] | ||
|
Contributor
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. Why this change?
Collaborator
Author
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. Yeah this code is pretty horrible |
||
| preview_blocks = [] | ||
|
|
||
| for component, val in sorted( | ||
| self._components_to_attention_required.items(), key=lambda x: x[0].order | ||
|
|
@@ -299,9 +298,9 @@ def _sort_channel_destination(self, default_channel): | |
| if alert.slack_channel: | ||
| model_specific_channel_config = alert.slack_channel | ||
| break | ||
| model_meta_data = try_load_json(alert.model_meta) | ||
| if model_meta_data and isinstance(model_meta_data, dict): | ||
| model_specific_channel_config = model_meta_data.get(CHANNEL_KEY) | ||
|
|
||
| model_specific_channel_config = alert.model_meta.get(CHANNEL_KEY) | ||
| if model_specific_channel_config: | ||
|
Collaborator
Author
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. A bit unsure if I'm missing anything here, but it does look like model_meta is always parsed in |
||
| break | ||
|
|
||
| if model_specific_channel_config: | ||
|
|
@@ -310,7 +309,14 @@ def _sort_channel_destination(self, default_channel): | |
| self.channel_destination = default_channel | ||
|
|
||
| def _get_tabulated_row_from_alert(self, alert: Alert) -> str: | ||
| return alert.consice_name | ||
| return alert.concise_name | ||
|
|
||
| def _attention_required_blocks(self): | ||
| preview_blocks = [f"*{self._db}.{self._schema}.{self._model}*"] | ||
| preview_blocks.extend( | ||
| super(GroupOfAlertsByTable, self)._attention_required_blocks() | ||
| ) | ||
| return preview_blocks | ||
|
|
||
|
|
||
| class GroupOfAlertsBySingleAlert(GroupOfAlerts): | ||
|
|
@@ -333,10 +339,10 @@ def to_slack(self): | |
| return self.alerts[0].to_slack() | ||
|
|
||
| def set_owners(self, owners: List[str]): | ||
| self.alerts[0].owners = ", ".join(owners) | ||
| self.alerts[0].owners = owners | ||
|
|
||
| def set_subscribers(self, subscribers: List[str]): | ||
| self.alerts[0].subscribers = ", ".join(subscribers) | ||
| self.alerts[0].subscribers = subscribers | ||
|
|
||
| def set_tags(self, tags: List[str]): | ||
| self.alerts[0].tags = ", ".join(tags) | ||
| self.alerts[0].tags = tags | ||
Uh oh!
There was an error while loading. Please reload this page.