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
- 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
- Ensure each project directory that needs code quality checks has:
- A
Pipfilewith the required tools installed - Appropriate tool configuration files (e.g.,
pyproject.toml,setup.cfg)
- A
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
- When the hook runs, it:
- Scans the repository for
Pipfiles - Maps each Python file to its controlling Pipenv environment
- Groups files by environment
- Scans the repository for
- 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:
- Clone the repository:
git clone https://github.com/yourusername/pipenv-tools-hook.git
cd pipenv-tools-hook
- Install development dependencies:
pip install hatch
- Run tests:
hatch run test
- Run type checking:
hatch run typecheck
- Run linting:
hatch run lint
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. Here's how you can contribute:
- Fork the repository
- Create a new branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run the test suite
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ebb52e7ed563a8e7717979ad3baa76e4aacb4f549c2bd1d5ae027361544f06b
|
|
| MD5 |
0ecb2249420a0137dbf31f0035f62406
|
|
| BLAKE2b-256 |
d832052585aec27ae302253015ed0506f754cc3343de1d5255bd8aa1cc672373
|
Provenance
The following attestation bundles were made for pipenv_tools_hook-0.1.3.tar.gz:
Publisher:
main.yml on macieyng/pipenv-tools-hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pipenv_tools_hook-0.1.3.tar.gz -
Subject digest:
0ebb52e7ed563a8e7717979ad3baa76e4aacb4f549c2bd1d5ae027361544f06b - Sigstore transparency entry: 168511115
- Sigstore integration time:
-
Permalink:
macieyng/pipenv-tools-hook@f48820969c003a961afcf7442b95b1ae21f4268b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/macieyng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@f48820969c003a961afcf7442b95b1ae21f4268b -
Trigger Event:
push
-
Statement type:
File details
Details for the file pipenv_tools_hook-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pipenv_tools_hook-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6d932c06ec3eed4b9695d8494efe5a65218a01a2e9e6f400b2207b0fd0b4779
|
|
| MD5 |
a497d0a304ca409a7dbd22252716d3ab
|
|
| BLAKE2b-256 |
4708f3aec04681dd0e1f027f6984e52024adc65790cf7416785c62ee61a50c06
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pipenv_tools_hook-0.1.3-py3-none-any.whl -
Subject digest:
a6d932c06ec3eed4b9695d8494efe5a65218a01a2e9e6f400b2207b0fd0b4779 - Sigstore transparency entry: 168511124
- Sigstore integration time:
-
Permalink:
macieyng/pipenv-tools-hook@f48820969c003a961afcf7442b95b1ae21f4268b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/macieyng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@f48820969c003a961afcf7442b95b1ae21f4268b -
Trigger Event:
push
-
Statement type: