Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel May committed Oct 26, 2021
1 parent c019a94 commit 5c9fd07
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Empty file added core/dbt/events/__init__.py
Empty file.
46 changes: 46 additions & 0 deletions core/dbt/events/events.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions core/dbt/task/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5c9fd07

Please sign in to comment.