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

style: address linting and typing issues #29

Merged
merged 11 commits into from
Oct 9, 2024
Merged

Conversation

Karanjot786
Copy link
Member

@Karanjot786 Karanjot786 commented Oct 2, 2024

Description:
This PR introduces linting with Ruff and type-checking with Mypy to enforce code quality and consistency across the project. The key changes are outlined below:

Added Support for Ruff and Mypy

Linting with Ruff:

  • Integrated Ruff as the project's linting tool.
  • Configured Ruff to focus on PEP8 compliance and to catch common coding errors.
  • Ensured the codebase adheres to consistent styling and best practices.

Type-Checking with Mypy:

  • Added Mypy for static type-checking.
  • Introduced type annotations across the codebase to ensure type safety and consistency.
  • Resolved untyped calls and methods flagged by Mypy.

Code Updates

Type Annotations Added:

  • Updated modules with necessary type annotations:
    • crategen/converters/abstract_converter.py
    • crategen/converters/utils.py
    • crategen/converters/wes_converter.py
    • crategen/converters/tes_converter.py
    • crategen/converter_manager.py
    • crategen/cli.py
  • Typed utility functions such as convert_to_iso8601 for ISO 8601 conversions.
  • Added return type annotations for methods in the AbstractConverter, WESConverter, TESConverter, and ConverterManager classes.
  • Ensured all helper functions and class methods are typed.

CI Pipeline Enhancements

Continuous Integration Updates:

  • Updated .github/workflows/ci.yml to:
    • Automatically run Ruff for linting during CI.
    • Execute Mypy for type-checking in the CI pipeline.
  • Ensured code adheres to strict typing and style guidelines during CI checks.

Lefthook Integration

Pre-Push Hooks:

  • Added a lefthook.yml configuration to enforce pre-push Ruff checks.
  • Prevented code that violates style guides from being merged by ensuring any code pushed passes linting checks.

Files Changed

CI and Hooks Configuration:

  • .github/workflows/ci.yml: Updated to run Ruff and Mypy checks during CI.
  • lefthook.yml: Added to configure Ruff for pre-push linting.

Codebase Updates:

  • crategen/converters/abstract_converter.py: Added type annotations to abstract methods.
  • crategen/converters/utils.py: Added type annotations to convert_to_iso8601.
  • crategen/converters/wes_converter.py: Added type annotations and fixed untyped function calls.
  • crategen/converters/tes_converter.py: Added type annotations and fixed untyped function calls.
  • crategen/converter_manager.py: Added type annotations to methods.
  • crategen/cli.py: Added type annotations and updated function signatures.

Summary by Sourcery

Add linting with Ruff and type-checking with Mypy to improve code quality and consistency. Update CI pipeline to include these checks and integrate Lefthook for pre-push linting enforcement. Enhance codebase with type annotations for better maintainability.

New Features:

  • Introduce linting with Ruff to enforce PEP8 compliance and catch common coding errors.
  • Add type-checking with Mypy to ensure type safety and consistency across the codebase.

Enhancements:

  • Add type annotations to various modules and functions to improve code clarity and maintainability.

CI:

  • Update CI pipeline to automatically run Ruff for linting and Mypy for type-checking during CI checks.

Chores:

  • Integrate Lefthook to enforce pre-push Ruff checks, preventing code that violates style guides from being merged.

Copy link

sourcery-ai bot commented Oct 2, 2024

Reviewer's Guide by Sourcery

This pull request introduces linting with Ruff and type-checking with Mypy to enforce code quality and consistency across the project. The changes include adding type annotations to existing Python files, updating the CI pipeline to include Ruff and Mypy checks, and integrating Lefthook for pre-push checks. The implementation focuses on improving code quality, type safety, and maintaining consistent coding standards.

Architecture diagram for CI pipeline with Ruff and Mypy

graph TD;
    A[CI Pipeline] -->|Run on push/pull_request| B[Build Job];
    B --> C[Checkout Code];
    B --> D[Set up Python 3.11];
    B --> E[Install Poetry];
    B --> F[Lint with Ruff];
    B --> G[Type check with Mypy];
    B --> H[Run security checks with Bandit];
    B --> I[Install test dependencies];
    F -->|If successful| G;
Loading

Class diagram for updated converters with type annotations

classDiagram
    class AbstractConverter {
        <<abstract>>
        +convert_to_wrroc(data: Dict~str, Any~) Dict~str, Any~
        +convert_from_wrroc(wrroc_data: Dict~str, Any~) Dict~str, Any~
    }
    class TESConverter {
        +convert_to_wrroc(tes_data: Dict~str, Any~) Dict~str, Any~
        +convert_from_wrroc(wrroc_data: Dict~str, Any~) Dict~str, Any~
    }
    class WESConverter {
        +convert_to_wrroc(wes_data: Dict~str, Any~) Dict~str, Any~
        +convert_from_wrroc(wrroc_data: Dict~str, Any~) Dict~str, Any~
    }
    class ConverterManager {
        +convert_tes_to_wrroc(tes_data: Dict~str, Any~) Dict~str, Any~
        +convert_wes_to_wrroc(wes_data: Dict~str, Any~) Dict~str, Any~
    }
    AbstractConverter <|-- TESConverter
    AbstractConverter <|-- WESConverter
    TESConverter <.. ConverterManager
    WESConverter <.. ConverterManager
