dbt-common 1.16.0__tar.gz → 1.18__tar.gz
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.
- {dbt_common-1.16.0 → dbt_common-1.18}/CHANGELOG.md +29 -2
- {dbt_common-1.16.0 → dbt_common-1.18}/PKG-INFO +2 -1
- dbt_common-1.18/dbt_common/__about__.py +1 -0
- dbt_common-1.18/dbt_common/events/event_manager.py +138 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/event_manager_client.py +0 -3
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/functions.py +13 -10
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/helpers.py +2 -2
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/logger.py +2 -2
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/types.proto +10 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/types.py +11 -1
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/types_pb2.py +5 -1
- dbt_common-1.18/dbt_common/helper_types.py +270 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/record.py +69 -28
- {dbt_common-1.16.0 → dbt_common-1.18}/pyproject.toml +1 -0
- dbt_common-1.16.0/dbt_common/__about__.py +0 -1
- dbt_common-1.16.0/dbt_common/events/event_manager.py +0 -73
- dbt_common-1.16.0/dbt_common/helper_types.py +0 -134
- {dbt_common-1.16.0 → dbt_common-1.18}/.gitignore +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/LICENSE +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/README.md +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/codecov.yml +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/__init__.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/behavior_flags.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/clients/__init__.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/clients/_jinja_blocks.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/clients/agate_helper.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/clients/jinja.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/clients/system.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/constants.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/context.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/__init__.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/config/__init__.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/config/base.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/config/materialization.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/config/metadata.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/config/properties.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/constraints.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/metadata.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/contracts/util.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/dataclass_schema.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/README.md +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/__init__.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/base_types.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/contextvars.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/event_handler.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/format.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/events/interfaces.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/__init__.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/base.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/cache.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/connection.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/contracts.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/events.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/jinja.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/macros.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/exceptions/system.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/invocation.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/py.typed +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/semver.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/tests.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/ui.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/utils/__init__.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/utils/casting.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/utils/connection.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/utils/dict.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/utils/encoding.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/utils/executor.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/utils/formatting.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/dbt_common/utils/jinja.py +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/docs/README.md +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/docs/arch/adr-0001-build-tooling.md +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/docs/guides/record_replay.md +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/agate/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/agate/data_types.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/colorama/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/isodate/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/config.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/const.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/helpers.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/code/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/code/builder.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/code/lines.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/helpers.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/mixin.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/types/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/types/common.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/types/pack.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/core/meta/types/unpack.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/dialect.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/exceptions.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/helper.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/jsonschema/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/jsonschema/annotations.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/jsonschema/builder.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/jsonschema/dialects.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/jsonschema/models.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/jsonschema/schema.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/mixins/__init__.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/mixins/dict.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/mixins/json.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/mixins/msgpack.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/mixins/orjson.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/mixins/toml.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/mixins/yaml.pyi +0 -0
- {dbt_common-1.16.0 → dbt_common-1.18}/third-party-stubs/mashumaro/types.pyi +0 -0
@@ -5,13 +5,40 @@
|
|
5
5
|
- "Breaking changes" listed under a version may require action from end users or external maintainers when upgrading to that version.
|
6
6
|
- Do not edit this file directly. This file is auto-generated using [changie](https://github.com/miniscruff/changie). For details on how to document a change, see [the contributing guide](https://github.com/dbt-labs/dbt-common/blob/main/CONTRIBUTING.md#adding-changelog-entry)
|
7
7
|
|
8
|
-
## dbt-common 1.
|
8
|
+
## dbt-common 1.18 - April 14, 2025
|
9
9
|
|
10
10
|
### Features
|
11
11
|
|
12
|
-
-
|
12
|
+
- Ability to specify 'Deprecations' in `WarnErrorOptions` ([#265](https://github.com/dbt-labs/dbt-common/issues/265))
|
13
|
+
|
14
|
+
### Fixes
|
15
|
+
|
16
|
+
- Replace depricated datetime.datetime.utcnow() for datetime.datetime.now(timezone.utc) to reduce stdout spam. ([#238](https://github.com/dbt-labs/dbt-common/issues/238), [#99](https://github.com/dbt-labs/dbt-common/issues/99))
|
17
|
+
|
18
|
+
### Under the Hood
|
19
|
+
|
20
|
+
- Add support for Python 3.13 ([#263](https://github.com/dbt-labs/dbt-common/issues/263))
|
21
|
+
- Add new event to signal issues during record/replay ([#268](https://github.com/dbt-labs/dbt-common/issues/268))
|
22
|
+
|
23
|
+
### Contributors
|
24
|
+
- [@cfernhout](https://github.com/cfernhout) ([#238](https://github.com/dbt-labs/dbt-common/issues/238), [#99](https://github.com/dbt-labs/dbt-common/issues/99))
|
25
|
+
|
13
26
|
|
27
|
+
## dbt-common 1.17.0 - March 31, 2025
|
14
28
|
|
29
|
+
### Breaking Changes
|
30
|
+
|
31
|
+
- Update `fire_event` to handle `warn_or_error` logic ([#236](https://github.com/dbt-labs/dbt-common/issues/236))
|
32
|
+
|
33
|
+
### Under the Hood
|
34
|
+
|
35
|
+
- Stream recorded events to disk rather than storing them in memory. ([#260](https://github.com/dbt-labs/dbt-common/issues/260))
|
36
|
+
|
37
|
+
## dbt-common 1.16.0 - March 18, 2025
|
38
|
+
|
39
|
+
### Features
|
40
|
+
|
41
|
+
- Add sequence number to record/replay records and add new invocation context accessor ([#251](https://github.com/dbt-labs/dbt-common/issues/251))
|
15
42
|
|
16
43
|
## dbt-common 1.15.0 - February 14, 2025
|
17
44
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: dbt-common
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.18
|
4
4
|
Summary: The shared common utilities that dbt-core and adapter implementations use
|
5
5
|
Project-URL: Homepage, https://github.com/dbt-labs/dbt-common
|
6
6
|
Project-URL: Repository, https://github.com/dbt-labs/dbt-common.git
|
@@ -20,6 +20,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.10
|
21
21
|
Classifier: Programming Language :: Python :: 3.11
|
22
22
|
Classifier: Programming Language :: Python :: 3.12
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
23
24
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
24
25
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
25
26
|
Requires-Python: >=3.9
|
@@ -0,0 +1 @@
|
|
1
|
+
version = "1.18"
|
@@ -0,0 +1,138 @@
|
|
1
|
+
import os
|
2
|
+
import traceback
|
3
|
+
from typing import Any, List, Optional, Protocol, Tuple
|
4
|
+
|
5
|
+
from dbt_common.events.base_types import BaseEvent, EventLevel, msg_from_base_event, TCallback
|
6
|
+
from dbt_common.events.logger import LoggerConfig, _Logger, _TextLogger, _JsonLogger, LineFormat
|
7
|
+
from dbt_common.exceptions.events import EventCompilationError
|
8
|
+
from dbt_common.helper_types import WarnErrorOptions
|
9
|
+
|
10
|
+
|
11
|
+
class EventManager:
|
12
|
+
def __init__(self) -> None:
|
13
|
+
self.loggers: List[_Logger] = []
|
14
|
+
self.callbacks: List[TCallback] = []
|
15
|
+
self._warn_error: Optional[bool] = None
|
16
|
+
self._warn_error_options: Optional[WarnErrorOptions] = None
|
17
|
+
self.require_warn_or_error_handling: bool = False
|
18
|
+
|
19
|
+
@property
|
20
|
+
def warn_error(self) -> bool:
|
21
|
+
if self._warn_error is None:
|
22
|
+
from dbt_common.events.functions import WARN_ERROR
|
23
|
+
|
24
|
+
return WARN_ERROR
|
25
|
+
return self._warn_error
|
26
|
+
|
27
|
+
@warn_error.setter
|
28
|
+
def warn_error(self, warn_error: bool) -> None:
|
29
|
+
self._warn_error = warn_error
|
30
|
+
|
31
|
+
@property
|
32
|
+
def warn_error_options(self) -> WarnErrorOptions:
|
33
|
+
if self._warn_error_options is None:
|
34
|
+
from dbt_common.events.functions import WARN_ERROR_OPTIONS
|
35
|
+
|
36
|
+
return WARN_ERROR_OPTIONS
|
37
|
+
return self._warn_error_options
|
38
|
+
|
39
|
+
@warn_error_options.setter
|
40
|
+
def warn_error_options(self, warn_error_options: WarnErrorOptions) -> None:
|
41
|
+
self._warn_error_options = warn_error_options
|
42
|
+
|
43
|
+
def fire_event(
|
44
|
+
self,
|
45
|
+
e: BaseEvent,
|
46
|
+
level: Optional[EventLevel] = None,
|
47
|
+
node: Any = None,
|
48
|
+
force_warn_or_error_handling: bool = False,
|
49
|
+
) -> None:
|
50
|
+
msg = msg_from_base_event(e, level=level)
|
51
|
+
|
52
|
+
if force_warn_or_error_handling or (
|
53
|
+
self.require_warn_or_error_handling and msg.info.level == "warn"
|
54
|
+
):
|
55
|
+
event_name = type(e).__name__
|
56
|
+
if self.warn_error or self.warn_error_options.includes(event_name):
|
57
|
+
# This has the potential to create an infinite loop if the handling of the raised
|
58
|
+
# EventCompilationError fires an event as a warning instead of an error.
|
59
|
+
raise EventCompilationError(e.message(), node)
|
60
|
+
elif self.warn_error_options.silenced(event_name):
|
61
|
+
# Return early if the event is silenced
|
62
|
+
return
|
63
|
+
|
64
|
+
if os.environ.get("DBT_TEST_BINARY_SERIALIZATION"):
|
65
|
+
print(f"--- {msg.info.name}")
|
66
|
+
try:
|
67
|
+
msg.SerializeToString()
|
68
|
+
except Exception as exc:
|
69
|
+
raise Exception(
|
70
|
+
f"{msg.info.name} is not serializable to binary. ",
|
71
|
+
f"Originating exception: {exc}, {traceback.format_exc()}",
|
72
|
+
)
|
73
|
+
|
74
|
+
for logger in self.loggers:
|
75
|
+
if logger.filter(msg): # type: ignore
|
76
|
+
logger.write_line(msg)
|
77
|
+
|
78
|
+
for callback in self.callbacks:
|
79
|
+
callback(msg)
|
80
|
+
|
81
|
+
def add_logger(self, config: LoggerConfig) -> None:
|
82
|
+
logger = (
|
83
|
+
_JsonLogger(config) if config.line_format == LineFormat.Json else _TextLogger(config)
|
84
|
+
)
|
85
|
+
self.loggers.append(logger)
|
86
|
+
|
87
|
+
def add_callback(self, callback: TCallback) -> None:
|
88
|
+
self.callbacks.append(callback)
|
89
|
+
|
90
|
+
def flush(self) -> None:
|
91
|
+
for logger in self.loggers:
|
92
|
+
logger.flush()
|
93
|
+
|
94
|
+
|
95
|
+
class IEventManager(Protocol):
|
96
|
+
callbacks: List[TCallback]
|
97
|
+
loggers: List[_Logger]
|
98
|
+
warn_error: bool
|
99
|
+
warn_error_options: WarnErrorOptions
|
100
|
+
require_warn_or_error_handling: bool
|
101
|
+
|
102
|
+
def fire_event(
|
103
|
+
self,
|
104
|
+
e: BaseEvent,
|
105
|
+
level: Optional[EventLevel] = None,
|
106
|
+
node: Any = None,
|
107
|
+
force_warn_or_error_handling: bool = False,
|
108
|
+
) -> None:
|
109
|
+
...
|
110
|
+
|
111
|
+
def add_logger(self, config: LoggerConfig) -> None:
|
112
|
+
...
|
113
|
+
|
114
|
+
def add_callback(self, callback: TCallback) -> None:
|
115
|
+
...
|
116
|
+
|
117
|
+
|
118
|
+
class TestEventManager(IEventManager):
|
119
|
+
__test__ = False
|
120
|
+
|
121
|
+
def __init__(self) -> None:
|
122
|
+
self.event_history: List[Tuple[BaseEvent, Optional[EventLevel]]] = []
|
123
|
+
self.loggers = []
|
124
|
+
self.warn_error = False
|
125
|
+
self.warn_error_options = WarnErrorOptions(include=[], exclude=[])
|
126
|
+
self.require_warn_or_error_handling = False
|
127
|
+
|
128
|
+
def fire_event(
|
129
|
+
self,
|
130
|
+
e: BaseEvent,
|
131
|
+
level: Optional[EventLevel] = None,
|
132
|
+
node: Any = None,
|
133
|
+
force_warn_or_error_handling: bool = False,
|
134
|
+
) -> None:
|
135
|
+
self.event_history.append((e, level))
|
136
|
+
|
137
|
+
def add_logger(self, config: LoggerConfig) -> None:
|
138
|
+
raise NotImplementedError()
|
@@ -8,17 +8,14 @@ _EVENT_MANAGER: IEventManager = EventManager()
|
|
8
8
|
|
9
9
|
|
10
10
|
def get_event_manager() -> IEventManager:
|
11
|
-
global _EVENT_MANAGER
|
12
11
|
return _EVENT_MANAGER
|
13
12
|
|
14
13
|
|
15
14
|
def add_logger_to_manager(logger) -> None:
|
16
|
-
global _EVENT_MANAGER
|
17
15
|
_EVENT_MANAGER.add_logger(logger)
|
18
16
|
|
19
17
|
|
20
18
|
def add_callback_to_manager(callback: TCallback) -> None:
|
21
|
-
global _EVENT_MANAGER
|
22
19
|
_EVENT_MANAGER.add_callback(callback)
|
23
20
|
|
24
21
|
|
@@ -1,9 +1,8 @@
|
|
1
1
|
from pathlib import Path
|
2
2
|
|
3
3
|
from dbt_common.events.event_manager_client import get_event_manager
|
4
|
-
from dbt_common.exceptions import EventCompilationError
|
5
|
-
from dbt_common.invocation import get_invocation_id
|
6
4
|
from dbt_common.helper_types import WarnErrorOptions
|
5
|
+
from dbt_common.invocation import get_invocation_id
|
7
6
|
from dbt_common.utils.encoding import ForgivingJSONEncoder
|
8
7
|
from dbt_common.events.base_types import BaseEvent, EventLevel, EventMsg
|
9
8
|
from dbt_common.events.logger import LoggerConfig, LineFormat
|
@@ -13,7 +12,7 @@ from functools import partial
|
|
13
12
|
import json
|
14
13
|
import os
|
15
14
|
import sys
|
16
|
-
from typing import Callable, Dict, Optional, TextIO, Union
|
15
|
+
from typing import Any, Callable, Dict, Optional, TextIO, Union
|
17
16
|
from google.protobuf.json_format import MessageToDict
|
18
17
|
|
19
18
|
LOG_VERSION = 3
|
@@ -114,12 +113,9 @@ def msg_to_dict(msg: EventMsg) -> dict:
|
|
114
113
|
return msg_dict
|
115
114
|
|
116
115
|
|
116
|
+
# This function continues to exist to provide backwards compatibility
|
117
117
|
def warn_or_error(event, node=None) -> None:
|
118
|
-
|
119
|
-
if WARN_ERROR or WARN_ERROR_OPTIONS.includes(event_name):
|
120
|
-
raise EventCompilationError(event.message(), node)
|
121
|
-
elif not WARN_ERROR_OPTIONS.silenced(event_name):
|
122
|
-
fire_event(event)
|
118
|
+
fire_event(e=event, node=node, force_warn_or_error_handling=True)
|
123
119
|
|
124
120
|
|
125
121
|
# an alternative to fire_event which only creates and logs the event value
|
@@ -135,8 +131,15 @@ def fire_event_if(
|
|
135
131
|
# this is where all the side effects happen branched by event type
|
136
132
|
# (i.e. - mutating the event history, printing to stdout, logging
|
137
133
|
# to files, etc.)
|
138
|
-
def fire_event(
|
139
|
-
|
134
|
+
def fire_event(
|
135
|
+
e: BaseEvent,
|
136
|
+
level: Optional[EventLevel] = None,
|
137
|
+
node: Any = None,
|
138
|
+
force_warn_or_error_handling: bool = False,
|
139
|
+
) -> None:
|
140
|
+
get_event_manager().fire_event(
|
141
|
+
e, level=level, node=node, force_warn_or_error_handling=force_warn_or_error_handling
|
142
|
+
)
|
140
143
|
|
141
144
|
|
142
145
|
def get_metadata_vars() -> Dict[str, str]:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from datetime import datetime
|
1
|
+
from datetime import datetime, timezone
|
2
2
|
|
3
3
|
|
4
4
|
# This converts a datetime to a json format datetime string which
|
@@ -9,6 +9,6 @@ def datetime_to_json_string(dt: datetime) -> str:
|
|
9
9
|
|
10
10
|
# preformatted time stamp
|
11
11
|
def get_json_string_utcnow() -> str:
|
12
|
-
ts = datetime.
|
12
|
+
ts = datetime.now(timezone.utc).replace(tzinfo=None)
|
13
13
|
ts_rfc3339 = datetime_to_json_string(ts)
|
14
14
|
return ts_rfc3339
|
@@ -2,7 +2,7 @@ import json
|
|
2
2
|
import logging
|
3
3
|
import threading
|
4
4
|
from dataclasses import dataclass
|
5
|
-
from datetime import datetime
|
5
|
+
from datetime import datetime, timezone
|
6
6
|
from enum import Enum
|
7
7
|
from logging.handlers import RotatingFileHandler
|
8
8
|
from typing import Optional, TextIO, Any, Callable
|
@@ -156,7 +156,7 @@ class _TextLogger(_Logger):
|
|
156
156
|
if _is_print_event(msg):
|
157
157
|
# PrintEvent is a special case, we don't want to add a timestamp
|
158
158
|
return scrubbed_msg
|
159
|
-
ts: str = datetime.
|
159
|
+
ts: str = datetime.now(timezone.utc).replace(tzinfo=None).strftime("%H:%M:%S")
|
160
160
|
return f"{self._get_color_tag()}{ts} {scrubbed_msg}"
|
161
161
|
|
162
162
|
def create_debug_line(self, msg: EventMsg) -> str:
|
@@ -144,3 +144,13 @@ message PrintEventMsg {
|
|
144
144
|
EventInfo info = 1;
|
145
145
|
PrintEvent data = 2;
|
146
146
|
}
|
147
|
+
|
148
|
+
// Z053
|
149
|
+
message RecordReplayIssue {
|
150
|
+
string msg = 1;
|
151
|
+
}
|
152
|
+
|
153
|
+
message RecordReplayIssueMsg {
|
154
|
+
EventInfo info = 1;
|
155
|
+
RecordReplayIssue data = 2;
|
156
|
+
}
|
@@ -118,7 +118,7 @@ class SystemReportReturnCode(DebugLevel):
|
|
118
118
|
|
119
119
|
|
120
120
|
# We use events to create console output, but also think of them as a sequence of important and
|
121
|
-
# meaningful occurrences to be used for debugging and monitoring. The Formatting event
|
121
|
+
# meaningful occurrences to be used for debugging and monitoring. The Formatting event eases
|
122
122
|
# the tension between these two goals by allowing empty lines, heading separators, and other
|
123
123
|
# formatting to be written to the console, while they can be ignored for other purposes. For
|
124
124
|
# general information that isn't simple formatting, the Note event should be used instead.
|
@@ -156,3 +156,13 @@ class PrintEvent(InfoLevel):
|
|
156
156
|
|
157
157
|
def message(self) -> str:
|
158
158
|
return self.msg
|
159
|
+
|
160
|
+
|
161
|
+
class RecordReplayIssue(InfoLevel):
|
162
|
+
"""General event for reporting record/replay issues at runtime."""
|
163
|
+
|
164
|
+
def code(self) -> str:
|
165
|
+
return "Z053"
|
166
|
+
|
167
|
+
def message(self) -> str:
|
168
|
+
return self.msg
|
@@ -25,7 +25,7 @@ _sym_db = _symbol_database.Default()
|
|
25
25
|
from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2
|
26
26
|
|
27
27
|
|
28
|
-
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0btypes.proto\x12\x0bproto_types\x1a\x1fgoogle/protobuf/timestamp.proto\"\x91\x02\n\tEventInfo\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04\x63ode\x18\x02 \x01(\t\x12\x0b\n\x03msg\x18\x03 \x01(\t\x12\r\n\x05level\x18\x04 \x01(\t\x12\x15\n\rinvocation_id\x18\x05 \x01(\t\x12\x0b\n\x03pid\x18\x06 \x01(\x05\x12\x0e\n\x06thread\x18\x07 \x01(\t\x12&\n\x02ts\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x30\n\x05\x65xtra\x18\t \x03(\x0b\x32!.proto_types.EventInfo.ExtraEntry\x12\x10\n\x08\x63\x61tegory\x18\n \x01(\t\x1a,\n\nExtraEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"6\n\x0eGenericMessage\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\"d\n\x13\x42\x65haviorChangeEvent\x12\x11\n\tflag_name\x18\x01 \x01(\t\x12\x13\n\x0b\x66lag_source\x18\x02 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\t\x12\x10\n\x08\x64ocs_url\x18\x04 \x01(\t\"n\n\x16\x42\x65haviorChangeEventMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12.\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32 .proto_types.BehaviorChangeEvent\"1\n\x11RetryExternalCall\x12\x0f\n\x07\x61ttempt\x18\x01 \x01(\x05\x12\x0b\n\x03max\x18\x02 \x01(\x05\"j\n\x14RetryExternalCallMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12,\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1e.proto_types.RetryExternalCall\"#\n\x14RecordRetryException\x12\x0b\n\x03\x65xc\x18\x01 \x01(\t\"p\n\x17RecordRetryExceptionMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12/\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32!.proto_types.RecordRetryException\"@\n\x13SystemCouldNotWrite\x12\x0c\n\x04path\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\x12\x0b\n\x03\x65xc\x18\x03 \x01(\t\"n\n\x16SystemCouldNotWriteMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12.\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32 .proto_types.SystemCouldNotWrite\"!\n\x12SystemExecutingCmd\x12\x0b\n\x03\x63md\x18\x01 \x03(\t\"l\n\x15SystemExecutingCmdMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12-\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1f.proto_types.SystemExecutingCmd\"\x1c\n\x0cSystemStdOut\x12\x0c\n\x04\x62msg\x18\x01 \x01(\t\"`\n\x0fSystemStdOutMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\'\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x19.proto_types.SystemStdOut\"\x1c\n\x0cSystemStdErr\x12\x0c\n\x04\x62msg\x18\x01 \x01(\t\"`\n\x0fSystemStdErrMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\'\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x19.proto_types.SystemStdErr\",\n\x16SystemReportReturnCode\x12\x12\n\nreturncode\x18\x01 \x01(\x05\"t\n\x19SystemReportReturnCodeMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\x31\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32#.proto_types.SystemReportReturnCode\"\x19\n\nFormatting\x12\x0b\n\x03msg\x18\x01 \x01(\t\"\\\n\rFormattingMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12%\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x17.proto_types.Formatting\"\x13\n\x04Note\x12\x0b\n\x03msg\x18\x01 \x01(\t\"P\n\x07NoteMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\x1f\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x11.proto_types.Note\"\x19\n\nPrintEvent\x12\x0b\n\x03msg\x18\x01 \x01(\t\"\\\n\rPrintEventMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12%\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x17.proto_types.
|
28
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0btypes.proto\x12\x0bproto_types\x1a\x1fgoogle/protobuf/timestamp.proto\"\x91\x02\n\tEventInfo\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04\x63ode\x18\x02 \x01(\t\x12\x0b\n\x03msg\x18\x03 \x01(\t\x12\r\n\x05level\x18\x04 \x01(\t\x12\x15\n\rinvocation_id\x18\x05 \x01(\t\x12\x0b\n\x03pid\x18\x06 \x01(\x05\x12\x0e\n\x06thread\x18\x07 \x01(\t\x12&\n\x02ts\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x30\n\x05\x65xtra\x18\t \x03(\x0b\x32!.proto_types.EventInfo.ExtraEntry\x12\x10\n\x08\x63\x61tegory\x18\n \x01(\t\x1a,\n\nExtraEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"6\n\x0eGenericMessage\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\"d\n\x13\x42\x65haviorChangeEvent\x12\x11\n\tflag_name\x18\x01 \x01(\t\x12\x13\n\x0b\x66lag_source\x18\x02 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\t\x12\x10\n\x08\x64ocs_url\x18\x04 \x01(\t\"n\n\x16\x42\x65haviorChangeEventMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12.\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32 .proto_types.BehaviorChangeEvent\"1\n\x11RetryExternalCall\x12\x0f\n\x07\x61ttempt\x18\x01 \x01(\x05\x12\x0b\n\x03max\x18\x02 \x01(\x05\"j\n\x14RetryExternalCallMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12,\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1e.proto_types.RetryExternalCall\"#\n\x14RecordRetryException\x12\x0b\n\x03\x65xc\x18\x01 \x01(\t\"p\n\x17RecordRetryExceptionMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12/\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32!.proto_types.RecordRetryException\"@\n\x13SystemCouldNotWrite\x12\x0c\n\x04path\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\x12\x0b\n\x03\x65xc\x18\x03 \x01(\t\"n\n\x16SystemCouldNotWriteMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12.\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32 .proto_types.SystemCouldNotWrite\"!\n\x12SystemExecutingCmd\x12\x0b\n\x03\x63md\x18\x01 \x03(\t\"l\n\x15SystemExecutingCmdMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12-\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1f.proto_types.SystemExecutingCmd\"\x1c\n\x0cSystemStdOut\x12\x0c\n\x04\x62msg\x18\x01 \x01(\t\"`\n\x0fSystemStdOutMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\'\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x19.proto_types.SystemStdOut\"\x1c\n\x0cSystemStdErr\x12\x0c\n\x04\x62msg\x18\x01 \x01(\t\"`\n\x0fSystemStdErrMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\'\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x19.proto_types.SystemStdErr\",\n\x16SystemReportReturnCode\x12\x12\n\nreturncode\x18\x01 \x01(\x05\"t\n\x19SystemReportReturnCodeMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\x31\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32#.proto_types.SystemReportReturnCode\"\x19\n\nFormatting\x12\x0b\n\x03msg\x18\x01 \x01(\t\"\\\n\rFormattingMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12%\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x17.proto_types.Formatting\"\x13\n\x04Note\x12\x0b\n\x03msg\x18\x01 \x01(\t\"P\n\x07NoteMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\x1f\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x11.proto_types.Note\"\x19\n\nPrintEvent\x12\x0b\n\x03msg\x18\x01 \x01(\t\"\\\n\rPrintEventMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12%\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x17.proto_types.PrintEvent\" \n\x11RecordReplayIssue\x12\x0b\n\x03msg\x18\x01 \x01(\t\"j\n\x14RecordReplayIssueMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12,\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1e.proto_types.RecordReplayIssueb\x06proto3')
|
29
29
|
|
30
30
|
_globals = globals()
|
31
31
|
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
@@ -84,4 +84,8 @@ if not _descriptor._USE_C_DESCRIPTORS:
|
|
84
84
|
_globals['_PRINTEVENT']._serialized_end=1909
|
85
85
|
_globals['_PRINTEVENTMSG']._serialized_start=1911
|
86
86
|
_globals['_PRINTEVENTMSG']._serialized_end=2003
|
87
|
+
_globals['_RECORDREPLAYISSUE']._serialized_start=2005
|
88
|
+
_globals['_RECORDREPLAYISSUE']._serialized_end=2037
|
89
|
+
_globals['_RECORDREPLAYISSUEMSG']._serialized_start=2039
|
90
|
+
_globals['_RECORDREPLAYISSUEMSG']._serialized_end=2145
|
87
91
|
# @@protoc_insertion_point(module_scope)
|
@@ -0,0 +1,270 @@
|
|
1
|
+
# never name this package "types", or mypy will crash in ugly ways
|
2
|
+
|
3
|
+
# necessary for annotating constructors
|
4
|
+
from __future__ import annotations
|
5
|
+
|
6
|
+
from dataclasses import dataclass, field
|
7
|
+
from typing import Tuple, AbstractSet, Union
|
8
|
+
from typing import Callable, cast, Generic, Optional, TypeVar, List, NewType, Set
|
9
|
+
|
10
|
+
from dbt_common.dataclass_schema import (
|
11
|
+
dbtClassMixin,
|
12
|
+
ValidationError,
|
13
|
+
StrEnum,
|
14
|
+
)
|
15
|
+
from dbt_common.events.base_types import BaseEvent
|
16
|
+
|
17
|
+
Port = NewType("Port", int)
|
18
|
+
|
19
|
+
|
20
|
+
class NVEnum(StrEnum):
|
21
|
+
novalue = "novalue"
|
22
|
+
|
23
|
+
def __eq__(self, other) -> bool:
|
24
|
+
return isinstance(other, NVEnum)
|
25
|
+
|
26
|
+
|
27
|
+
@dataclass
|
28
|
+
class NoValue(dbtClassMixin):
|
29
|
+
"""Sometimes, you want a way to say none that isn't None!"""
|
30
|
+
|
31
|
+
novalue: NVEnum = field(default_factory=lambda: NVEnum.novalue)
|
32
|
+
|
33
|
+
|
34
|
+
@dataclass
|
35
|
+
class IncludeExclude(dbtClassMixin):
|
36
|
+
INCLUDE_ALL = ("all", "*")
|
37
|
+
|
38
|
+
include: Union[str, List[str]]
|
39
|
+
exclude: List[str] = field(default_factory=list)
|
40
|
+
|
41
|
+
def __post_init__(self):
|
42
|
+
if isinstance(self.include, str) and self.include not in self.INCLUDE_ALL:
|
43
|
+
raise ValidationError(
|
44
|
+
f"include must be one of {self.INCLUDE_ALL} or a list of strings"
|
45
|
+
)
|
46
|
+
|
47
|
+
if self.exclude and self.include not in self.INCLUDE_ALL:
|
48
|
+
raise ValidationError(
|
49
|
+
f"exclude can only be specified if include is one of {self.INCLUDE_ALL}"
|
50
|
+
)
|
51
|
+
|
52
|
+
if isinstance(self.include, list):
|
53
|
+
self._validate_items(self.include)
|
54
|
+
|
55
|
+
if isinstance(self.exclude, list):
|
56
|
+
self._validate_items(self.exclude)
|
57
|
+
|
58
|
+
def includes(self, item_name: str) -> bool:
|
59
|
+
return (
|
60
|
+
item_name in self.include or self.include in self.INCLUDE_ALL
|
61
|
+
) and item_name not in self.exclude
|
62
|
+
|
63
|
+
def _validate_items(self, items: List[str]) -> None:
|
64
|
+
pass
|
65
|
+
|
66
|
+
|
67
|
+
class WarnErrorOptions(IncludeExclude):
|
68
|
+
"""
|
69
|
+
This class is used to configure the behavior of the warn_error feature (now part of fire_event).
|
70
|
+
|
71
|
+
include: "all", "*", or a list of event names.
|
72
|
+
exclude: a list of event names.
|
73
|
+
silence: a list of event names.
|
74
|
+
valid_error_names: a set of event names that can be named in include, exclude, and silence.
|
75
|
+
|
76
|
+
In a hierarchy of configuration, the following rules apply:
|
77
|
+
1. named > Deprecations > "all"/"*"
|
78
|
+
2. silence > exclude > include
|
79
|
+
3. (1) > (2)
|
80
|
+
"""
|
81
|
+
|
82
|
+
DEPRECATIONS = "Deprecations"
|
83
|
+
|
84
|
+
def __init__(
|
85
|
+
self,
|
86
|
+
include: Union[str, List[str]],
|
87
|
+
exclude: Optional[List[str]] = None,
|
88
|
+
valid_error_names: Optional[Set[str]] = None,
|
89
|
+
silence: Optional[List[str]] = None,
|
90
|
+
):
|
91
|
+
self.silence = silence or []
|
92
|
+
self._valid_error_names: Set[str] = valid_error_names or set()
|
93
|
+
self._valid_error_names.add(self.DEPRECATIONS)
|
94
|
+
super().__init__(include=include, exclude=(exclude or []))
|
95
|
+
|
96
|
+
def __post_init__(self):
|
97
|
+
if isinstance(self.include, str) and self.include not in self.INCLUDE_ALL:
|
98
|
+
raise ValidationError(
|
99
|
+
f"include must be one of {self.INCLUDE_ALL} or a list of strings"
|
100
|
+
)
|
101
|
+
|
102
|
+
# To specify exclude, either `include` must be "all" or "deprecations" must be
|
103
|
+
# in `include` or `silence`.
|
104
|
+
if self.exclude and not (
|
105
|
+
self.include in self.INCLUDE_ALL
|
106
|
+
or self.DEPRECATIONS in self.include
|
107
|
+
or self.DEPRECATIONS in self.silence
|
108
|
+
):
|
109
|
+
raise ValidationError(
|
110
|
+
f"exclude can only be specified if include is one of {self.INCLUDE_ALL} or "
|
111
|
+
f"{self.DEPRECATIONS} is in include or silence."
|
112
|
+
)
|
113
|
+
|
114
|
+
if isinstance(self.include, list):
|
115
|
+
self._validate_items(self.include)
|
116
|
+
|
117
|
+
if isinstance(self.exclude, list):
|
118
|
+
self._validate_items(self.exclude)
|
119
|
+
|
120
|
+
if isinstance(self.silence, list):
|
121
|
+
self._validate_items(self.silence)
|
122
|
+
|
123
|
+
def _includes_all(self) -> bool:
|
124
|
+
"""Is `*` or `all` set as include?"""
|
125
|
+
return self.include in self.INCLUDE_ALL
|
126
|
+
|
127
|
+
def _named_inclusion(self, item_name: str) -> bool:
|
128
|
+
"""Is the item_name named in the include list?"""
|
129
|
+
return item_name in self.include
|
130
|
+
|
131
|
+
def _named_exclusion(self, item_name: str) -> bool:
|
132
|
+
"""Is the item_name named in the exclude list?"""
|
133
|
+
return item_name in self.exclude
|
134
|
+
|
135
|
+
def _named_silence(self, item_name: str) -> bool:
|
136
|
+
"""Is the item_name named in the silence list?"""
|
137
|
+
return item_name in self.silence
|
138
|
+
|
139
|
+
def _include_as_deprecation(self, event: Optional[BaseEvent]) -> bool:
|
140
|
+
"""Is event included as a deprecation?"""
|
141
|
+
return (
|
142
|
+
event is not None
|
143
|
+
and event.code().startswith("D")
|
144
|
+
and self.DEPRECATIONS in self.include
|
145
|
+
)
|
146
|
+
|
147
|
+
def _exclude_as_deprecation(self, event: Optional[BaseEvent]) -> bool:
|
148
|
+
"""Is event excluded as a deprecation?"""
|
149
|
+
return (
|
150
|
+
event is not None
|
151
|
+
and event.code().startswith("D")
|
152
|
+
and self.DEPRECATIONS in self.exclude
|
153
|
+
)
|
154
|
+
|
155
|
+
def _silence_as_deprecation(self, event: Optional[BaseEvent]) -> bool:
|
156
|
+
"""Is event silenced as a deprecation?"""
|
157
|
+
return (
|
158
|
+
event is not None
|
159
|
+
and event.code().startswith("D")
|
160
|
+
and self.DEPRECATIONS in self.silence
|
161
|
+
)
|
162
|
+
|
163
|
+
def includes(self, item_name: Union[str, BaseEvent]) -> bool:
|
164
|
+
"""Is the event included?
|
165
|
+
|
166
|
+
An event included if any of the following are true:
|
167
|
+
- The event is named in `include` and not named in `exclude` or `silence`
|
168
|
+
- "*" or "all" is specified for `include`, and the event is not named in `exclude` or `silence`
|
169
|
+
- The event is a deprecation, "deprecations" is in `include`, and the event is not named in `exclude` or `silence`
|
170
|
+
nor is "deprecations" in `exclude` or `silence`
|
171
|
+
"""
|
172
|
+
# Setup based on item_name type
|
173
|
+
if isinstance(item_name, str):
|
174
|
+
event_name = item_name
|
175
|
+
event = None
|
176
|
+
else:
|
177
|
+
event_name = type(item_name).__name__
|
178
|
+
event = item_name
|
179
|
+
|
180
|
+
# Pre-compute checks that will be used multiple times
|
181
|
+
named_elsewhere = self._named_exclusion(event_name) or self._named_silence(event_name)
|
182
|
+
deprecation_elsewhere = self._exclude_as_deprecation(
|
183
|
+
event
|
184
|
+
) or self._silence_as_deprecation(event)
|
185
|
+
|
186
|
+
# Calculate result
|
187
|
+
if self._named_inclusion(event_name) and not named_elsewhere:
|
188
|
+
return True
|
189
|
+
elif self._include_as_deprecation(event) and not (
|
190
|
+
named_elsewhere or deprecation_elsewhere
|
191
|
+
):
|
192
|
+
return True
|
193
|
+
elif self._includes_all() and not (named_elsewhere or deprecation_elsewhere):
|
194
|
+
return True
|
195
|
+
else:
|
196
|
+
return False
|
197
|
+
|
198
|
+
def silenced(self, item_name: Union[str, BaseEvent]) -> bool:
|
199
|
+
"""Is the event silenced?
|
200
|
+
|
201
|
+
An event silenced if any of the following are true:
|
202
|
+
- The event is named in `silence`
|
203
|
+
- "Deprecations" is in `silence` and the event is not named in `include` or `exclude`
|
204
|
+
"""
|
205
|
+
# Setup based on item_name type
|
206
|
+
if isinstance(item_name, str):
|
207
|
+
event_name = item_name
|
208
|
+
event = None
|
209
|
+
else:
|
210
|
+
event_name = type(item_name).__name__
|
211
|
+
event = item_name
|
212
|
+
|
213
|
+
# Pre-compute checks that will be used multiple times
|
214
|
+
named_elsewhere = self._named_inclusion(event_name) or self._named_exclusion(event_name)
|
215
|
+
|
216
|
+
# Calculate result
|
217
|
+
if self._named_silence(event_name):
|
218
|
+
return True
|
219
|
+
elif self._silence_as_deprecation(event) and not named_elsewhere:
|
220
|
+
return True
|
221
|
+
else:
|
222
|
+
return False
|
223
|
+
|
224
|
+
def _validate_items(self, items: List[str]):
|
225
|
+
for item in items:
|
226
|
+
if item not in self._valid_error_names:
|
227
|
+
raise ValidationError(f"{item} is not a valid dbt error name.")
|
228
|
+
|
229
|
+
|
230
|
+
FQNPath = Tuple[str, ...]
|
231
|
+
PathSet = AbstractSet[FQNPath]
|
232
|
+
|
233
|
+
T = TypeVar("T")
|
234
|
+
|
235
|
+
|
236
|
+
# A data type for representing lazily evaluated values.
|
237
|
+
#
|
238
|
+
# usage:
|
239
|
+
# x = Lazy.defer(lambda: expensive_fn())
|
240
|
+
# y = x.force()
|
241
|
+
#
|
242
|
+
# inspired by the purescript data type
|
243
|
+
# https://pursuit.purescript.org/packages/purescript-lazy/5.0.0/docs/Data.Lazy
|
244
|
+
@dataclass
|
245
|
+
class Lazy(Generic[T]):
|
246
|
+
_f: Callable[[], T]
|
247
|
+
memo: Optional[T] = None
|
248
|
+
|
249
|
+
# constructor for lazy values
|
250
|
+
@classmethod
|
251
|
+
def defer(cls, f: Callable[[], T]) -> Lazy[T]:
|
252
|
+
return Lazy(f)
|
253
|
+
|
254
|
+
# workaround for open mypy issue:
|
255
|
+
# https://github.com/python/mypy/issues/6910
|
256
|
+
def _typed_eval_f(self) -> T:
|
257
|
+
return cast(Callable[[], T], getattr(self, "_f"))()
|
258
|
+
|
259
|
+
# evaluates the function if the value has not been memoized already
|
260
|
+
def force(self) -> T:
|
261
|
+
if self.memo is None:
|
262
|
+
self.memo = self._typed_eval_f()
|
263
|
+
return self.memo
|
264
|
+
|
265
|
+
|
266
|
+
# This class is used in to_target_dict, so that accesses to missing keys
|
267
|
+
# will return an empty string instead of Undefined
|
268
|
+
class DictDefaultEmptyStr(dict):
|
269
|
+
def __getitem__(self, key):
|
270
|
+
return dict.get(self, key, "")
|