Skip to content

Commit

Permalink
Add changie
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed May 29, 2024
1 parent 89b7256 commit 2bac23c
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 512 deletions.
6 changes: 0 additions & 6 deletions .changes/unreleased/Features-20240514-162052.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions .changes/unreleased/Features-20240515-161106.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240529-142737.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Move catalog artifact schema to dbt-common
time: 2024-05-29T14:27:37.302801+01:00
custom:
Author: aranke
Issue: "141"
2 changes: 1 addition & 1 deletion dbt_common/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.1.0"
version = "1.0.4"
10 changes: 5 additions & 5 deletions dbt_common/events/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
from google.protobuf.json_format import ParseDict, MessageToDict, MessageToJson
from google.protobuf.message import Message
from dbt_common.events.helpers import get_json_string_utcnow
from typing import Callable, Optional
from typing import Optional

from dbt_common.invocation import get_invocation_id

from typing import Protocol
if sys.version_info >= (3, 8):
from typing import Protocol
else:
from typing_extensions import Protocol


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down Expand Up @@ -125,9 +128,6 @@ class EventMsg(Protocol):
data: Message


TCallback = Callable[[EventMsg], None]


def msg_from_base_event(event: BaseEvent, level: Optional[EventLevel] = None):
msg_class_name = f"{type(event).__name__}Msg"
msg_cls = getattr(event.PROTO_TYPES_MODULE, msg_class_name)
Expand Down
14 changes: 4 additions & 10 deletions dbt_common/events/event_manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
import traceback
from typing import List, Optional, Protocol, Tuple
from typing import Callable, List, Optional, Protocol, Tuple

from dbt_common.events.base_types import BaseEvent, EventLevel, msg_from_base_event, TCallback
from dbt_common.events.base_types import BaseEvent, EventLevel, msg_from_base_event, EventMsg
from dbt_common.events.logger import LoggerConfig, _Logger, _TextLogger, _JsonLogger, LineFormat


class EventManager:
def __init__(self) -> None:
self.loggers: List[_Logger] = []
self.callbacks: List[TCallback] = []
self.callbacks: List[Callable[[EventMsg], None]] = []

def fire_event(self, e: BaseEvent, level: Optional[EventLevel] = None) -> None:
msg = msg_from_base_event(e, level=level)
Expand Down Expand Up @@ -37,16 +37,13 @@ def add_logger(self, config: LoggerConfig) -> None:
)
self.loggers.append(logger)

def add_callback(self, callback: TCallback) -> None:
self.callbacks.append(callback)

def flush(self) -> None:
for logger in self.loggers:
logger.flush()


class IEventManager(Protocol):
callbacks: List[TCallback]
callbacks: List[Callable[[EventMsg], None]]
loggers: List[_Logger]

def fire_event(self, e: BaseEvent, level: Optional[EventLevel] = None) -> None:
Expand All @@ -55,9 +52,6 @@ def fire_event(self, e: BaseEvent, level: Optional[EventLevel] = None) -> None:
def add_logger(self, config: LoggerConfig) -> None:
...

def add_callback(self, callback: TCallback) -> None:
...


class TestEventManager(IEventManager):
__test__ = False
Expand Down
6 changes: 0 additions & 6 deletions dbt_common/events/event_manager_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Since dbt-rpc does not do its own log setup, and since some events can
# currently fire before logs can be configured by setup_event_logger(), we
# create a default configuration with default settings and no file output.
from dbt_common.events.base_types import TCallback
from dbt_common.events.event_manager import IEventManager, EventManager

_EVENT_MANAGER: IEventManager = EventManager()
Expand All @@ -17,11 +16,6 @@ def add_logger_to_manager(logger) -> None:
_EVENT_MANAGER.add_logger(logger)


def add_callback_to_manager(callback: TCallback) -> None:
global _EVENT_MANAGER
_EVENT_MANAGER.add_callback(callback)


def ctx_set_event_manager(event_manager: IEventManager) -> None:
global _EVENT_MANAGER
_EVENT_MANAGER = event_manager
Expand Down
21 changes: 2 additions & 19 deletions dbt_common/events/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
from dbt_common.events.format import timestamp_to_datetime_string
from dbt_common.utils.encoding import ForgivingJSONEncoder

PRINT_EVENT_NAME = "PrintEvent"


def _is_print_event(msg: EventMsg) -> bool:
return msg.info.name == PRINT_EVENT_NAME


# A Filter is a function which takes a BaseEvent and returns True if the event
# should be logged, False otherwise.
Filter = Callable[[EventMsg], bool]
Expand Down Expand Up @@ -127,14 +120,7 @@ def create_line(self, msg: EventMsg) -> str:
def write_line(self, msg: EventMsg):
line = self.create_line(msg)
if self._python_logger is not None:
# We send PrintEvent to logger as error so it goes to stdout
# when --quiet flag is set.
# --quiet flag will filter out all events lower than ERROR.
if _is_print_event(msg):
level = "error"
else:
level = msg.info.level
send_to_logger(self._python_logger, level, line)
send_to_logger(self._python_logger, msg.info.level, line)

def flush(self):
if self._python_logger is not None:
Expand All @@ -152,11 +138,8 @@ def create_line(self, msg: EventMsg) -> str:
return self.create_debug_line(msg) if self.use_debug_format else self.create_info_line(msg)

def create_info_line(self, msg: EventMsg) -> str:
scrubbed_msg: str = self.scrubber(msg.info.msg) # type: ignore
if _is_print_event(msg):
# PrintEvent is a special case, we don't want to add a timestamp
return scrubbed_msg
ts: str = datetime.utcnow().strftime("%H:%M:%S")
scrubbed_msg: str = self.scrubber(msg.info.msg) # type: ignore
return f"{self._get_color_tag()}{ts} {scrubbed_msg}"

def create_debug_line(self, msg: EventMsg) -> str:
Expand Down
10 changes: 0 additions & 10 deletions dbt_common/events/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,3 @@ message NoteMsg {
EventInfo info = 1;
Note data = 2;
}

// Z052
message PrintEvent {
string msg = 1;
}

message PrintEventMsg {
EventInfo info = 1;
PrintEvent data = 2;
}
11 changes: 0 additions & 11 deletions dbt_common/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,3 @@ def code(self) -> str:

def message(self) -> str:
return self.msg


class PrintEvent(InfoLevel):
# Use this event to skip any formatting and just print a message
# This event will get to stdout even if the logger is set to ERROR
# This is to support commands that want --quiet option but also log something to stdout
def code(self) -> str:
return "Z052"

def message(self) -> str:
return self.msg
107 changes: 51 additions & 56 deletions dbt_common/events/types_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ lint = [
]
test = [
"pytest>=7.3,<8.0",
"pytest-mock",
"pytest-xdist>=3.2,<4.0",
"pytest-cov>=4.1,<5.0",
"hypothesis>=6.87,<7.0",
Expand Down
Empty file removed tests/__init__.py
Empty file.
Empty file removed tests/unit/__init__.py
Empty file.
40 changes: 0 additions & 40 deletions tests/unit/events/test_logger.py

This file was deleted.

11 changes: 0 additions & 11 deletions tests/unit/test_event_manager.py

This file was deleted.

Loading

0 comments on commit 2bac23c

Please sign in to comment.