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.0.tar.gz (8.2 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.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pipenv_tools_hook-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 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.0.tar.gz
Algorithm Hash digest
SHA256 d2bfbdaddea32327ddf0268b3349ae24bd17b8a173b1e27223e15e56e83476b1
MD5 cd2996fdafa29b0931ee48ab6ebe1a18
BLAKE2b-256 ab8178463032cddee03c11e0ccb15066cb653a635ecbfc02f50a986ae456b4cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pipenv_tools_hook-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pipenv_tools_hook-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b96c180f34a0fc46ff9459aea808a47e37ac02e63419150d0ad68255938cc31
MD5 47ac08d0ef05bd921a1266534afbd513
BLAKE2b-256 cc27afc07e7e813cbb358cbd082484e9604ea772e321ea5d69349fac2e2f3369

See more details on using hashes here.

Provenance

The following attestation bundles were made for pipenv_tools_hook-0.1.0-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