Skip to content

Commit

Permalink
add and configure pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Apr 16, 2024
1 parent 2680f86 commit e3bd2fd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 73 deletions.
28 changes: 9 additions & 19 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ on:
workflow_dispatch:
inputs:
dbt_adapters_branch:
description: "The branch of dbt-adapters to evaluate"
type: string
required: true
default: "main"
description: "The branch of dbt-adapters to evaluate"
type: string
default: "main"
workflow_call:
inputs:
dbt_adapters_branch:
description: "The branch of dbt-adapters to evaluate"
type: string
required: true
default: "main"

permissions: read-all
Expand All @@ -27,34 +25,26 @@ permissions: read-all
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.ref || github.sha }}
cancel-in-progress: true
env:
# set DBT_ADAPTERS_BRANCH to the input value if the event is a workflow_dispatch (workflow_call uses the same event_name),
# otherwise use 'main'
DBT_ADAPTERS_BRANCH: ${{ github.event_name == 'workflow_dispatch' && inputs.dbt_adapters_branch || 'main' }}

jobs:
code-quality:
name: Code Quality
runs-on: ubuntu-latest


steps:
- name: Check out repository
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Update Adapters and Core branches
if: ${{ contains(github.event_name, 'workflow_') }}
shell: bash
run: |
./.github/scripts/update_dev_packages.sh \
$DBT_ADAPTERS_BRANCH \
"main"
run: ./.github/scripts/update_dev_packages.sh ${{ inputs.dbt_adapters_branch }} "main"

- name: Setup `hatch`
uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main

- name: Run linters
run: hatch run lint:all

- name: Run typechecks
run: hatch run typecheck:all
- name: Run code quality
shell: bash
run: hatch run code-quality
57 changes: 27 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
# For more on configuring pre-commit hooks (see https://pre-commit.com/)

# Force all unspecified python hooks to run python 3.8
default_language_version:
python: python3
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
args: [--unsafe]
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
args: [--unsafe]
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
26 changes: 2 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,10 @@ dependencies = [
]
post-install-commands = ["pre-commit install"]
[tool.hatch.envs.default.scripts]
precommit = "pre-commit run --all-files"

[tool.hatch.envs.lint]
detached = true
dependencies = [
"black>=24.3",
"flake8",
"Flake8-pyproject",
]
[tool.hatch.envs.lint.scripts]
all = [
"black",
"flake8",
]
code-quality = "pre-commit run --all-files" # runs others via hooks
black = "python -m black ."
flake8 = "python -m flake8 ."

[tool.hatch.envs.typecheck]
dependencies = [
"mypy",
"types-protobuf",
"types-pytz",
]
[tool.hatch.envs.typecheck.scripts]
all = "python -m mypy ."
mypy = "python -m mypy ."

[tool.hatch.envs.unit-tests]
dependencies = [
Expand All @@ -105,7 +84,6 @@ dependencies = [
"pytest-xdist",
]
extra-dependencies = [
# TODO: remove `dbt-core` dependencies from unit tests
"dbt-adapters @ git+https://github.com/dbt-labs/dbt-adapters.git",
"dbt-common @ git+https://github.com/dbt-labs/dbt-common.git",
"dbt-core @ git+https://github.com/dbt-labs/dbt-core.git#subdirectory=core",
Expand Down

0 comments on commit e3bd2fd

Please sign in to comment.