Skip to content

Commit

Permalink
Split dbt into core and plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Dec 14, 2018
1 parent c61561a commit 4780c4b
Show file tree
Hide file tree
Showing 205 changed files with 1,722 additions and 1,241 deletions.
14 changes: 11 additions & 3 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.12.2rc1
current_version = 0.13.0a1
parse = (?P<major>\d+)
\.(?P<minor>\d+)
\.(?P<patch>\d+)
Expand All @@ -20,7 +20,15 @@ values =
[bumpversion:part:num]
first_value = 1

[bumpversion:file:setup.py]
[bumpversion:file:core/setup.py]

[bumpversion:file:dbt/version.py]
[bumpversion:file:core/dbt/version.py]

[bumpversion:file:plugins/postgres/setup.py]

[bumpversion:file:plugins/redshift/setup.py]

[bumpversion:file:plugins/snowflake/setup.py]

[bumpversion:file:plugins/bigquery/setup.py]

3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[report]
include =
dbt/*
core/dbt/*
plugins/adapters/dbt/*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions core/dbt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions core/dbt/adapters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from dbt.adapters.base.relation import BaseRelation
from dbt.adapters.base.connections import BaseConnectionManager, Credentials
from dbt.adapters.base.impl import BaseAdapter
from dbt.adapters.base.plugin import AdapterPlugin
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions core/dbt/adapters/base/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from dbt.config.project import Project


class AdapterPlugin(object):
"""Defines the basic requirements for a dbt adapter plugin.
:param type adapter: An adapter class, derived from BaseAdapter
:param type credentials: A credentials object, derived from Credentials
:param str project_name: The name of this adapter plugin's associated dbt
project.
:param str include_path: The path to this adapter plugin's root
:param Optional[List[str]] dependencies: A list of adapter names that this\
adapter depends upon.
"""
def __init__(self, adapter, credentials, include_path, dependencies=None):
self.adapter = adapter
self.credentials = credentials
self.include_path = include_path
project_path = os.path.join(self.include_path, adapter.type())
project = Project.from_project_root(project_path, {})
self.project_name = project.project_name
if dependencies is None:
dependencies = []
self.dependencies = dependencies
File renamed without changes.
File renamed without changes.
24 changes: 15 additions & 9 deletions dbt/adapters/factory.py → core/dbt/adapters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import dbt.exceptions
from importlib import import_module
from dbt.include.global_project import PACKAGES

import threading


ADAPTER_TYPES = {}

_ADAPTERS = {}
Expand All @@ -28,25 +28,31 @@ def get_relation_class_by_name(adapter_name):
return adapter.Relation


def load_adapter(adapter_name):
"""Load an adapter package with the class of adapter_name, put it in the
ADAPTER_TYPES dict, and return its associated Credentials
"""
def load_plugin(adapter_name):
try:
mod = import_module('.'+adapter_name, 'dbt.adapters')
except ImportError:
raise dbt.exceptions.RuntimeException(
"Could not find adapter type {}!".format(adapter_name)
)
if mod.Adapter.type() != adapter_name:
plugin = mod.Plugin

if plugin.adapter.type() != adapter_name:
raise dbt.exceptions.RuntimeException(
'Expected to find adapter with type named {}, got adapter with '
'type {}'
.format(adapter_name, mod.Adapter.type())
.format(adapter_name, plugin.adapter.type())
)

ADAPTER_TYPES[adapter_name] = mod.Adapter
return mod.Credentials
with _ADAPTER_LOCK:
ADAPTER_TYPES[adapter_name] = plugin.adapter

PACKAGES[plugin.project_name] = plugin.include_path

for dep in plugin.dependencies:
load_plugin(dep)

return plugin.credentials


def get_adapter(config):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions core/dbt/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

from .renderer import ConfigRenderer
from .profile import Profile, UserConfig
from .project import Project
from .profile import read_profile
from .profile import PROFILES_DIR
from .runtime import RuntimeConfig


def read_profiles(profiles_dir=None):
"""This is only used in main, for some error handling"""
if profiles_dir is None:
profiles_dir = PROFILES_DIR

raw_profiles = read_profile(profiles_dir)

if raw_profiles is None:
profiles = {}
else:
profiles = {k: v for (k, v) in raw_profiles.items() if k != 'config'}

return profiles
Loading

0 comments on commit 4780c4b

Please sign in to comment.