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

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented Dec 21, 2024

Consolidate Ruff linting rules into a ruff.toml file and establish a pre-commit configuration to streamline code quality checks. Additionally, apply auto-formatting and fix minor formatting issues, including missing copyright text.

Note:

  • This PR adds streamlined ability to auto-format with prettier and add copyright text, but it doesn't (yet) make stricter CI rules.
  • This doesn't change our CI as of yet. I expect to pick that up in a future iteration.
  • For now, pre-commit is just added as an option to streamline the required auto-format steps (plus a bit more).

Summary by CodeRabbit

  • New Features

    • Introduced a new class SliceHasher for computing hash values based on stream names and slices.
    • Added various authentication and pagination classes to enhance the functionality of the Airbyte CDK.
    • Implemented a comprehensive set of classes for declarative component schema.
  • Bug Fixes

    • Enhanced unit tests for DeclarativePartitionFactory and get_primary_key_from_stream to ensure correct functionality.
  • Chores

    • Added copyright notices across multiple files for compliance.
    • Introduced a new configuration file for Ruff to streamline linting processes.
    • Updated pyproject.toml to manage dependencies effectively.

@aaronsteers aaronsteers changed the title Move Ruff rules to dedicated config and add pre-commit setup Move Ruff rules to dedicated ruff.toml config, and add pre-commit setup Dec 21, 2024
@aaronsteers aaronsteers changed the title Move Ruff rules to dedicated ruff.toml config, and add pre-commit setup CI: Move Ruff rules to dedicated ruff.toml config, and add pre-commit setup Dec 21, 2024
Copy link
Contributor

coderabbitai bot commented Dec 21, 2024

📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive set of changes across the Airbyte CDK repository, primarily focusing on adding copyright notices, enhancing workflow configurations, and introducing new configuration files. The modifications span multiple directories, including GitHub Actions workflows, pre-commit configurations, and various Python modules, with an emphasis on standardizing code formatting, licensing, and build processes.

Changes

File Change Summary
.github/workflows/pypi_publish.yml Modified tag pattern from single to double quotes, added detailed workflow dispatch input descriptions
.pre-commit-config.yaml New configuration file with Ruff, Prettier, and license header hooks
LICENSE_SHORT Added 2024 copyright notice for Airbyte, Inc.
pyproject.toml Removed isort and ruff sections, streamlined dependency management
ruff.toml New configuration file for Ruff linting and formatting
Multiple __init__.py files Added copyright notices across various modules
airbyte_cdk/utils/slice_hasher.py Added new SliceHasher class for computing hash values
unit_tests/sources/declarative/stream_slicers/test_declarative_partition_generator.py New test class for stream slicer partition generator
unit_tests/sources/streams/concurrent/test_helpers.py Added tests for primary key handling in concurrent streams

Possibly related PRs

Suggested labels

ci, enhancement

Suggested reviewers

  • ChristoGrab
  • maxi297

Would you like me to elaborate on any specific aspect of these changes? 🤔 What do you think about the comprehensive updates to the repository's configuration and testing infrastructure? wdyt?

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (2)
airbyte_cdk/sources/declarative/models/declarative_component_schema.py (2)

Line range hint 61-160: Confirm if user-supplied strings are adequately sanitized.

Many fields rely on user-provided configurations (like custom class names, tokens, etc.). Are we confident that these inputs won't create security issues (e.g., path traversal in dynamic imports)? Maybe you can consider a validation or safer import approach, wdyt?


Line range hint 161-320: Check if you want to unify the “parameters” usage.

We see repeated usage of Optional[Dict[str, Any]] named “parameters” across classes. Is there a uniform approach or base class that might consolidate this field’s behavior to reduce duplication, wdyt?

🧹 Nitpick comments (11)
unit_tests/sources/streams/concurrent/test_helpers.py (4)

Line range hint 6-8: Consider adding a docstring for better documentation?

The test is well-written and follows BDD naming, but what do you think about adding a brief docstring to explain the purpose and expected behavior? Something like:

def test_given_primary_key_is_list_of_strings_when_get_primary_key_from_stream_then_assume_it_is_composite_key_and_return_as_is():
    """Verify that a list of strings is treated as a composite key and returned unchanged."""
    result = get_primary_key_from_stream(["composite_id_1", "composite_id_2"])
    assert result == ["composite_id_1", "composite_id_2"]

wdyt?


Line range hint 11-13: Consider adding input immutability check?

The test looks good! Would it be valuable to add an assertion verifying that the original input remains unchanged after the function call? This could help catch any accidental mutations, wdyt?

def test_given_primary_key_is_composite_in_nested_lists_when_get_primary_key_from_stream_then_flatten_lists():
    input_value = [["composite_id_1"], ["composite_id_2"]]
    original = [x[:] for x in input_value]  # Deep copy
    result = get_primary_key_from_stream(input_value)
    assert result == ["composite_id_1", "composite_id_2"]
    assert input_value == original  # Verify input wasn't modified

Line range hint 16-18: How about verifying the error message too?

The error case testing is great! Would it be helpful to also verify the error message to ensure it provides meaningful feedback? Something like:

def test_given_nested_key_when_get_primary_key_from_stream_then_raise_error():
    with pytest.raises(ValueError, match="Expected flat list of strings or list of single-item lists"):
        get_primary_key_from_stream([["composite_id_1", "composite_id_2"]])

Line range hint 1-18: Consider adding tests for additional edge cases?

The current test coverage is good for the basic scenarios! Would it be valuable to add tests for:

  1. Empty list input
  2. Non-string values in the list
  3. None input
  4. Single string input (not in a list)

These would help ensure robust handling of edge cases. Happy to help draft these if you're interested! wdyt?

airbyte_cdk/sources/declarative/models/declarative_component_schema.py (3)

Line range hint 1-60: Ponder re-grouping related classes into separate modules?

This file is quite large, hosting a variety of classes (authentication, pagination, transformations, etc.). Splitting them into smaller modules might improve clarity and modularity, wdyt?


Line range hint 321-620: Evaluate potential synergy of multiple OAuth classes.

We have multiple OAuth-related classes (OAuthAuthenticator, RefreshTokenUpdater, OAuthConfigSpecification, etc.). Is there a risk of duplication or confusion between them? Maybe stepping back to see if they can be combined or made more compositional for easier maintenance, wdyt?


Line range hint 621-873: Would you consider adding thorough unit tests for these data models?

Since these models drive important workflows, a robust set of tests might help catch schema changes early. Possibly consider adding or enhancing tests for both happy and edge-case scenarios, wdyt?

airbyte_cdk/utils/slice_hasher.py (2)

Line range hint 1-12: Add logging for serialization errors?

Right now, if JSON serialization fails, a ValueError is raised. Logging may help troubleshoot specific slices. Would you consider logging the failing slice before raising the exception, wdyt?


Line range hint 13-24: Consider clarifying “last 8 bytes of the hash” usage.

Using only the last 8 bytes for the hash is interesting. Perhaps add a docstring explaining why 8 bytes are preferred. This might help new contributors understand this design choice, wdyt?

unit_tests/sources/declarative/stream_slicers/test_declarative_partition_generator.py (2)

Line range hint 37-80: Add coverage for concurrency or partial failures?

Currently, the tests focus on single-thread scenarios. Have you considered testing partial failures or concurrency use cases if any? Doing so might uncover more edge cases, wdyt?


Line range hint 81-103: Check the final assertion style for consistency.

We see a mix of assert statements and assert_called_once_with. Maintaining a consistent approach (like using pytest’s style vs. raw asserts) might improve readability, wdyt?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae1211f and dd58b61.

📒 Files selected for processing (56)
  • .github/workflows/pypi_publish.yml (1 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • LICENSE_SHORT (1 hunks)
  • airbyte_cdk/cli/source_declarative_manifest/__init__.py (1 hunks)
  • airbyte_cdk/models/__init__.py (2 hunks)
  • airbyte_cdk/sources/declarative/async_job/__init__.py (1 hunks)
  • airbyte_cdk/sources/declarative/migrations/__init__.py (1 hunks)
  • airbyte_cdk/sources/declarative/models/__init__.py (1 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1 hunks)
  • airbyte_cdk/sources/file_based/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/availability_strategy/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/config/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/discovery_policy/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/file_types/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/schema_validation_policies/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/stream/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/stream/concurrent/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/stream/concurrent/cursor/__init__.py (1 hunks)
  • airbyte_cdk/sources/file_based/stream/cursor/__init__.py (1 hunks)
  • airbyte_cdk/sources/streams/concurrent/state_converters/__init__.py (1 hunks)
  • airbyte_cdk/sql/__init__.py (1 hunks)
  • airbyte_cdk/sql/_util/__init__.py (1 hunks)
  • airbyte_cdk/test/mock_http/__init__.py (1 hunks)
  • airbyte_cdk/utils/slice_hasher.py (1 hunks)
  • pyproject.toml (0 hunks)
  • ruff.toml (1 hunks)
  • unit_tests/__init__.py (1 hunks)
  • unit_tests/destinations/__init__.py (1 hunks)
  • unit_tests/source_declarative_manifest/__init__.py (1 hunks)
  • unit_tests/source_declarative_manifest/resources/__init__.py (1 hunks)
  • unit_tests/sources/__init__.py (1 hunks)
  • unit_tests/sources/declarative/async_job/__init__.py (1 hunks)
  • unit_tests/sources/declarative/concurrency_level/__init__.py (1 hunks)
  • unit_tests/sources/declarative/decoders/__init__.py (1 hunks)
  • unit_tests/sources/declarative/incremental/__init__.py (1 hunks)
  • unit_tests/sources/declarative/migrations/__init__.py (1 hunks)
  • unit_tests/sources/declarative/stream_slicers/test_declarative_partition_generator.py (1 hunks)
  • unit_tests/sources/file_based/__init__.py (1 hunks)
  • unit_tests/sources/file_based/availability_strategy/__init__.py (1 hunks)
  • unit_tests/sources/file_based/config/__init__.py (1 hunks)
  • unit_tests/sources/file_based/discovery_policy/__init__.py (1 hunks)
  • unit_tests/sources/file_based/file_types/__init__.py (1 hunks)
  • unit_tests/sources/file_based/scenarios/__init__.py (1 hunks)
  • unit_tests/sources/file_based/stream/__init__.py (1 hunks)
  • unit_tests/sources/file_based/stream/concurrent/__init__.py (1 hunks)
  • unit_tests/sources/message/__init__.py (1 hunks)
  • unit_tests/sources/streams/__init__.py (1 hunks)
  • unit_tests/sources/streams/checkpoint/__init__.py (1 hunks)
  • unit_tests/sources/streams/concurrent/test_helpers.py (1 hunks)
  • unit_tests/sources/streams/http/__init__.py (1 hunks)
  • unit_tests/sources/streams/http/error_handlers/__init__.py (1 hunks)
  • unit_tests/sources/streams/http/requests_native_auth/__init__.py (1 hunks)
  • unit_tests/test/__init__.py (1 hunks)
  • unit_tests/test/mock_http/__init__.py (1 hunks)
  • unit_tests/test_counter.py (0 hunks)
  • unit_tests/utils/__init__.py (1 hunks)
💤 Files with no reviewable changes (2)
  • unit_tests/test_counter.py
  • pyproject.toml
✅ Files skipped from review due to trivial changes (50)
  • unit_tests/sources/init.py
  • airbyte_cdk/sources/file_based/config/init.py
  • unit_tests/sources/file_based/stream/init.py
  • unit_tests/sources/declarative/decoders/init.py
  • unit_tests/sources/file_based/stream/concurrent/init.py
  • unit_tests/sources/file_based/discovery_policy/init.py
  • airbyte_cdk/cli/source_declarative_manifest/init.py
  • airbyte_cdk/sources/file_based/stream/cursor/init.py
  • unit_tests/sources/file_based/init.py
  • unit_tests/destinations/init.py
  • airbyte_cdk/sources/file_based/discovery_policy/init.py
  • unit_tests/test/mock_http/init.py
  • unit_tests/sources/declarative/migrations/init.py
  • airbyte_cdk/sql/init.py
  • unit_tests/sources/streams/http/error_handlers/init.py
  • airbyte_cdk/sources/streams/concurrent/state_converters/init.py
  • unit_tests/sources/declarative/incremental/init.py
  • unit_tests/sources/declarative/async_job/init.py
  • unit_tests/source_declarative_manifest/init.py
  • unit_tests/sources/declarative/concurrency_level/init.py
  • airbyte_cdk/sources/declarative/async_job/init.py
  • unit_tests/sources/file_based/file_types/init.py
  • unit_tests/sources/streams/checkpoint/init.py
  • unit_tests/sources/streams/http/requests_native_auth/init.py
  • LICENSE_SHORT
  • unit_tests/source_declarative_manifest/resources/init.py
  • airbyte_cdk/sql/_util/init.py
  • unit_tests/sources/file_based/config/init.py
  • unit_tests/sources/streams/http/init.py
  • airbyte_cdk/sources/declarative/models/init.py
  • unit_tests/sources/file_based/availability_strategy/init.py
  • airbyte_cdk/test/mock_http/init.py
  • unit_tests/sources/message/init.py
  • unit_tests/sources/streams/init.py
  • unit_tests/sources/file_based/scenarios/init.py
  • unit_tests/test/init.py
  • unit_tests/utils/init.py
  • airbyte_cdk/sources/file_based/stream/concurrent/cursor/init.py
  • airbyte_cdk/sources/file_based/stream/concurrent/init.py
  • airbyte_cdk/sources/file_based/stream/init.py
  • ruff.toml
  • airbyte_cdk/sources/file_based/availability_strategy/init.py
  • airbyte_cdk/sources/declarative/migrations/init.py
  • airbyte_cdk/models/init.py
  • airbyte_cdk/sources/file_based/file_types/init.py
  • unit_tests/init.py
  • airbyte_cdk/sources/file_based/schema_validation_policies/init.py
  • airbyte_cdk/sources/file_based/init.py
  • .pre-commit-config.yaml
  • .github/workflows/pypi_publish.yml
🔇 Additional comments (2)
unit_tests/sources/streams/concurrent/test_helpers.py (1)

1-3: LGTM! Clean imports and proper copyright notice.

The imports are minimal and appropriate for the test file's needs.

unit_tests/sources/declarative/stream_slicers/test_declarative_partition_generator.py (1)

Line range hint 1-36: Add a test documenting expected usage for empty slices?

It may be helpful to have a test demonstrating behavior when an empty slice is created. This could clarify the intended usage and corner-case coverage, wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant