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.
- dvt/__init__.py +7 -0
- dvt/_pydantic_shim.py +26 -0
- dvt/adapters/__init__.py +16 -0
- dvt/adapters/multi_adapter_manager.py +268 -0
- dvt/artifacts/__init__.py +0 -0
- dvt/artifacts/exceptions/__init__.py +1 -0
- dvt/artifacts/exceptions/schemas.py +31 -0
- dvt/artifacts/resources/__init__.py +116 -0
- dvt/artifacts/resources/base.py +68 -0
- dvt/artifacts/resources/types.py +93 -0
- dvt/artifacts/resources/v1/analysis.py +10 -0
- dvt/artifacts/resources/v1/catalog.py +23 -0
- dvt/artifacts/resources/v1/components.py +275 -0
- dvt/artifacts/resources/v1/config.py +282 -0
- dvt/artifacts/resources/v1/documentation.py +11 -0
- dvt/artifacts/resources/v1/exposure.py +52 -0
- dvt/artifacts/resources/v1/function.py +53 -0
- dvt/artifacts/resources/v1/generic_test.py +32 -0
- dvt/artifacts/resources/v1/group.py +22 -0
- dvt/artifacts/resources/v1/hook.py +11 -0
- dvt/artifacts/resources/v1/macro.py +30 -0
- dvt/artifacts/resources/v1/metric.py +173 -0
- dvt/artifacts/resources/v1/model.py +146 -0
- dvt/artifacts/resources/v1/owner.py +10 -0
- dvt/artifacts/resources/v1/saved_query.py +112 -0
- dvt/artifacts/resources/v1/seed.py +42 -0
- dvt/artifacts/resources/v1/semantic_layer_components.py +72 -0
- dvt/artifacts/resources/v1/semantic_model.py +315 -0
- dvt/artifacts/resources/v1/singular_test.py +14 -0
- dvt/artifacts/resources/v1/snapshot.py +92 -0
- dvt/artifacts/resources/v1/source_definition.py +85 -0
- dvt/artifacts/resources/v1/sql_operation.py +10 -0
- dvt/artifacts/resources/v1/unit_test_definition.py +78 -0
- dvt/artifacts/schemas/__init__.py +0 -0
- dvt/artifacts/schemas/base.py +191 -0
- dvt/artifacts/schemas/batch_results.py +24 -0
- dvt/artifacts/schemas/catalog/__init__.py +12 -0
- dvt/artifacts/schemas/catalog/v1/__init__.py +0 -0
- dvt/artifacts/schemas/catalog/v1/catalog.py +60 -0
- dvt/artifacts/schemas/freshness/__init__.py +1 -0
- dvt/artifacts/schemas/freshness/v3/__init__.py +0 -0
- dvt/artifacts/schemas/freshness/v3/freshness.py +159 -0
- dvt/artifacts/schemas/manifest/__init__.py +2 -0
- dvt/artifacts/schemas/manifest/v12/__init__.py +0 -0
- dvt/artifacts/schemas/manifest/v12/manifest.py +212 -0
- dvt/artifacts/schemas/results.py +148 -0
- dvt/artifacts/schemas/run/__init__.py +2 -0
- dvt/artifacts/schemas/run/v5/__init__.py +0 -0
- dvt/artifacts/schemas/run/v5/run.py +184 -0
- dvt/artifacts/schemas/upgrades/__init__.py +4 -0
- dvt/artifacts/schemas/upgrades/upgrade_manifest.py +174 -0
- dvt/artifacts/schemas/upgrades/upgrade_manifest_dbt_version.py +2 -0
- dvt/artifacts/utils/validation.py +153 -0
- dvt/cli/__init__.py +1 -0
- dvt/cli/context.py +16 -0
- dvt/cli/exceptions.py +56 -0
- dvt/cli/flags.py +558 -0
- dvt/cli/main.py +971 -0
- dvt/cli/option_types.py +121 -0
- dvt/cli/options.py +79 -0
- dvt/cli/params.py +803 -0
- dvt/cli/requires.py +478 -0
- dvt/cli/resolvers.py +32 -0
- dvt/cli/types.py +40 -0
- dvt/clients/__init__.py +0 -0
- dvt/clients/checked_load.py +82 -0
- dvt/clients/git.py +164 -0
- dvt/clients/jinja.py +206 -0
- dvt/clients/jinja_static.py +245 -0
- dvt/clients/registry.py +192 -0
- dvt/clients/yaml_helper.py +68 -0
- dvt/compilation.py +833 -0
- dvt/compute/__init__.py +26 -0
- dvt/compute/base.py +288 -0
- dvt/compute/engines/__init__.py +13 -0
- dvt/compute/engines/duckdb_engine.py +368 -0
- dvt/compute/engines/spark_engine.py +273 -0
- dvt/compute/query_analyzer.py +212 -0
- dvt/compute/router.py +483 -0
- dvt/config/__init__.py +4 -0
- dvt/config/catalogs.py +95 -0
- dvt/config/compute_config.py +406 -0
- dvt/config/profile.py +411 -0
- dvt/config/profiles_v2.py +464 -0
- dvt/config/project.py +893 -0
- dvt/config/renderer.py +232 -0
- dvt/config/runtime.py +491 -0
- dvt/config/selectors.py +209 -0
- dvt/config/utils.py +78 -0
- dvt/connectors/.gitignore +6 -0
- dvt/connectors/README.md +306 -0
- dvt/connectors/catalog.yml +217 -0
- dvt/connectors/download_connectors.py +300 -0
- dvt/constants.py +29 -0
- dvt/context/__init__.py +0 -0
- dvt/context/base.py +746 -0
- dvt/context/configured.py +136 -0
- dvt/context/context_config.py +350 -0
- dvt/context/docs.py +82 -0
- dvt/context/exceptions_jinja.py +179 -0
- dvt/context/macro_resolver.py +195 -0
- dvt/context/macros.py +171 -0
- dvt/context/manifest.py +73 -0
- dvt/context/providers.py +2198 -0
- dvt/context/query_header.py +14 -0
- dvt/context/secret.py +59 -0
- dvt/context/target.py +74 -0
- dvt/contracts/__init__.py +0 -0
- dvt/contracts/files.py +413 -0
- dvt/contracts/graph/__init__.py +0 -0
- dvt/contracts/graph/manifest.py +1904 -0
- dvt/contracts/graph/metrics.py +98 -0
- dvt/contracts/graph/model_config.py +71 -0
- dvt/contracts/graph/node_args.py +42 -0
- dvt/contracts/graph/nodes.py +1806 -0
- dvt/contracts/graph/semantic_manifest.py +233 -0
- dvt/contracts/graph/unparsed.py +812 -0
- dvt/contracts/project.py +417 -0
- dvt/contracts/results.py +53 -0
- dvt/contracts/selection.py +23 -0
- dvt/contracts/sql.py +86 -0
- dvt/contracts/state.py +69 -0
- dvt/contracts/util.py +46 -0
- dvt/deprecations.py +347 -0
- dvt/deps/__init__.py +0 -0
- dvt/deps/base.py +153 -0
- dvt/deps/git.py +196 -0
- dvt/deps/local.py +80 -0
- dvt/deps/registry.py +131 -0
- dvt/deps/resolver.py +149 -0
- dvt/deps/tarball.py +121 -0
- dvt/docs/source/_ext/dbt_click.py +118 -0
- dvt/docs/source/conf.py +32 -0
- dvt/env_vars.py +64 -0
- dvt/event_time/event_time.py +40 -0
- dvt/event_time/sample_window.py +60 -0
- dvt/events/__init__.py +16 -0
- dvt/events/base_types.py +37 -0
- dvt/events/core_types_pb2.py +2 -0
- dvt/events/logging.py +109 -0
- dvt/events/types.py +2534 -0
- dvt/exceptions.py +1487 -0
- dvt/flags.py +89 -0
- dvt/graph/__init__.py +11 -0
- dvt/graph/cli.py +248 -0
- dvt/graph/graph.py +172 -0
- dvt/graph/queue.py +213 -0
- dvt/graph/selector.py +375 -0
- dvt/graph/selector_methods.py +976 -0
- dvt/graph/selector_spec.py +223 -0
- dvt/graph/thread_pool.py +18 -0
- dvt/hooks.py +21 -0
- dvt/include/README.md +49 -0
- dvt/include/__init__.py +3 -0
- dvt/include/global_project.py +4 -0
- dvt/include/starter_project/.gitignore +4 -0
- dvt/include/starter_project/README.md +15 -0
- dvt/include/starter_project/__init__.py +3 -0
- dvt/include/starter_project/analyses/.gitkeep +0 -0
- dvt/include/starter_project/dvt_project.yml +36 -0
- dvt/include/starter_project/macros/.gitkeep +0 -0
- dvt/include/starter_project/models/example/my_first_dbt_model.sql +27 -0
- dvt/include/starter_project/models/example/my_second_dbt_model.sql +6 -0
- dvt/include/starter_project/models/example/schema.yml +21 -0
- dvt/include/starter_project/seeds/.gitkeep +0 -0
- dvt/include/starter_project/snapshots/.gitkeep +0 -0
- dvt/include/starter_project/tests/.gitkeep +0 -0
- dvt/internal_deprecations.py +27 -0
- dvt/jsonschemas/__init__.py +3 -0
- dvt/jsonschemas/jsonschemas.py +309 -0
- dvt/jsonschemas/project/0.0.110.json +4717 -0
- dvt/jsonschemas/project/0.0.85.json +2015 -0
- dvt/jsonschemas/resources/0.0.110.json +2636 -0
- dvt/jsonschemas/resources/0.0.85.json +2536 -0
- dvt/jsonschemas/resources/latest.json +6773 -0
- dvt/links.py +4 -0
- dvt/materializations/__init__.py +0 -0
- dvt/materializations/incremental/__init__.py +0 -0
- dvt/materializations/incremental/microbatch.py +235 -0
- dvt/mp_context.py +8 -0
- dvt/node_types.py +37 -0
- dvt/parser/__init__.py +23 -0
- dvt/parser/analysis.py +21 -0
- dvt/parser/base.py +549 -0
- dvt/parser/common.py +267 -0
- dvt/parser/docs.py +52 -0
- dvt/parser/fixtures.py +51 -0
- dvt/parser/functions.py +30 -0
- dvt/parser/generic_test.py +100 -0
- dvt/parser/generic_test_builders.py +334 -0
- dvt/parser/hooks.py +119 -0
- dvt/parser/macros.py +137 -0
- dvt/parser/manifest.py +2204 -0
- dvt/parser/models.py +574 -0
- dvt/parser/partial.py +1179 -0
- dvt/parser/read_files.py +445 -0
- dvt/parser/schema_generic_tests.py +423 -0
- dvt/parser/schema_renderer.py +111 -0
- dvt/parser/schema_yaml_readers.py +936 -0
- dvt/parser/schemas.py +1467 -0
- dvt/parser/search.py +149 -0
- dvt/parser/seeds.py +28 -0
- dvt/parser/singular_test.py +20 -0
- dvt/parser/snapshots.py +44 -0
- dvt/parser/sources.py +557 -0
- dvt/parser/sql.py +63 -0
- dvt/parser/unit_tests.py +622 -0
- dvt/plugins/__init__.py +20 -0
- dvt/plugins/contracts.py +10 -0
- dvt/plugins/exceptions.py +2 -0
- dvt/plugins/manager.py +164 -0
- dvt/plugins/manifest.py +21 -0
- dvt/profiler.py +20 -0
- dvt/py.typed +1 -0
- dvt/runners/__init__.py +2 -0
- dvt/runners/exposure_runner.py +7 -0
- dvt/runners/no_op_runner.py +46 -0
- dvt/runners/saved_query_runner.py +7 -0
- dvt/selected_resources.py +8 -0
- dvt/task/__init__.py +0 -0
- dvt/task/base.py +504 -0
- dvt/task/build.py +197 -0
- dvt/task/clean.py +57 -0
- dvt/task/clone.py +162 -0
- dvt/task/compile.py +151 -0
- dvt/task/compute.py +366 -0
- dvt/task/debug.py +650 -0
- dvt/task/deps.py +280 -0
- dvt/task/docs/__init__.py +3 -0
- dvt/task/docs/generate.py +408 -0
- dvt/task/docs/index.html +250 -0
- dvt/task/docs/serve.py +28 -0
- dvt/task/freshness.py +323 -0
- dvt/task/function.py +122 -0
- dvt/task/group_lookup.py +46 -0
- dvt/task/init.py +374 -0
- dvt/task/list.py +237 -0
- dvt/task/printer.py +176 -0
- dvt/task/profiles.py +256 -0
- dvt/task/retry.py +175 -0
- dvt/task/run.py +1146 -0
- dvt/task/run_operation.py +142 -0
- dvt/task/runnable.py +802 -0
- dvt/task/seed.py +104 -0
- dvt/task/show.py +150 -0
- dvt/task/snapshot.py +57 -0
- dvt/task/sql.py +111 -0
- dvt/task/test.py +464 -0
- dvt/tests/fixtures/__init__.py +1 -0
- dvt/tests/fixtures/project.py +620 -0
- dvt/tests/util.py +651 -0
- dvt/tracking.py +529 -0
- dvt/utils/__init__.py +3 -0
- dvt/utils/artifact_upload.py +151 -0
- dvt/utils/utils.py +408 -0
- dvt/version.py +249 -0
- dvt_core-1.11.0b4.dist-info/METADATA +252 -0
- dvt_core-1.11.0b4.dist-info/RECORD +261 -0
- dvt_core-1.11.0b4.dist-info/WHEEL +5 -0
- dvt_core-1.11.0b4.dist-info/entry_points.txt +2 -0
- dvt_core-1.11.0b4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
from dateutil.relativedelta import relativedelta
|
|
4
|
+
from dvt.artifacts.resources.types import BatchSize
|
|
5
|
+
|
|
6
|
+
from dbt_common.exceptions import DbtRuntimeError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def offset_timestamp(timestamp=datetime, batch_size=BatchSize, offset=int) -> datetime:
|
|
10
|
+
"""Offsets the passed in timestamp based on the batch_size and offset.
|
|
11
|
+
|
|
12
|
+
Note: THIS IS DIFFERENT FROM MicrobatchBuilder.offset_timestamp. That function first
|
|
13
|
+
`truncates` the timestamp, and then does delta addition subtraction from there. This
|
|
14
|
+
function _doesn't_ truncate the timestamp and uses `relativedelta` for specific edge
|
|
15
|
+
case handling (months, years), which may produce different results than the delta math
|
|
16
|
+
done in `MicrobatchBuilder.offset_timestamp`
|
|
17
|
+
|
|
18
|
+
Examples
|
|
19
|
+
2024-09-17 16:06:00 + Batchsize.hour -1 -> 2024-09-17 15:06:00
|
|
20
|
+
2024-09-17 16:06:00 + Batchsize.hour +1 -> 2024-09-17 17:06:00
|
|
21
|
+
2024-09-17 16:06:00 + Batchsize.day -1 -> 2024-09-16 16:06:00
|
|
22
|
+
2024-09-17 16:06:00 + Batchsize.day +1 -> 2024-09-18 16:06:00
|
|
23
|
+
2024-09-17 16:06:00 + Batchsize.month -1 -> 2024-08-17 16:06:00
|
|
24
|
+
2024-09-17 16:06:00 + Batchsize.month +1 -> 2024-10-17 16:06:00
|
|
25
|
+
2024-09-17 16:06:00 + Batchsize.year -1 -> 2023-09-17 16:06:00
|
|
26
|
+
2024-09-17 16:06:00 + Batchsize.year +1 -> 2025-09-17 16:06:00
|
|
27
|
+
2024-01-31 16:06:00 + Batchsize.month +1 -> 2024-02-29 16:06:00
|
|
28
|
+
2024-02-29 16:06:00 + Batchsize.year +1 -> 2025-02-28 16:06:00
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
if batch_size == BatchSize.hour:
|
|
32
|
+
return timestamp + relativedelta(hours=offset)
|
|
33
|
+
elif batch_size == BatchSize.day:
|
|
34
|
+
return timestamp + relativedelta(days=offset)
|
|
35
|
+
elif batch_size == BatchSize.month:
|
|
36
|
+
return timestamp + relativedelta(months=offset)
|
|
37
|
+
elif batch_size == BatchSize.year:
|
|
38
|
+
return timestamp + relativedelta(years=offset)
|
|
39
|
+
else:
|
|
40
|
+
raise DbtRuntimeError(f"Unhandled batch_size '{batch_size}'")
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
import pytz
|
|
6
|
+
from attr import dataclass
|
|
7
|
+
from dvt.artifacts.resources.types import BatchSize
|
|
8
|
+
from dvt.event_time.event_time import offset_timestamp
|
|
9
|
+
|
|
10
|
+
from dbt_common.dataclass_schema import dbtClassMixin
|
|
11
|
+
from dbt_common.exceptions import DbtRuntimeError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class SampleWindow(dbtClassMixin):
|
|
16
|
+
start: datetime
|
|
17
|
+
end: datetime
|
|
18
|
+
|
|
19
|
+
def __post_serialize__(self, data, context):
|
|
20
|
+
# This is insane, but necessary, I apologize. Mashumaro handles the
|
|
21
|
+
# dictification of this class via a compile time generated `to_dict`
|
|
22
|
+
# method based off of the _typing_ of th class. By default `datetime`
|
|
23
|
+
# types are converted to strings. We don't want that, we want them to
|
|
24
|
+
# stay datetimes.
|
|
25
|
+
# Note: This is safe because the `SampleWindow` isn't part of the artifact
|
|
26
|
+
# and thus doesn't get written out.
|
|
27
|
+
new_data = super().__post_serialize__(data, context)
|
|
28
|
+
new_data["start"] = self.start
|
|
29
|
+
new_data["end"] = self.end
|
|
30
|
+
return new_data
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def from_relative_string(cls, relative_string: str) -> SampleWindow:
|
|
34
|
+
end = datetime.now(tz=pytz.UTC)
|
|
35
|
+
|
|
36
|
+
relative_window = relative_string.split(" ")
|
|
37
|
+
if len(relative_window) != 2:
|
|
38
|
+
raise DbtRuntimeError(
|
|
39
|
+
f"Cannot load SAMPLE_WINDOW from '{relative_string}'. Must be of form 'DAYS_INT GRAIN_SIZE'."
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
lookback = int(relative_window[0])
|
|
44
|
+
except Exception:
|
|
45
|
+
raise DbtRuntimeError(f"Unable to convert '{relative_window[0]}' to an integer.")
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
batch_size_string = relative_window[1].lower().rstrip("s")
|
|
49
|
+
batch_size = BatchSize[batch_size_string]
|
|
50
|
+
except Exception:
|
|
51
|
+
grains = [size.value for size in BatchSize]
|
|
52
|
+
grain_plurals = [BatchSize.plural(size) for size in BatchSize]
|
|
53
|
+
valid_grains = grains + grain_plurals
|
|
54
|
+
raise DbtRuntimeError(
|
|
55
|
+
f"Invalid grain size '{relative_window[1]}'. Must be one of {valid_grains}."
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
start = offset_timestamp(timestamp=end, batch_size=batch_size, offset=-1 * lookback)
|
|
59
|
+
|
|
60
|
+
return cls(start=start, end=end)
|
dvt/events/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Any, Dict, Set
|
|
2
|
+
|
|
3
|
+
import dvt.events.types as core_dbt_event_types
|
|
4
|
+
|
|
5
|
+
import dbt.adapters.events.types as adapter_dbt_event_types
|
|
6
|
+
import dbt_common.events.types as dbt_event_types
|
|
7
|
+
|
|
8
|
+
ALL_EVENT_TYPES: Dict[str, Any] = {
|
|
9
|
+
**dbt_event_types.__dict__,
|
|
10
|
+
**core_dbt_event_types.__dict__,
|
|
11
|
+
**adapter_dbt_event_types.__dict__,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
ALL_EVENT_NAMES: Set[str] = set(
|
|
15
|
+
[name for name, cls in ALL_EVENT_TYPES.items() if isinstance(cls, type)]
|
|
16
|
+
)
|
dvt/events/base_types.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from dvt.events import core_types_pb2
|
|
2
|
+
|
|
3
|
+
from dbt_common.events.base_types import BaseEvent
|
|
4
|
+
from dbt_common.events.base_types import DebugLevel as CommonDebugLevel
|
|
5
|
+
from dbt_common.events.base_types import DynamicLevel as CommonDyanicLevel
|
|
6
|
+
from dbt_common.events.base_types import ErrorLevel as CommonErrorLevel
|
|
7
|
+
from dbt_common.events.base_types import InfoLevel as CommonInfoLevel
|
|
8
|
+
from dbt_common.events.base_types import TestLevel as CommonTestLevel
|
|
9
|
+
from dbt_common.events.base_types import WarnLevel as CommonWarnLevel
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CoreBaseEvent(BaseEvent):
|
|
13
|
+
PROTO_TYPES_MODULE = core_types_pb2
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DynamicLevel(CommonDyanicLevel, CoreBaseEvent):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestLevel(CommonTestLevel, CoreBaseEvent):
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DebugLevel(CommonDebugLevel, CoreBaseEvent):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class InfoLevel(CommonInfoLevel, CoreBaseEvent):
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class WarnLevel(CommonWarnLevel, CoreBaseEvent):
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ErrorLevel(CommonErrorLevel, CoreBaseEvent):
|
|
37
|
+
pass
|
dvt/events/logging.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from functools import partial
|
|
3
|
+
from typing import Callable, List
|
|
4
|
+
|
|
5
|
+
from dvt.tracking import track_behavior_change_warn
|
|
6
|
+
|
|
7
|
+
from dbt_common.events.base_types import EventLevel, EventMsg
|
|
8
|
+
from dbt_common.events.event_manager_client import (
|
|
9
|
+
add_callback_to_manager,
|
|
10
|
+
add_logger_to_manager,
|
|
11
|
+
cleanup_event_logger,
|
|
12
|
+
get_event_manager,
|
|
13
|
+
)
|
|
14
|
+
from dbt_common.events.functions import (
|
|
15
|
+
env_scrubber,
|
|
16
|
+
get_capture_stream,
|
|
17
|
+
get_stdout_config,
|
|
18
|
+
make_log_dir_if_missing,
|
|
19
|
+
)
|
|
20
|
+
from dbt_common.events.logger import LineFormat, LoggerConfig
|
|
21
|
+
from dbt_common.invocation import get_invocation_id
|
|
22
|
+
|
|
23
|
+
# These are the logging events issued by the "clean" command,
|
|
24
|
+
# where we can't count on having a log directory. We've removed
|
|
25
|
+
# the "class" flags on the events in types.py. If necessary we
|
|
26
|
+
# could still use class or method flags, but we'd have to get
|
|
27
|
+
# the type class from the msg and then get the information from the class.
|
|
28
|
+
_NOFILE_CODES = ["Z012", "Z013", "Z014", "Z015"]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _line_format_from_str(format_str: str, default: LineFormat) -> LineFormat:
|
|
32
|
+
if format_str == "text":
|
|
33
|
+
return LineFormat.PlainText
|
|
34
|
+
elif format_str == "debug":
|
|
35
|
+
return LineFormat.DebugText
|
|
36
|
+
elif format_str == "json":
|
|
37
|
+
return LineFormat.Json
|
|
38
|
+
|
|
39
|
+
return default
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _get_logfile_config(
|
|
43
|
+
log_path: str,
|
|
44
|
+
use_colors: bool,
|
|
45
|
+
line_format: LineFormat,
|
|
46
|
+
level: EventLevel,
|
|
47
|
+
log_file_max_bytes: int,
|
|
48
|
+
log_cache_events: bool = False,
|
|
49
|
+
) -> LoggerConfig:
|
|
50
|
+
return LoggerConfig(
|
|
51
|
+
name="file_log",
|
|
52
|
+
line_format=line_format,
|
|
53
|
+
use_colors=use_colors,
|
|
54
|
+
level=level, # File log is *always* debug level
|
|
55
|
+
scrubber=env_scrubber,
|
|
56
|
+
filter=partial(_logfile_filter, log_cache_events, line_format),
|
|
57
|
+
invocation_id=get_invocation_id(),
|
|
58
|
+
output_file_name=log_path,
|
|
59
|
+
output_file_max_bytes=log_file_max_bytes,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _logfile_filter(log_cache_events: bool, line_format: LineFormat, msg: EventMsg) -> bool:
|
|
64
|
+
return msg.info.code not in _NOFILE_CODES and not (
|
|
65
|
+
msg.info.name in ["CacheAction", "CacheDumpGraph"] and not log_cache_events
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def setup_event_logger(flags, callbacks: List[Callable[[EventMsg], None]] = []) -> None:
|
|
70
|
+
cleanup_event_logger()
|
|
71
|
+
make_log_dir_if_missing(flags.LOG_PATH)
|
|
72
|
+
event_manager = get_event_manager()
|
|
73
|
+
event_manager.callbacks = callbacks.copy()
|
|
74
|
+
add_callback_to_manager(track_behavior_change_warn)
|
|
75
|
+
|
|
76
|
+
if flags.LOG_LEVEL != "none":
|
|
77
|
+
line_format = _line_format_from_str(flags.LOG_FORMAT, LineFormat.PlainText)
|
|
78
|
+
log_level = (
|
|
79
|
+
EventLevel.ERROR
|
|
80
|
+
if flags.QUIET
|
|
81
|
+
else EventLevel.DEBUG if flags.DEBUG else EventLevel(flags.LOG_LEVEL)
|
|
82
|
+
)
|
|
83
|
+
console_config = get_stdout_config(
|
|
84
|
+
line_format,
|
|
85
|
+
flags.USE_COLORS,
|
|
86
|
+
log_level,
|
|
87
|
+
flags.LOG_CACHE_EVENTS,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if get_capture_stream():
|
|
91
|
+
# Create second stdout logger to support test which want to know what's
|
|
92
|
+
# being sent to stdout.
|
|
93
|
+
console_config.output_stream = get_capture_stream()
|
|
94
|
+
add_logger_to_manager(console_config)
|
|
95
|
+
|
|
96
|
+
if flags.LOG_LEVEL_FILE != "none":
|
|
97
|
+
# create and add the file logger to the event manager
|
|
98
|
+
log_file = os.path.join(flags.LOG_PATH, "dbt.log")
|
|
99
|
+
log_file_format = _line_format_from_str(flags.LOG_FORMAT_FILE, LineFormat.DebugText)
|
|
100
|
+
log_level_file = EventLevel.DEBUG if flags.DEBUG else EventLevel(flags.LOG_LEVEL_FILE)
|
|
101
|
+
add_logger_to_manager(
|
|
102
|
+
_get_logfile_config(
|
|
103
|
+
log_file,
|
|
104
|
+
flags.USE_COLORS_FILE,
|
|
105
|
+
log_file_format,
|
|
106
|
+
log_level_file,
|
|
107
|
+
flags.LOG_FILE_MAX_BYTES,
|
|
108
|
+
)
|
|
109
|
+
)
|