You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maintaining code quality and consistency is crucial in collaborative projects like Ersilia. I am inspired by the recent ersilia codebase formatting using black by @DhanshreeA and this issue aims to make it more robust, also contributor focused and easy. It will also isort(supported built in by ruff not need to install) alongside Ruff ensures our Python imports are logically grouped and consistently ordered, improving readability and reducing merge conflicts. So in the end we hope for this:
Enforce coding standards with minimal manual intervention.
Automate linting, formatting, and import sorting in a unified workflow.
Ensure that contributors stick to the project's conventions, reducing review cycles.
Why Ruff?
Ruff is a fast(x21 faster than the best linter autoflake), all-in-one tool for Python linting and formatting. It consolidates multiple tools like Pyflakes, Pycodestyle, black and isort into a single solution.
Integration Plan
High-level ruff.toml configs:
Two files, ruff.toml and .pre-commit-config.yaml will be created at project root. In the ruff.toml file includes key configurations:
General Settings
Line length: Set to 88 characters (default for PEP 8).
Indent width: Use 4 spaces for Pythonic consistency.
Target Python version: Configured for Python 3.10.
Linting Rules
Focus on common error and style codes like E (errors), F (Pyflakes), and W (warnings).
Enable additional checks for unused variables, annotations, and import sorting.
Configure per-file ignores for test files and specific rules that may not apply globally.
Formatting Preferences
Use double quotes for strings.
Enable trailing commas for better diff readability.
Configure imports with logical grouping (FUTURE, STDLIB, THIRDPARTY, etc.). Relative import sorting in Ersilia case.
Set Up Pre-commit Hooks:
In the second file .pre-commit-config.yaml its going to be configured which ensures a easy and comprehensive workflow for linting and fixing issues with Ruff. It includes safe fixes for automated enforcement and an option for more advanced, potentially unsafe fixes during manual runs which in our case both are included.
To integrate Ruff linting into the CI/CD pipeline, the following two options are proposed:
Option 1: Create a New Workflow File
A new file named .github/workflows/lint.yml can be created to handle Ruff linting independently. This workflow will be triggered on push and pull_request events, ensuring code quality checks are run separately from existing workflows.
Option 2: Integrate Ruff Linting into pr_check.yml
Ruff can be added to the existing pr_check.yml workflow, executed before the current steps. This approach consolidates all validation steps, ensuring code is linted and validated in the same workflow.
Overview
Maintaining code quality and consistency is crucial in collaborative projects like Ersilia. I am inspired by the recent ersilia codebase formatting using
black
by @DhanshreeA and this issue aims to make it more robust, also contributor focused and easy. It will alsoisort
(supported built in by ruff not need to install) alongsideRuff
ensures our Python imports are logically grouped and consistently ordered, improving readability and reducing merge conflicts. So in the end we hope for this:Why Ruff?
Ruff is a fast(x21 faster than the best linter autoflake), all-in-one tool for Python linting and formatting. It consolidates multiple tools like Pyflakes, Pycodestyle, black and isort into a single solution.
Integration Plan
ruff.toml
configs:Two files,
ruff.toml
and.pre-commit-config.yaml
will be created atproject root
. In theruff.toml
file includes key configurations:General Settings
Linting Rules
E
(errors),F
(Pyflakes), andW
(warnings).Formatting Preferences
FUTURE
,STDLIB
,THIRDPARTY
, etc.). Relative import sorting in Ersilia case.In the second file
.pre-commit-config.yaml
its going to be configured which ensures a easy and comprehensive workflow for linting and fixing issues withRuff
. It includes safe fixes for automated enforcement and an option for more advanced, potentially unsafe fixes during manual runs which in our case both are included.To integrate Ruff linting into the CI/CD pipeline, the following two options are proposed:
Option 1: Create a New Workflow File
A new file named
.github/workflows/lint.yml
can be created to handle Ruff linting independently. This workflow will be triggered onpush
andpull_request
events, ensuring code quality checks are run separately from existing workflows.workflow samples:
Option 2: Integrate Ruff Linting into
pr_check.yml
Ruff can be added to the existing
pr_check.yml
workflow, executed before the current steps. This approach consolidates all validation steps, ensuring code is linted and validated in the same workflow.Modification to
pr_check.yml
:Provide clear instructions for contributors to install and use these tools.
High-level Contributor Guide
Install Dependencies:
Install the required tools using pip:
Activate Pre-commit Hooks:
Initialize the pre-commit hooks after cloning the repository:
During Development:
Ruff
will automatically:isort
.Manual Usage:
To manually lint, format, or sort imports, run:
ruff check . --fix
or unsafe mode
ruff check . --fix --unsafe-fixes
Commit and Push Changes:
Resolve all issues, then commit and push your code.
References
Objective(s)
The text was updated successfully, but these errors were encountered: