From 5c9fd07050c45be3fec59b3748d7b2cd17c6cf7d Mon Sep 17 00:00:00 2001 From: Nathaniel May Date: Wed, 13 Oct 2021 16:05:54 -0400 Subject: [PATCH] init --- core/dbt/events/__init__.py | 0 core/dbt/events/events.py | 46 +++++++++++++++++++++++++++++++++++++ core/dbt/task/parse.py | 1 + 3 files changed, 47 insertions(+) create mode 100644 core/dbt/events/__init__.py create mode 100644 core/dbt/events/events.py diff --git a/core/dbt/events/__init__.py b/core/dbt/events/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/core/dbt/events/events.py b/core/dbt/events/events.py new file mode 100644 index 00000000000..0d4921e8ad6 --- /dev/null +++ b/core/dbt/events/events.py @@ -0,0 +1,46 @@ + +from typing import NamedTuple, NoReturn, Union + + +# common trick for getting mypy to do exhaustiveness checks +# will come up with something like `"assert_never" has incompatible type` +# if something is missing. +def assert_never(x: NoReturn) -> NoReturn: + raise AssertionError("Unhandled type: {}".format(type(x).__name__)) + +# The following classes represent the data necessary to describe a +# particular event to both human readable logs, and machine reliable +# event streams. The transformation to these forms will live in outside +# functions. +# +# Until we drop support for Python 3.6 we must use NamedTuples over +# frozen dataclasses. + +# TODO dummy class +class OK(NamedTuple): + result: int + + +# TODO dummy class +class Failure(NamedTuple): + msg: str + + +# using a union instead of inheritance means that this set cannot +# be extended outside this file, and thus mypy can do exhaustiveness +# checks for us. +Event = Union[OK, Failure] + + +# function that translates any instance of the above event types +# into its human-readable message. +# +# This could instead be implemented as a method on an ABC for all +# above classes, but this at least puts all that logic in one place. +def humanMsg(r: Event) -> str: + if isinstance(r, OK): + return str(r.result) + elif isinstance(r, Failure): + return "Failure: " + r.msg + else: + assert_never(r) diff --git a/core/dbt/task/parse.py b/core/dbt/task/parse.py index 985db062093..6f68df53b68 100644 --- a/core/dbt/task/parse.py +++ b/core/dbt/task/parse.py @@ -81,6 +81,7 @@ def compile_manifest(self): self.graph = compiler.compile(self.manifest) def run(self): + events.register(Progress(ParseStart)) print_timestamped_line('Start parsing.') self.get_full_manifest() if self.args.compile: