Skip to content

Commit

Permalink
Fix some mypy issues
Browse files Browse the repository at this point in the history
Split up hooks to expose the hook dict
Remove some odd imports
  • Loading branch information
Jacob Beck committed Apr 20, 2020
1 parent 070e13d commit 72d82e4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
1 change: 0 additions & 1 deletion core/dbt/contracts/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass, field
from typing import (
Any, ClassVar, Dict, Tuple, Iterable, Optional, NewType, List, Callable,
TypeVar
)
from typing_extensions import Protocol

Expand Down
8 changes: 0 additions & 8 deletions core/dbt/hooks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from hologram.helpers import StrEnum
import json

from dbt.contracts.graph.parsed import Hook

from typing import Union, Dict, Any


Expand All @@ -21,9 +19,3 @@ def get_hook_dict(source: Union[str, Dict[str, Any]]) -> Dict[str, Any]:
return json.loads(source)
except ValueError:
return {'sql': source}


def get_hook(source, index):
hook_dict = get_hook_dict(source)
hook_dict.setdefault('index', index)
return Hook.from_dict(hook_dict)
10 changes: 7 additions & 3 deletions core/dbt/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ def default_schema(self):
def default_database(self):
return self.root_project.credentials.database

def get_fqn_prefix(self, path: str) -> List[str]:
no_ext = os.path.splitext(path)[0]
fqn = [self.project.project_name]
fqn.extend(dbt.utils.split_path(no_ext)[:-1])
return fqn

def get_fqn(self, path: str, name: str) -> List[str]:
"""Get the FQN for the node. This impacts node selection and config
application.
"""
no_ext = os.path.splitext(path)[0]
fqn = [self.project.project_name]
fqn.extend(dbt.utils.split_path(no_ext)[:-1])
fqn = self.get_fqn_prefix(path)
fqn.append(name)
return fqn

Expand Down
9 changes: 8 additions & 1 deletion core/dbt/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import dbt.exceptions
import dbt.flags
from dbt.hooks import get_hook
from dbt.hooks import get_hook_dict
from dbt.ui.printer import \
print_hook_start_line, \
print_hook_end_line, \
Expand All @@ -26,6 +26,7 @@

from dbt.compilation import compile_node
from dbt.contracts.graph.compiled import CompileResultNode
from dbt.contracts.graph.model_config import Hook
from dbt.contracts.graph.parsed import ParsedHookNode
from dbt.task.compile import CompileTask

Expand Down Expand Up @@ -76,6 +77,12 @@ def get_hooks_by_tags(
return matched_nodes


def get_hook(source, index):
hook_dict = get_hook_dict(source)
hook_dict.setdefault('index', index)
return Hook.from_dict(hook_dict)


class RunTask(CompileTask):
def __init__(self, args, config):
super().__init__(args, config)
Expand Down

0 comments on commit 72d82e4

Please sign in to comment.