Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commit hook tooling. #346

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = test
26 changes: 9 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,10 @@ defaults:

jobs:
code-quality:
name: ${{ matrix.toxenv }}
name: code-quality

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
toxenv: [flake8]

env:
TOXENV: ${{ matrix.toxenv }}
PYTEST_ADDOPTS: "-v --color=yes"

steps:
- name: Check out the repository
uses: actions/checkout@v2
Expand All @@ -58,18 +49,19 @@ jobs:

- name: Set up Python
uses: actions/setup-python@v2
with:
with:
python-version: '3.8'

- name: Install python dependencies
run: |
sudo apt-get install libsasl2-dev
pip install --user --upgrade pip
pip install tox
pip --version
tox --version
- name: Run tox
run: tox
pip install -r dev_requirements.txt
pre-commit --version
mypy --version
dbt --version
- name: pre-commit hooks
run: pre-commit run --all-files --show-diff-on-failure

unit:
name: unit test / python ${{ matrix.python-version }}
Expand Down Expand Up @@ -153,7 +145,7 @@ jobs:
- name: Check wheel contents
run: |
check-wheel-contents dist/*.whl --ignore W007,W008

- name: Check if this is an alpha version
id: check-is-alpha
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ jobs:
stale-pr-message: "This PR has been marked as Stale because it has been open for 180 days with no activity. If you would like the PR to remain open, please remove the stale label or comment on the PR, or it will be closed in 7 days."
# mark issues/PRs stale when they haven't seen activity in 180 days
days-before-stale: 180
# ignore checking issues with the following labels
exempt-issue-labels: "epic, discussion"
53 changes: 41 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
.hive-metastore/
.spark-warehouse/
*.egg-info
env/
*.pyc
# Byte-compiled / optimized / DLL files
__pycache__
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build/
env*/
dbt_env/
dist/
*.egg-info
logs/


# Unit test
.tox/
.env
test.env


# Django stuff
*.log

# Mypy
*.pytest_cache/

# Vim
*.sw*

# Pyenv
.python-version

# pycharm
.idea/
build/
dist/
dbt-integration-tests
test/integration/.user.yml

# MacOS
.DS_Store
test.env

# vscode
.vscode
*.log
logs/

# other
.hive-metastore/
.spark-warehouse/
dbt-integration-tests
test/integration/.user.yml
66 changes: 66 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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/.*'

# Force all unspecified python hooks to run python 3.8
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: 21.12b0
hooks:
- id: black
additional_dependencies: ['click==8.0.4']
args:
- "--line-length=99"
- "--target-version=py38"
- id: black
alias: black-check
stages: [manual]
additional_dependencies: ['click==8.0.4']
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
VersusFacit marked this conversation as resolved.
Show resolved Hide resolved
hooks:
- id: mypy
# N.B.: Mypy is... a bit fragile.
#
# By using `language: system` we run this hook in the local
# environment instead of a pre-commit isolated one. This is needed
# to ensure mypy correctly parses the project.

# It may cause trouble in that it adds environmental variables out
# of our control to the mix. Unfortunately, there's nothing we can
# do about per pre-commit's author.
# See https://github.com/pre-commit/pre-commit/issues/730 for details.
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
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.DEFAULT_GOAL:=help

.PHONY: dev
dev: ## Installs adapter in develop mode along with development depedencies
@\
pip install -r dev_requirements.txt && pre-commit install

.PHONY: mypy
mypy: ## Runs mypy against staged changes for static type checking.
@\
pre-commit run --hook-stage manual mypy-check | grep -v "INFO"

.PHONY: flake8
flake8: ## Runs flake8 against staged changes to enforce style guide.
@\
pre-commit run --hook-stage manual flake8-check | grep -v "INFO"

.PHONY: black
black: ## Runs black against staged changes to enforce style guide.
@\
pre-commit run --hook-stage manual black-check -v | grep -v "INFO"

.PHONY: lint
lint: ## Runs flake8 and mypy code checks against staged changes.
@\
pre-commit run flake8-check --hook-stage manual | grep -v "INFO"; \
pre-commit run mypy-check --hook-stage manual | grep -v "INFO"

.PHONY: linecheck
linecheck: ## Checks for all Python lines 100 characters or more
@\
find dbt -type f -name "*.py" -exec grep -I -r -n '.\{100\}' {} \;

.PHONY: unit
unit: ## Runs unit tests with py38.
@\
tox -e py38

.PHONY: test
test: ## Runs unit tests with py38 and code checks against staged changes.
@\
tox -p -e py38; \
pre-commit run black-check --hook-stage manual | grep -v "INFO"; \
pre-commit run flake8-check --hook-stage manual | grep -v "INFO"; \
pre-commit run mypy-check --hook-stage manual | grep -v "INFO"

.PHONY: integration
integration: ## Runs snowflake integration tests with py38.
VersusFacit marked this conversation as resolved.
Show resolved Hide resolved
@\
tox -e py38-snowflake --

.PHONY: clean
@echo "cleaning repo"
@git clean -f -X

.PHONY: help
help: ## Show this help message.
@echo 'usage: make [target]'
@echo
@echo 'targets:'
@grep -E '^[7+a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
20 changes: 12 additions & 8 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter

black==21.12b0
VersusFacit marked this conversation as resolved.
Show resolved Hide resolved
bumpversion
click~=8.0.4
flake8
flaky
freezegun==0.3.9
pytest>=6.0.2
ipdb
mock>=1.3.0
flake8
mypy==0.782
pre-commit
pytest-csv
pytest-dotenv
pytest-xdist
pytest>=6.0.2
pytz
bumpversion
tox>=3.2.0
ipdb
pytest-xdist
pytest-dotenv
pytest-csv
flaky

# Test requirements
sasl>=0.2.1
Expand Down
8 changes: 0 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
skipsdist = True
envlist = unit, flake8, integration-spark-thrift


[testenv:flake8]
basepython = python3.8
commands = /bin/bash -c '$(which flake8) --max-line-length 99 --select=E,W,F --ignore=W504 dbt/'
passenv = DBT_* PYTEST_ADDOPTS
deps =
-r{toxinidir}/dev_requirements.txt

[testenv:unit]
basepython = python3.8
commands = /bin/bash -c '{envpython} -m pytest -v {posargs} tests/unit'
Expand Down