From 311b24b4b39bc1e8feebbbd81ac555553ad816fa Mon Sep 17 00:00:00 2001 From: Nitesh Yadav Date: Thu, 4 May 2023 17:20:12 -0700 Subject: [PATCH] DBT-693: Pre-commit checks for code quality and syntax, with python 3.7 support --- .pre-commit-config.yaml | 61 +++++++++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 6 ++++ README.md | 2 +- dev-requirements.txt | 2 ++ setup.py | 1 + 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..61c0d0a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,61 @@ +default_language_version: + python: python3 + +exclude: ^(./.venv/|./build/) +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + # Identify invalid files + - id: check-ast + - id: check-yaml + - id: check-json + - id: check-toml + + # git checks + - id: check-merge-conflict + - id: check-added-large-files + - id: detect-private-key + - id: check-case-conflict + + # Python checks + - id: check-docstring-first + - id: debug-statements + - id: requirements-txt-fixer + - id: fix-byte-order-marker + + # General quality checks + - id: mixed-line-ending + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + - id: end-of-file-fixer + + - repo: https://github.com/PyCQA/autoflake + rev: v2.0.1 + hooks: + - id: autoflake + + - repo: https://github.com/asottile/pyupgrade + rev: v3.3.1 + hooks: + - id: pyupgrade + args: + - '--py37-plus' + + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + additional_dependencies: ['click~=8.1'] + args: + - "--line-length=99" + - "--target-version=py37" + - id: black + alias: black-check + stages: [manual] + additional_dependencies: ['click~=8.1'] + args: + - "--line-length=99" + - "--target-version=py37" + - "--check" + - "--diff" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 54b3acd..441d194 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,6 +3,7 @@ 1. [About this document](#about-this-document) 2. [Getting the code](#getting-the-code) 3. [Running `dbt-impala` in development](#running-dbt-impala-in-development) +4. [Testing](#testing) 4. [Submitting a Pull Request](#submitting-a-pull-request) ## About this document @@ -49,6 +50,8 @@ If you are a member of the `Cloudera` GitHub organization, you will have push ac 4. Install `dbt-impala` and development dependencies in the active `virtualenv`. Run `pip install -e . -r dev-requirements.txt`. +5. Add the pre-commit hook. Run `pre-commit install` + When `dbt-impala` is installed this way, any changes you make to the `dbt-impala` source code will be reflected immediately (i.e. in your next local dbt invocation against a Impala target). ## Testing @@ -76,6 +79,9 @@ You may run a specific test or group of tests using `pytest` directly. Activate ```sh # Note: replace $strings with valid names +# run full tests suite against an environment/endpoint +python -m pytest --profile dwx_endpoint + # run all impala functional tests in a directory python -m pytest tests/functional/$test_directory --profile dwx_endpoint python -m pytest tests/functional/adapter/test_basic.py --profile dwx_endpoint diff --git a/README.md b/README.md index cdc60e9..68434db 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The `dbt-impala` adapter allows you to use [dbt](https://www.getdbt.com/) along Current version of dbt-impala work only with dbt-core 1.3 but not with dbt-core >= 1.4. We are actively working on next release 1.4 which will work with dbt-core 1.4 -Python >= 3.8 +Python >= 3.7 dbt-core == 1.3.* For development/testing or contribution to the dbt-impala, please follow [Contributing](CONTRIBUTING.md) guidelines. diff --git a/dev-requirements.txt b/dev-requirements.txt index 651f74a..973ee2d 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,3 +1,5 @@ dbt-tests-adapter==1.3.* +pre-commit~=2.21;python_version=="3.7" +pre-commit~=3.2;python_version>="3.8" pytest pytest-dotenv diff --git a/setup.py b/setup.py index 6b284e2..470a851 100644 --- a/setup.py +++ b/setup.py @@ -74,6 +74,7 @@ def _get_dbt_core_version(): "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "License :: OSI Approved :: Apache Software License",