Skip to content

Commit 5ed05f2

Browse files
authored
fix: fixes pre-commit-config and adds type-checking; updates poe tasks (#547)
1 parent 77a68a5 commit 5ed05f2

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

.pre-commit-config.yaml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
exclude: |
44
(?x)(
55
# Python/system files
6-
^.*/__init__\.py$|
76
^.*?/\.venv/.*$|
87
^.*?/node_modules/.*$|
9-
8+
109
# Generated/test files
1110
^.*?/\.pytest_cache/.*$|
1211
^.*?/__pycache__/.*$|
1312
^.*?/\.mypy_cache/.*$|
14-
^.*?/\.ruff_cache/.*$
13+
^.*?/\.ruff_cache/.*$|
1514
1615
# Package management
1716
^.*?/poetry\.lock$|
@@ -22,7 +21,7 @@ exclude: |
2221
^.*?/build/.*$|
2322
^.*?/dist/.*$|
2423
^.*?/\.coverage$|
25-
^.*?/coverage\.xml$|
24+
^.*?/coverage\.xml$
2625
)
2726
2827
repos:
@@ -38,18 +37,15 @@ repos:
3837
- repo: https://github.com/astral-sh/ruff-pre-commit
3938
rev: v0.11.5
4039
hooks:
41-
# Run the linter with repo-defined settings
4240
- id: ruff
4341
args: [--fix]
44-
45-
# Run the formatter with repo-defined settings
4642
- id: ruff-format
4743

4844
- repo: https://github.com/pre-commit/mirrors-prettier
4945
rev: v3.0.3
5046
hooks:
5147
- id: prettier
52-
types_or: [json, yaml]
48+
args: [--write]
5349
additional_dependencies:
5450
- prettier@3.0.3
5551

@@ -61,3 +57,20 @@ repos:
6157
language: golang
6258
additional_dependencies: [github.com/google/addlicense@v1.1.1]
6359
files: \.py$
60+
61+
- id: poetry-check
62+
name: Check Poetry lockfile
63+
entry: poetry check
64+
language: system
65+
pass_filenames: false
66+
always_run: true
67+
68+
- repo: https://github.com/pre-commit/mirrors-mypy
69+
rev: v1.8.0
70+
hooks:
71+
- id: mypy
72+
name: mypy
73+
entry: mypy
74+
args: [--config-file=mypy.ini, --show-column-numbers]
75+
files: ^airbyte_cdk/
76+
pass_filenames: true

pyproject.toml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,63 +124,60 @@ dev = ["pytest"]
124124
airbyte-cdk = "airbyte_cdk.cli.airbyte_cdk:cli"
125125
source-declarative-manifest = "airbyte_cdk.cli.source_declarative_manifest:run"
126126

127-
[tool.isort]
128-
skip = ["__init__.py"] # TODO: Remove after this is fixed: https://github.com/airbytehq/airbyte-python-cdk/issues/12
129-
130127
# Ruff configuration moved to ruff.toml
131128

132129
[tool.poe.tasks]
133130
# Installation
134-
install = { shell = "poetry install --all-extras" }
135-
lock = { shell = "poetry lock" }
131+
install = { shell = "poetry install --all-extras", help = "Install all dependencies." }
132+
lock = { shell = "poetry lock", help = "Lock all dependencies." }
133+
134+
# Pre-commit tasks
135+
pre-commit = {cmd = "poetry run pre-commit run --all-files", help = "Run all pre-commit hooks on all files."}
136136

137137
# Build tasks
138138
assemble = {cmd = "bin/generate-component-manifest-dagger.sh", help = "Generate component manifest files."}
139139
build-package = {cmd = "poetry build", help = "Build the python package: source and wheels archives."}
140140
build = {sequence = ["assemble", "build-package"], help = "Run all tasks to build the package."}
141141

142142
# Format check tasks
143+
format-check = {sequence = ["_format-check-ruff", "_format-check-prettier"], help = "Check formatting for all file types via Ruff and Prettier.", ignore_fail = "return_non_zero"}
143144
_format-check-ruff = {cmd = "poetry run ruff format --check .", help = "Check formatting with Ruff."}
144145
_format-check-prettier = {cmd = "npx prettier . --check", help = "Check formatting with prettier."}
145-
format-check = {sequence = ["_format-check-ruff", "_format-check-prettier"], help = "Check formatting for all file types.", ignore_fail = "return_non_zero"}
146146

147147
# Format fix tasks
148+
format-fix = {sequence = ["_format-fix-ruff", "_format-fix-prettier"], help = "Format all file types via Ruff and Prettier.", ignore_fail = "return_non_zero"}
148149
_format-fix-ruff = {cmd = "poetry run ruff format .", help = "Format with Ruff."}
149150
_format-fix-prettier = {cmd = "npx prettier . --write", help = "Format with prettier."}
150-
format-fix = {sequence = ["_format-fix-ruff", "_format-fix-prettier"], help = "Format all file types.", ignore_fail = "return_non_zero"}
151151

152152
# Linting/Typing check tasks
153-
_lint-ruff = {cmd = "poetry run ruff check .", help = "Lint with Ruff."}
153+
lint = {cmd = "poetry run ruff check .", help = "Lint with Ruff."}
154154
type-check = {cmd = "poetry run mypy airbyte_cdk", help = "Type check modified files with mypy."}
155-
lint = {sequence = ["_lint-ruff", "type-check"], help = "Lint all code. Includes type checking.", ignore_fail = "return_non_zero"}
156-
157-
# Lockfile check task
158-
check-lockfile = {cmd = "poetry check", help = "Check the poetry lock file."}
159155

160156
# Linting/Typing fix tasks
161-
lint-fix = { cmd = "poetry run ruff check --fix .", help = "Auto-fix any lint issues that Ruff can automatically resolve (excluding 'unsafe' fixes)." }
162-
lint-fix-unsafe = { cmd = "poetry run ruff check --fix --unsafe-fixes .", help = "Lint-fix modified files, including 'unsafe' fixes. It is recommended to first commit any pending changes and then always manually review any unsafe changes applied." }
157+
lint-fix = { cmd = "poetry run ruff check --fix .", help = "Auto-fix any lint issues that Ruff can automatically resolve (excluding 'unsafe' fixes) with Ruff." }
158+
lint-fix-unsafe = { cmd = "poetry run ruff check --fix --unsafe-fixes .", help = "Lint-fix modified files, including 'unsafe' fixes with Ruff. It is recommended to first commit any pending changes and then always manually review any unsafe changes applied." }
163159

164160
# ruff fix everything (ignoring non-Python fixes)
165161
ruff-fix = { sequence = ["lint-fix", "_format-fix-ruff"], help = "Lint-fix and format-fix all code." }
166162

167-
# Combined Check and Fix tasks
163+
# Lockfile check task
164+
_check-lockfile = {cmd = "poetry check", help = "Check the poetry lock file."}
168165

169-
check-all = {sequence = ["lint", "format-check", "type-check", "check-lockfile"], help = "Lint, format, and type-check modified files.", ignore_fail = "return_non_zero"}
166+
# Combined Check and Fix tasks
167+
check-all = {sequence = ["lint", "format-check", "type-check", "_check-lockfile"], help = "Lint, format, and type-check modified files.", ignore_fail = "return_non_zero"}
170168
fix-all = {sequence = ["format-fix", "lint-fix"], help = "Lint-fix and format-fix modified files, ignoring unsafe fixes.", ignore_fail = "return_non_zero"}
171169
fix-and-check = {sequence = ["fix-all", "check-all"], help = "Lint-fix and format-fix, then re-check to see if any issues remain.", ignore_fail = "return_non_zero"}
172170

173171
# PyTest tasks
174-
175172
pytest = {cmd = "poetry run coverage run -m pytest --durations=10", help = "Run all pytest tests."}
176-
pytest-fast = {cmd = "poetry run coverage run -m pytest --durations=5 --exitfirst -m 'not flaky and not slow and not requires_creds'", help = "Run pytest tests, failing fast and excluding slow tests."}
173+
pytest-fast = {cmd = "poetry run coverage run -m pytest --skipslow --durations=5 --exitfirst -m 'not flaky and not slow and not requires_creds'", help = "Run pytest tests, failing fast and excluding slow tests."}
177174
unit-test-with-cov = {cmd = "poetry run pytest -s unit_tests --cov=airbyte_cdk --cov-report=term --cov-config ./pyproject.toml", help = "Run unit tests and create a coverage report."}
178175

179176
# Combined check tasks (other)
180177

181178
# TODO: find a version of the modified mypy check that works both locally and in CI.
182-
check-local = {sequence = ["lint", "type-check", "check-lockfile", "unit-test-with-cov"], help = "Lint all code, type-check modified files, and run unit tests."}
183-
check-ci = {sequence = ["check-lockfile", "build", "lint", "unit-test-with-cov"], help = "Build the package, lint and run unit tests. Does not include type-checking."}
179+
check-local = {sequence = ["lint", "type-check", "_check-lockfile", "unit-test-with-cov"], help = "Lint all code, type-check modified files, and run unit tests."}
180+
check-ci = {sequence = ["_check-lockfile", "build", "lint", "unit-test-with-cov"], help = "Build the package, lint and run unit tests. Does not include type-checking."}
184181

185182
# Build and check
186183
pre-push = {sequence = ["build", "check-local"], help = "Run all build and check tasks."}

0 commit comments

Comments
 (0)