-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem Description
The project currently relies on manual execution of code quality tools like black, isort, and mypy, or on checks performed late in the development cycle by the CI pipeline. This workflow has several drawbacks:
- It introduces a risk of inconsistent code formatting and style across the codebase.
- Developers might forget to run these checks locally, leading to unnecessary CI failures that could have been caught earlier.
- It adds cognitive load, as contributors must manually ensure their code adheres to all project standards before pushing changes.
Proposed Solution
Integrate pre-commit, a framework for managing and maintaining multi-language pre-commit hooks. This will automate code formatting, import sorting, and static type checking, ensuring these checks are performed automatically before any code is committed.
By enforcing these standards locally and automatically, we can improve code quality, streamline the development workflow, and reduce CI pipeline noise.
Alternative Solutions
- Rely solely on CI: Continue with the current approach where the CI pipeline is the only enforcer of code quality. This is less efficient as it catches issues late and requires developers to push fixes for minor formatting or type errors.
- Use Git Hooks Manually: Developers could set up their own local Git hooks. This approach is not scalable, is difficult to enforce consistently across all contributors, and requires manual setup for each developer.
Given the drawbacks of the alternatives, integrating pre-commit is the most effective and standard solution for a collaborative project.
Additional Context
- This feature will improve the development experience for all current and future contributors.
- It helps enforce the coding style guidelines defined in
pyproject.tomlautomatically. - A successful implementation will involve an initial, one-time run of the hooks across the entire codebase to establish a consistent baseline.
Implementation Details
- Add Dependency: Add
pre-committo thedevgroup in the project'spyproject.tomloptional dependencies. - Create Config File: Create a
.pre-commit-config.yamlfile in the project root. - Configure Hooks: Configure the repositories and hooks for the following tools:
pre-commit-hooks: For basic checks liketrailing-whitespace,end-of-file-fixer,check-yaml, andcheck-toml.black: For code formatting.isort: For import sorting.mypy: For static type checking.
- Install Hooks: Instruct developers to run
pre-commit installonce to set up the git hook scripts in their local repository. - Initial Run: Perform a one-time execution across all files with
pre-commit run --all-filesto apply formatting and fix issues project-wide. This will be part of the implementation PR. - Update Documentation: Add a section to
CONTRIBUTING.mddetailing thepre-commitsetup and explaining its purpose to new contributors.
Guidelines
- I agree to follow this project's Contributing Guidelines
- I have searched for similar feature requests
- I understand that this is a request and implementation is not guaranteed
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request