Loading

File-Level Changes

Change Details Files
Integration of Ruff for linting and Mypy for type-checking
  • Added Ruff configuration for linting
  • Introduced Mypy for static type-checking
  • Updated CI pipeline to run Ruff and Mypy checks
  • Added pre-push hooks using Lefthook to enforce linting and type-checking
.github/workflows/ci.yml
lefthook.yml
Addition of type annotations to existing Python files
  • Added type hints to function parameters and return values
  • Updated import statements to include typing module
  • Added docstrings with type information
crategen/cli.py
crategen/converters/tes_converter.py
crategen/converters/wes_converter.py
crategen/converters/utils.py
crategen/converter_manager.py
crategen/converters/abstract_converter.py
Refactoring of existing code to improve readability and maintainability
  • Updated formatting to comply with PEP8 standards
  • Improved error handling and default value assignments
  • Enhanced docstrings with more detailed descriptions
crategen/cli.py
crategen/converters/tes_converter.py
crategen/converters/wes_converter.py
crategen/converters/utils.py
crategen/converter_manager.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Karanjot786 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

crategen/converters/tes_converter.py Outdated Show resolved Hide resolved
crategen/converters/tes_converter.py Show resolved Hide resolved
crategen/converters/tes_converter.py Show resolved Hide resolved
@uniqueg uniqueg changed the title style: add linting with Ruff and type-checking with Mypy style: address linting and typing issues Oct 3, 2024
Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

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

Looks mostly good to me. Two minor comments:

  • Please do the upgrade/modifications of the CI workflow in a separate PR and remove from here. The new PR should be merged before this one. Also make sure to remove the commented out lines. Readd them only later when you actually add tests (obviously uncommented then).
  • Ignore the Sourcery comments for this PR. They may be useful to consider in future PRs though.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
crategen/converters/tes_converter.py Outdated Show resolved Hide resolved
crategen/converters/tes_converter.py Show resolved Hide resolved
crategen/converters/tes_converter.py Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@Karanjot786
Copy link
Member Author

Looks mostly good to me. Two minor comments:

* Please do the upgrade/modifications of the CI workflow in a separate PR and remove from here. The new PR should be merged _before_ this one. Also make sure to remove the commented out lines. Readd them only later when you actually add tests (obviously uncommented then).

* Ignore the Sourcery comments for _this_ PR. They may be useful to consider in future PRs though.

Hi @uniqueg,

Thanks for the feedback!

  1. CI Workflow Modifications:

As suggested, I will create a separate PR specifically for the upgrade and modifications to the CI workflow. Once that’s merged, I’ll remove the changes from this PR. I'll make sure to remove the commented-out lines and re-add them later when the tests are included.

  1. Sourcery Comments:

Got it! I'll ignore the Sourcery comments for this PR and will take them into account for future PRs where relevant.

@uniqueg
Copy link
Member

uniqueg commented Oct 8, 2024

Thanks @Karanjot786! #30 is approved now and can be merged.

Please:

@Karanjot786
Copy link
Member Author

I have temporarily adjusted the mypy configuration in pyproject.toml to relax strict type checking. This allows the code to pass mypy checks without adding type annotations. I plan to address type annotations and re-enable strict mypy checks in a separate PR.

@Karanjot786 Karanjot786 requested a review from uniqueg October 8, 2024 16:19
Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

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

Good stuff!

Please work on the docstring sections, then it will be good to go.

crategen/cli.py Outdated Show resolved Hide resolved
crategen/cli.py Show resolved Hide resolved
@Karanjot786
Copy link
Member Author

Hi @uniqueg,

I've updated the docstrings as per your feedback. All functions and methods now include "Args", "Returns", and other relevant sections where applicable. I've ensured consistency across the codebase.

As you suggested, I have not added type hints in this PR and plan to address them in an upcoming PR.

Please let me know if there's anything else you'd like me to adjust.

@Karanjot786 Karanjot786 requested a review from uniqueg October 9, 2024 13:42
Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

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

Thanks, looks great. One thing before we can merge: Please only include "Raises" sections in functions/methods that explicitly raise errors (most don't). You don't wanna describe errors that the code may implicitly raise, because you'll never see the end of that.

@Karanjot786
Copy link
Member Author

I've updated the docstrings to remove the "Raises" sections from functions and methods that do not explicitly raise exceptions. This should make the documentation cleaner and more focused.

@Karanjot786 Karanjot786 requested a review from uniqueg October 9, 2024 14:51
@Karanjot786 Karanjot786 merged commit 3159337 into main Oct 9, 2024
2 checks passed
@Karanjot786 Karanjot786 deleted the linting-style-changes branch October 9, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants