Skip to content

Commit

Permalink
init push
Browse files Browse the repository at this point in the history
  • Loading branch information
McKnight-42 committed Apr 13, 2022
0 parents commit d034217
Show file tree
Hide file tree
Showing 25 changed files with 740 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
select =
E
W
F
ignore =
W503 # makes Flake8 work like black
W504
E203 # makes Flake8 work like black
E741
E501
exclude = tests
Empty file added .github/workflows/.gitkeep
Empty file.
Empty file.
Empty file added .github/workflows/main.yml
Empty file.
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
53 changes: 53 additions & 0 deletions .pre-commit-configt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# For more on configuring pre-commit hooks (see https://pre-commit.com/)

# TODO: remove global exclusion of tests when testing overhaul is complete
exclude: '^tests/.*'

default_language_version:
python: python3.8

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-yaml
args: [--unsafe]
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args:
- "--line-length=99"
- "--target-version=py38"
- id: black
alias: black-check
stages: [manual]
args:
- "--line-length=99"
- "--target-version=py38"
- "--check"
- "--diff"
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
- id: flake8
alias: flake8-check
stages: [manual]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
hooks:
- id: mypy
args: [--show-error-codes, --ignore-missing-imports]
files: ^dbt/adapters/.*
language: system
- id: mypy
alias: mypy-check
stages: [manual]
args: [--show-error-codes, --pretty, --ignore-missing-imports]
files: ^dbt/adapters
language: system
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include dbt/include *.sql *.yml *.md
12 changes: 12 additions & 0 deletions dbt/adapters/testadapter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dbt.adapters.testadapter.connections import TestAdapterConnectionManager
from dbt.adapters.testadapter.connections import TestAdapterCredentials
from dbt.adapters.testadapter.impl import TestAdapterAdapter

from dbt.adapters.base import AdapterPlugin
from dbt.include import testadapter


Plugin = AdapterPlugin(
adapter=TestAdapterAdapter,
credentials=TestAdapterCredentials,
include_path=testadapter.PACKAGE_PATH)
1 change: 1 addition & 0 deletions dbt/adapters/testadapter/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = '1.0.0'
121 changes: 121 additions & 0 deletions dbt/adapters/testadapter/connections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
from contextlib import contextmanager
from dataclasses import dataclass
import dbt.exceptions
from dbt.adapters.base import Credentials
from dbt.adapters.sql import SQLConnectionManager
from dbt.logger import GLOBAL_LOGGER as logger

@dataclass
class TestAdapterCredentials(Credentials):
'''
Defines database specific credentials that get added to
profiles.yml to connect to new adapter
'''

# Add credentials members here, like:
# host: str
# port: int
# username: str
# password: str

_ALIASES = {
'dbname':'database',
'pass':'password',
'user':'username'
}

@property
def type(self):
'''Return name of adapter.'''
return 'testadapter'

@property
def unique_field(self):
"""
Hashed and included in anonymous telemetry to track adapter adoption.
Pick a field that can uniquely identify one team/organization building with this adapter
"""
return self.host

def _connection_keys(self):
"""
List of keys to display in the `dbt debug` output.
"""
return ('host','port','username','user')

class TestAdapterConnectionManager(SQLConnectionManager):
TYPE = 'testadapter'


@contextmanager
def exception_handler(self, sql: str):
'''
Returns a context manager, that will handle exceptions raised
from queries, catch, log, and raise dbt exceptions it knows how to handle.
'''
# ## Example ##
# try:
# yield
# except myadapter_library.DatabaseError as exc:
# self.release(connection_name)

# logger.debug('myadapter error: {}'.format(str(e)))
# raise dbt.exceptions.DatabaseException(str(exc))
# except Exception as exc:
# logger.debug("Error running SQL: {}".format(sql))
# logger.debug("Rolling back transaction.")
# self.release(connection_name)
# raise dbt.exceptions.RuntimeException(str(exc))
pass

@classmethod
def open(cls, connection):
'''
Receives a connection object and a Credentials object
and moves it to the 'open' state.
'''
# ## Example ##
# if connection.state == 'open':
# logger.debug('Connection is already open, skipping open.')
# return connection

# credentials = connection.credentials

# try:
# handle = myadapter_library.connect(
# host=credentials.host,
# port=credentials.port,
# username=credentials.username,
# password=credentials.password,
# catalog=credentials.database
# )
# connection.state = 'open'
# connection.handle = handle
# return connection
pass

@classmethod
def get_response(cls,cursor):
'''
Gets a cursor object and returns adapter-specific information
about the last executed command generally a AdapterResponse ojbect
that has items such as code, rows_affected,etc. can also just be a string ex. 'OK'
if your cursor does not offer rich metadata.
'''
# ## Example ##
# return cursor.status_message
pass

def cancel(self, connection):
'''
Gets a connection object and attempts to cancel any ongoing queries.
'''
# ## Example ##
# tid = connection.handle.transaction_id()
# sql = 'select cancel_transaction({})'.format(tid)
# logger.debug("Cancelling query '{}' ({})".format(connection_name, pid))
# _, cursor = self.add_query(sql, 'master')
# res = cursor.fetchone()
# logger.debug("Canceled query '{}': {}".format(connection_name, res))
pass

21 changes: 21 additions & 0 deletions dbt/adapters/testadapter/impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# adapter_src, and adapter_cls comes from kwargs in create.py
from dbt.adapters.sql import SQLAdapter
from dbt.adapters.testadapter import TestAdapterConnectionManager



class TestAdapterAdapter(SQLAdapter):
'''
Controls actual implmentation of adapter, and ability to override certain methods.
'''

ConnectionManager = TestAdapterConnectionManager

@classmethod
def date_function(cls):
'''
Returns canonical date func
'''
return 'datenow()'

# may require more build out to make more user friendly to confer with team and community.
2 changes: 2 additions & 0 deletions dbt/include/testadapter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import os
PACKAGE_PATH = os.path.dirname(__file__)
5 changes: 5 additions & 0 deletions dbt/include/testadapter/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: dbt_testadapter
version: 1.0.0
config-version: 2

macro-paths: ["macros"]
Loading

0 comments on commit d034217

Please sign in to comment.