Skip to main content

A pre-commit hook for running Python tools in multiple Pipenv environments

Project description

pipenv-tools-hook

A pre-commit hook for running Python tools (like ruff, mypy, etc.) in multiple Pipenv environments within a monorepo or multi-project repository structure.

Overview

This tool solves the common problem of running Python code quality tools in repositories with multiple Python projects, each with its own Pipenv environment and tooling requirements. It automatically:

  • Discovers Pipenv environments in your repository
  • Groups files by their closest controlling Pipenv environment
  • Runs specified tools (like ruff, mypy) using the appropriate Pipenv environment for each file

Features

  • 🔍 Automatic Pipenv environment discovery
  • 🗂️ Smart file-to-environment mapping
  • 🛠️ Support for any Pipenv-installed tool (ruff, mypy, pylint, etc.)
  • 🔄 Seamless integration with pre-commit
  • 📁 Works with monorepos and multi-project repositories

Installation

pip install pipenv-tools-hook

Usage

  1. Add the hook to your .pre-commit-config.yaml:
repo: https://github.com/yourusername/pipenv-tools-hook
rev: v0.1.0 # Use the latest version
hooks:
id: pipenv-tools
name: Run Python tools in Pipenv environments
args: ['--tool=ruff'] # Specify which tool to run
  1. Ensure each project directory that needs code quality checks has:
    • A Pipfile with the required tools installed
    • Appropriate tool configuration files (e.g., pyproject.toml, setup.cfg)

Example repository structure:

my-monorepo/
├── .pre-commit-config.yaml
├── project1/
│ ├── Pipfile
│ ├── pyproject.toml
│ ├── src/
│ │ └── main.py
│ └── tests/
│ └── test_main.py
└── project2/
├── Pipfile
├── pyproject.toml
└── app.py

Configuration

The hook accepts the following arguments:

  • --tool: (Required) The Python tool to run (e.g., ruff, mypy, pylint)
  • --args: (Optional) Additional arguments to pass to the tool

Example configurations:

# Run ruff linter
- id: pipenv-tools
  args: ['--tool=ruff', '--args=--fix']
# Run mypy type checker
- id: pipenv-tools
  args: ['--tool=mypy', '--args=--strict']
# Run pylint
- id: pipenv-tools
  args: ['--tool=pylint']

How It Works

  1. When the hook runs, it:
    • Scans the repository for Pipfiles
    • Maps each Python file to its controlling Pipenv environment
    • Groups files by environment
  2. For each environment:
    • Changes to the appropriate directory
    • Runs the specified tool using pipenv run
    • Reports any issues found

Requirements

  • Python ≥ 3.8
  • pipenv ≥ 2023.0
  • pre-commit ≥ 2.9.0

Development

To set up the development environment:

  1. Clone the repository:
git clone https://github.com/yourusername/pipenv-tools-hook.git
cd pipenv-tools-hook
  1. Install development dependencies:
pip install hatch
  1. Run tests:
hatch run test
  1. Run type checking:
hatch run typecheck
  1. Run linting:
hatch run lint

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Here's how you can contribute:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run the test suite
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Please make sure your PR includes:

  • A clear description of the changes
  • Updates to documentation if needed
  • New tests for new functionality

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pipenv_tools_hook-0.1.3.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pipenv_tools_hook-0.1.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pipenv_tools_hook-0.1.3.tar.gz.

File metadata

  • Download URL: pipenv_tools_hook-0.1.3.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pipenv_tools_hook-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0ebb52e7ed563a8e7717979ad3baa76e4aacb4f549c2bd1d5ae027361544f06b
MD5 0ecb2249420a0137dbf31f0035f62406
BLAKE2b-256 d832052585aec27ae302253015ed0506f754cc3343de1d5255bd8aa1cc672373

See more details on using hashes here.

Provenance

The following attestation bundles were made for pipenv_tools_hook-0.1.3.tar.gz:

Publisher: main.yml on macieyng/pipenv-tools-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pipenv_tools_hook-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pipenv_tools_hook-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a6d932c06ec3eed4b9695d8494efe5a65218a01a2e9e6f400b2207b0fd0b4779
MD5 a497d0a304ca409a7dbd22252716d3ab
BLAKE2b-256 4708f3aec04681dd0e1f027f6984e52024adc65790cf7416785c62ee61a50c06

See more details on using hashes here.

Provenance

The following attestation bundles were made for pipenv_tools_hook-0.1.3-py3-none-any.whl:

Publisher: main.yml on macieyng/pipenv-tools-hook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page