Skip to content

Switch pre-commit hooks to use repo: local for Python tools #131

@hillairet

Description

@hillairet

🔭 Task Overview

Modify the copier template to conditionally generate pre-commit configuration based on whether the user wants to use Nix for dependency management. When Nix is enabled, use repo: local for Python development tools to ensure consistency with Nix-managed versions. When Nix is not used, keep the current remote repository configuration.

🎯 Objectives

  • Add a copier template variable to determine if Nix dependency management is desired
  • Generate two different pre-commit configurations based on this choice:
    • With Nix: Use repo: local for black, isort, ruff, and bandit
    • Without Nix: Keep current remote repo configuration with version pins
  • Ensure both configurations maintain the same functionality and arguments

🔬 Steps or Implementation Details

  1. Add copier template variable: Create a boolean variable (e.g., use_nix_deps) in the copier configuration to ask users about Nix dependency management

  2. Template the pre-commit config: Modify .pre-commit-config.yaml.jinja (or similar) to conditionally generate:

    • If use_nix_deps = true: Convert black, isort, ruff, bandit to local hooks
    • If use_nix_deps = false: Keep existing remote repo configuration
  3. Configure local hooks section: For Nix users, generate:

    - repo: local
      hooks:
        - id: black
          name: black
          entry: black
          language: system
          types: [python]
        - id: isort
          name: isort
          entry: isort
          language: system
          types: [python]
          args: ["--profile", "black", "--filter-files"]
        - id: ruff-check
          name: ruff-check
          entry: ruff check
          language: system
          types: [python]
          args: ["--ignore", "E501", "--extend-select", "E,W"]
        - id: bandit
          name: bandit
          entry: bandit
          language: system
          types: [python]
          args: ["-ll"]
  4. Test both configurations: Verify that both generated configurations work correctly in their respective environments

📝 Additional context (Optional)

This approach allows users to choose their preferred dependency management strategy while ensuring tool version consistency within each approach. Users who opt for Nix will get the benefits of unified tool versions, while users who prefer traditional Python dependency management can continue with the current setup.

The template should clearly explain the trade-offs between the two approaches during the copier questionnaire.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions