Skip to content
Merged
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
153 changes: 153 additions & 0 deletions .kiro/specs/black-to-ruff-migration/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Design Document

## Overview

This design outlines the migration from Black and isort to Ruff for the We All Code Django project. Ruff is a fast Python linter and formatter written in Rust that can replace both Black (formatting) and isort (import sorting) with a single tool. The migration will maintain existing code style preferences while consolidating tooling and improving performance.

## Architecture

### Tool Replacement Strategy

The migration follows a direct replacement approach:

- **Black** → **Ruff formatter** (maintains Black-compatible formatting)
- **isort** → **Ruff import sorting** (maintains isort-compatible import organization)

### Configuration Approach

Ruff will be configured in `pyproject.toml` using the `[tool.ruff]` section with subsections for:

- General settings (line length, target Python version, exclusions)
- Formatter settings (`[tool.ruff.format]`)
- Import sorting settings (`[tool.ruff.isort]`)
- Linting rules (`[tool.ruff.lint]`)

## Components and Interfaces

### Configuration Files

#### pyproject.toml Updates

**Rationale**: Centralizing all tool configuration in pyproject.toml follows Python packaging standards and simplifies maintenance.

- Remove `[tool.black]` section
- Remove `[tool.isort]` section
- Add comprehensive `[tool.ruff]` configuration
- Add Ruff as a development dependency in the "# Development & Debugging" section alongside django-debug-toolbar
- Remove Black and isort from dependencies if present

#### Pre-commit Configuration Updates

**Rationale**: Maintaining pre-commit integration ensures code quality checks remain automated and consistent across the development team.

- Replace Black hook (currently using psf/black rev 23.3.0) with Ruff formatter hook
- Replace isort hook (currently using pycqa/isort rev 5.12.0) with Ruff import sorting hook
- Maintain existing exclusion patterns for migrations and .vscode folders
- Keep all other pre-commit hooks unchanged (trailing-whitespace, end-of-file-fixer, etc.)

#### Documentation Updates

**Rationale**: Comprehensive documentation updates ensure all team members and new contributors understand the current tooling and maintain consistency across the project.

- Update `.kiro/steering/tech.md` Code Quality Tools section to reference Ruff instead of Black and isort
- Update `.kiro/steering/structure.md` Development Conventions section to reference Ruff formatting
- Check and update `README.md` if it contains references to Black or isort
- Update any developer setup instructions to include Ruff-specific commands
- Ensure all documentation maintains consistency with Ruff usage

### Ruff Configuration Sections

Based on the current Black and isort configuration, Ruff will be configured as follows:

#### Core Settings

```toml
[tool.ruff]
target-version = "py311"
exclude = [migrations, build artifacts, etc.]
```

#### Import Sorting Settings

**Rationale**: Django-aware import sorting maintains the existing project's import organization patterns while leveraging Ruff's performance benefits. This ensures proper separation of Django imports from other third-party libraries, maintaining the project's existing import organization standards.



## Data Models

No data models are affected by this migration as it only changes development tooling configuration.

## Error Handling

### Migration Validation

- Verify Ruff produces equivalent formatting to Black on existing codebase
- Ensure import sorting maintains Django-aware section organization
- Test pre-commit hooks function correctly with new configuration

### Rollback Strategy

- Keep backup of original Black/isort configuration
- Document steps to revert if issues are discovered
- Maintain git history for easy rollback

## Testing Strategy

### Configuration Testing

1. **Format Consistency Test**: Run Ruff formatter on existing codebase and verify minimal changes
2. **Import Sorting Test**: Verify Ruff import sorting maintains Django section organization
3. **Pre-commit Integration Test**: Test pre-commit hooks with Ruff configuration
4. **Exclusion Pattern Test**: Verify migrations and other excluded files are not processed

### Validation Steps

**Rationale**: These validation steps ensure the migration maintains code quality and formatting consistency while verifying all requirements are met.

1. Install Ruff and configure in pyproject.toml
2. Run `docker compose run --rm app uv run ruff format --check .` on codebase to verify compatibility (respects pyproject.toml settings)
3. Run `docker compose run --rm app uv run ruff check --select I .` to test import sorting (respects pyproject.toml settings)
4. Test pre-commit hooks in containerized environment using `docker compose run --rm app pre-commit run --all-files`
5. Compare output with existing Black/isort formatting to ensure consistency
6. Verify uv commands work correctly with Ruff (addresses Requirement 4.4)
7. Confirm migrations are properly excluded from formatting and linting

### Performance Verification

- Measure formatting speed improvement with Ruff vs Black+isort
- Verify pre-commit hook execution time improvement

## Implementation Considerations

### Dependency Management

**Rationale**: Proper dependency management ensures Ruff is available in all development environments and follows the project's existing organizational patterns.

