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

CI: Move Ruff rules to dedicated ruff.toml config, and add pre-commit setup #184

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/pypi_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: Packaging and Publishing
on:
push:
tags:
- 'v*'
- "v*"
workflow_dispatch:
inputs:
version:
Expand Down
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Pre-commit configuration file.
#
# Usage:
# pre-commit # Run pre-commit checks on modified files.
# pre-commit run --all-files # Run pre-commit on all files in the repo.
#
# You do not need to install pre-commit as a git hook. The pre-commit
# tool can be called directly (or in CI). You can also lean on your IDE
# or CLI of the individual tools to run them directly.
#
# If direct execution differs from the pre-commit execution, this is a bug
# and should be raised as an issue.
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
hooks:
# Run the linter.
- id: ruff
args:
- --fix
- --select=I

# Run the formatter.
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
- id: prettier
types_or: [json, yaml]
additional_dependencies:
- [email protected]

- repo: local
hooks:
- id: addlicense
name: Add license headers
entry: addlicense -c "Airbyte, Inc." -l apache -v -f LICENSE_SHORT
language: golang
additional_dependencies: [github.com/google/[email protected]]
files: \.py$
1 change: 1 addition & 0 deletions LICENSE_SHORT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copyright (c) 2024 Airbyte, Inc., all rights reserved.
2 changes: 2 additions & 0 deletions airbyte_cdk/cli/source_declarative_manifest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.

from airbyte_cdk.cli.source_declarative_manifest._run import run


Expand Down
4 changes: 3 additions & 1 deletion airbyte_cdk/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
#
# The earlier versions of airbyte-cdk (0.28.0<=) had the airbyte_protocol python classes
# declared inline in the airbyte-cdk code. However, somewhere around Feb 2023 the
# Airbyte Protocol moved to its own repo/PyPi package, called airbyte-protocol-models.
Expand Down Expand Up @@ -69,4 +71,4 @@
ConfiguredAirbyteCatalogSerializer,
ConfiguredAirbyteStreamSerializer,
ConnectorSpecificationSerializer,
)
)
1 change: 1 addition & 0 deletions airbyte_cdk/sources/declarative/async_job/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions airbyte_cdk/sources/declarative/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
2 changes: 2 additions & 0 deletions airbyte_cdk/sources/declarative/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
#
# generated by bin/generate_component_manifest_files.py
from .declarative_component_schema import *
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
#
# generated by datamodel-codegen:
# filename: declarative_component_schema.yaml

Expand Down
1 change: 1 addition & 0 deletions airbyte_cdk/sources/file_based/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from .config.abstract_file_based_spec import AbstractFileBasedSpec
from .config.csv_format import CsvFormat
from .config.file_based_stream_config import FileBasedStreamConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from .abstract_file_based_availability_strategy import AbstractFileBasedAvailabilityStrategy, AbstractFileBasedAvailabilityStrategyWrapper
from .default_file_based_availability_strategy import DefaultFileBasedAvailabilityStrategy

Expand Down
1 change: 1 addition & 0 deletions airbyte_cdk/sources/file_based/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from airbyte_cdk.sources.file_based.discovery_policy.abstract_discovery_policy import AbstractDiscoveryPolicy
from airbyte_cdk.sources.file_based.discovery_policy.default_discovery_policy import DefaultDiscoveryPolicy

Expand Down
1 change: 1 addition & 0 deletions airbyte_cdk/sources/file_based/file_types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from typing import Any, Mapping, Type

from airbyte_cdk.sources.file_based.config.avro_format import AvroFormat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from airbyte_cdk.sources.file_based.schema_validation_policies.abstract_schema_validation_policy import AbstractSchemaValidationPolicy
from airbyte_cdk.sources.file_based.schema_validation_policies.default_schema_validation_policies import (
DEFAULT_SCHEMA_VALIDATION_POLICIES,
Expand Down
1 change: 1 addition & 0 deletions airbyte_cdk/sources/file_based/stream/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from airbyte_cdk.sources.file_based.stream.abstract_file_based_stream import AbstractFileBasedStream
from airbyte_cdk.sources.file_based.stream.default_file_based_stream import DefaultFileBasedStream

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from .abstract_concurrent_file_based_cursor import AbstractConcurrentFileBasedCursor
from .file_based_concurrent_cursor import FileBasedConcurrentCursor
from .file_based_final_state_cursor import FileBasedFinalStateCursor
Expand Down
1 change: 1 addition & 0 deletions airbyte_cdk/sources/file_based/stream/cursor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from .abstract_file_based_cursor import AbstractFileBasedCursor
from .default_file_based_cursor import DefaultFileBasedCursor

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions airbyte_cdk/sql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions airbyte_cdk/sql/_util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions airbyte_cdk/test/mock_http/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from airbyte_cdk.test.mock_http.matcher import HttpRequestMatcher
from airbyte_cdk.test.mock_http.request import HttpRequest
from airbyte_cdk.test.mock_http.response import HttpResponse
Expand Down
1 change: 1 addition & 0 deletions airbyte_cdk/utils/slice_hasher.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
import hashlib
import json
from typing import Any, Final, Mapping, Optional
Expand Down
12 changes: 0 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ sql = ["sqlalchemy"]

source-declarative-manifest = "airbyte_cdk.cli.source_declarative_manifest:run"

[tool.isort]
skip = ["__init__.py"] # TODO: Remove after this is fixed: https://github.com/airbytehq/airbyte-python-cdk/issues/12

[tool.ruff]
exclude = ["__init__.py"] # TODO: Remove after this is fixed: https://github.com/airbytehq/airbyte-python-cdk/issues/12

target-version = "py310"
line-length = 100

[tool.ruff.lint]
select = ["I"]

[tool.poe.tasks]
# Installation
install = { shell = "poetry install --all-extras" }
Expand Down
17 changes: 17 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ruff linting and formatting config file
#
# We keep this in a dedicated file:
# 1. To keep pyproject.toml clean and focused on Python dependencies.
# 2. To streamline migration of rules and config options across our various Python projects.
#
# Ruff docs for quick reference:
# - https://docs.astral.sh/ruff/configuration/
# - https://docs.astral.sh/ruff/rules/

exclude = ["__init__.py"] # TODO: Remove after this is fixed: https://github.com/airbytehq/airbyte-python-cdk/issues/12

target-version = "py310"
line-length = 100

[lint]
select = ["I"]
1 change: 1 addition & 0 deletions unit_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
# THIS STOPS SOME MODELS TESTS FROM FALLING OVER. IT'S A HACK, WE SHOULD PIN DOWN WHAT'S ACTUALLY GOING ON HERE

# Import the thing that needs to be imported to stop the tests from falling over
Expand Down
1 change: 1 addition & 0 deletions unit_tests/destinations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/source_declarative_manifest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/declarative/async_job/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/declarative/decoders/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/declarative/incremental/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/declarative/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
from typing import List
from unittest import TestCase
from unittest.mock import Mock
Expand Down
1 change: 1 addition & 0 deletions unit_tests/sources/file_based/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/file_based/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/file_based/discovery_policy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/file_based/file_types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/file_based/scenarios/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/file_based/stream/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/message/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/streams/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/streams/checkpoint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/streams/concurrent/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
import pytest

from airbyte_cdk.sources.streams.concurrent.helpers import get_primary_key_from_stream
Expand Down
1 change: 1 addition & 0 deletions unit_tests/sources/streams/http/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/sources/streams/http/error_handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
1 change: 1 addition & 0 deletions unit_tests/test/mock_http/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
3 changes: 0 additions & 3 deletions unit_tests/test_counter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#


from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions unit_tests/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
Loading