- Ruff will be added to the "# Development & Debugging" section in pyproject.toml dependencies (addresses Requirement 4.1, 4.3)
- Black and isort configurations will be removed from pyproject.toml (addresses Requirement 4.2)
- uv will handle Ruff installation and version management (addresses Requirement 4.4)
- Ruff will be placed appropriately within the development tools section to maintain logical grouping

### Backward Compatibility

- Ruff's Black-compatible formatter ensures existing code style is maintained
- Django-aware import sorting preserves current import organization
- Line length and exclusion patterns remain unchanged

### Team Adoption

- Developers will need to update their local pre-commit hooks
- IDE integrations may need to be updated to use Ruff instead of Black
- Documentation will guide developers through the transition

## Requirements Traceability

This design addresses all requirements from the requirements document:

**Requirement 1 (Tool Replacement)**: Addressed through pyproject.toml configuration sections that replace Black and isort with Ruff while maintaining migration exclusions, and Django-aware import sorting.

**Requirement 2 (Pre-commit Integration)**: Addressed through pre-commit configuration updates that replace Black and isort hooks with Ruff equivalents while maintaining existing exclusion patterns.

**Requirement 3 (Documentation Updates)**: Addressed through systematic updates to steering documents, README, and developer setup instructions to reflect Ruff usage consistently.

**Requirement 4 (Dependency Management)**: Addressed through adding Ruff to development dependencies and removing Black/isort configurations, with uv handling installation and version management.
52 changes: 52 additions & 0 deletions .kiro/specs/black-to-ruff-migration/requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Requirements Document

## Introduction

This feature involves migrating the We All Code Django project from using Black (code formatter) and isort (import sorter) to Ruff, which is a faster, all-in-one Python linter and formatter that can replace both tools. Ruff provides the same formatting capabilities as Black while also offering linting and import sorting functionality in a single, faster tool.

## Requirements

### Requirement 1: Tool Replacement

**User Story:** As a developer, I want to use Ruff instead of Black and isort, so that I have faster code formatting and linting with a single tool.

#### Acceptance Criteria

1. WHEN the project is configured THEN Ruff SHALL replace Black as the code formatter
2. WHEN the project is configured THEN Ruff SHALL replace isort for import sorting
3. WHEN Ruff is configured THEN it SHALL exclude migrations from formatting (same as current Black config)
4. WHEN Ruff is configured THEN it SHALL maintain Django-aware import sorting sections with proper separation of Django imports from other third-party libraries

### Requirement 2: Pre-commit Integration

**User Story:** As a developer, I want the pre-commit hooks updated to use Ruff, so that code quality checks run automatically before commits.

#### Acceptance Criteria

1. WHEN pre-commit hooks are updated THEN they SHALL use Ruff instead of Black and isort
2. WHEN pre-commit runs THEN it SHALL format code using Ruff
3. WHEN pre-commit runs THEN it SHALL sort imports using Ruff
4. WHEN pre-commit runs THEN it SHALL maintain the same exclusion patterns as before

### Requirement 3: Documentation Updates

**User Story:** As a developer, I want all project documentation updated to reflect the Ruff migration, so that new contributors understand the current tooling and existing developers have accurate reference materials.

#### Acceptance Criteria

1. WHEN documentation is updated THEN .kiro/steering/tech.md SHALL reference Ruff instead of Black and isort in the Code Quality Tools section
2. WHEN documentation is updated THEN .kiro/steering/structure.md SHALL reference Ruff formatting conventions instead of Black
3. WHEN documentation is updated THEN README.md SHALL be updated if it contains references to Black or isort
4. WHEN documentation is updated THEN any developer setup instructions SHALL include Ruff-specific commands
5. WHEN documentation is updated THEN all references to code formatting tools SHALL be consistent with Ruff usage

### Requirement 4: Dependency Management

**User Story:** As a developer, I want Ruff to be added as a project dependency, so that it's available in the development environment.

#### Acceptance Criteria

1. WHEN dependencies are updated THEN Ruff SHALL be added to pyproject.toml
2. WHEN dependencies are updated THEN Black and isort SHALL be removed from dependencies (if present)
3. WHEN Ruff is added THEN it SHALL be in the appropriate dependency group for development tools
4. WHEN the configuration is complete THEN Ruff SHALL be usable via uv commands
66 changes: 66 additions & 0 deletions .kiro/specs/black-to-ruff-migration/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Implementation Plan

- [x] 1. Configure Ruff in pyproject.toml

- Remove existing [tool.black] and [tool.isort] configuration sections
- Add comprehensive [tool.ruff] configuration with general settings (target-version = "py311", exclude migrations)
- Add Ruff as a development dependency in the "# Development & Debugging" section alongside django-debug-toolbar
- Add [tool.ruff.lint] section with comprehensive linting rules
- _Requirements: 1.1, 1.2, 1.3, 1.4, 1.5, 4.1, 4.2, 4.3, 4.4_

- [x] 2. Update pre-commit configuration

- Replace Black hook (psf/black) with Ruff formatter hook (charliermarsh/ruff-pre-commit)
- Replace isort hook (pycqa/isort) with Ruff import sorting hook using ruff-check
- Maintain existing exclusion patterns for migrations and .vscode folders
- Keep all other pre-commit hooks unchanged (trailing-whitespace, end-of-file-fixer, etc.)
- _Requirements: 2.1, 2.2, 2.3, 2.4_

- [x] 3. Update documentation files
- [x] 3.1 Update .kiro/steering/tech.md

- Replace Black and isort references with Ruff in Code Quality Tools section
- Update tool descriptions to reflect Ruff's combined formatting and linting capabilities
- _Requirements: 3.1, 3.6_

- [x] 3.2 Update .kiro/steering/structure.md

- Replace Black formatter references with Ruff in Development Conventions section
- Update code style documentation to reference Ruff instead of Black and isort
- Maintain Django-aware import sorting documentation
- _Requirements: 3.2, 3.6_

- [x] 3.3 Check and update README.md if needed

- Search for any references to Black or isort in README.md (none found)
- Update developer setup instructions to include Ruff-specific commands if present (none needed)
- Ensure consistency with Ruff usage throughout documentation
- _Requirements: 3.3, 3.4, 3.5_

- [-] 4. Enhance Ruff configuration for complete migration
- [ ] 4.1 Complete pyproject.toml Ruff configuration

- Add exclude patterns for migrations and other directories
- Add [tool.ruff.isort] section with Django-aware import sorting (known-django, section-order, combine-as-imports)
- _Requirements: 1.1, 1.2, 1.3, 1.4, 1.5_

- [x] 5. Test Ruff configuration
- [x] 5.1 Validate formatting compatibility

- Run `docker compose run --rm app uv run ruff format --check .` on existing codebase to verify minimal changes
- Compare Ruff output with current formatting to ensure consistency
- Verify migrations are excluded from formatting (configured in pyproject.toml)
- _Requirements: 1.1, 1.3, 1.4_

- [x] 5.2 Validate import sorting

- Run `docker compose run --rm app uv run ruff check --select I .` to test import sorting functionality
- Verify Django-aware section organization is maintained
- Test that import sorting follows isort-compatible behavior using `docker compose run --rm app uv run ruff check --select I --fix .`
- _Requirements: 1.2, 1.5_

- [x] 5.3 Test pre-commit integration
- Run `docker compose run --rm app pre-commit run --all-files` to test pre-commit hooks in containerized environment
- Test that Ruff hooks execute correctly and maintain exclusion patterns
- Verify pre-commit performance improvement with Ruff using `docker compose run --rm app pre-commit run ruff-format ruff-check`
- _Requirements: 2.1, 2.2, 2.3, 2.4_
4 changes: 2 additions & 2 deletions .kiro/steering/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ Extends django-allauth for custom authentication:

### Code Style

- Black formatter with 79 character line length
- isort for import organization with Django-aware sections
- Ruff formatter and linter with 79 character line length
- Ruff import sorting with Django-aware sections
- Migrations excluded from formatting

### Database
Expand Down
3 changes: 1 addition & 2 deletions .kiro/steering/tech.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

## Code Quality Tools

- **Black** - Code formatter (line length: 79)
- **isort** - Import sorting with Black profile
- **Ruff** - Fast Python linter and formatter with import sorting
- **django-nose** - Test runner

## Common Commands
Expand Down
41 changes: 22 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
exclude: "^docs/|/migrations/|devcontainer.json"
default_stages: [pre-commit]
minimum_pre_commit_version: "3.2.0"

default_language_version:
python: python3.11

# Ignore all 'migration' folders and .vscode folder
exclude: '^(\.vscode\/?)|(.*\/migrations\/.*)$'

repos:
# pre-commit hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v5.0.0
hooks:
- id: no-commit-to-branch
args: [--branch, main]
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: detect-private-key
- id: no-commit-to-branch
args: [--branch, main]
- id: check-added-large-files
- id: check-merge-conflict
- id: detect-private-key
- id: mixed-line-ending
args: [--fix=lf]

# isort
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

# black
- repo: https://github.com/psf/black
rev: 23.3.0
# Run the Ruff linter.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.5
hooks:
- id: black
args: [--preview]
# Linter
- id: ruff-check
args: [--fix, --exit-non-zero-on-fix]
# Formatter
- id: ruff-format
8 changes: 3 additions & 5 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django.conf.urls import include
from django.urls import path

from .views import (
AccountHomeView,
LoginView,
SignupView,
)
from .views import AccountHomeView
from .views import LoginView
from .views import SignupView

urlpatterns = [
path("", AccountHomeView.as_view(), name="account_home"),
Expand Down
Loading