A comprehensive quality assurance CLI for enforcing strict Python code standards.
Python Enforcer is a command-line tool that wraps industry-standard static analysis tools with curated, strict configurations. It ensures code quality, security, and maintainability by providing a unified interface to run these checks.
- Centralized Configuration: Bundles strict configurations for all supported tools, ensuring consistency across projects.
- Unified Interface: Run multiple quality checks using a single command-line tool.
- Tool Suite: Integrates six specialized tools:
- Ruff: Linting and formatting.
- Mypy: Static type checking.
- Pylint: Code analysis.
- Bandit: Security linting.
- Semgrep: Static analysis for security and bugs.
- Vulture: Dead code detection.
Install pyenforce from PyPI (or from source) with the dependencies you need.
Installs only the CLI runner. You must install the underlying tools (like ruff or mypy) separately or have them in your environment.
pip install pyenforceInstall pyenforce along with specific tools you plan to use.
# Install with Ruff
pip install "pyenforce[ruff]"
# Install with Mypy
pip install "pyenforce[mypy]"
# Install with multiple tools
pip install "pyenforce[ruff,mypy]"Install the CLI and the complete suite of supported tools.
pip install "pyenforce[all]"Run any of the supported tools using the pye command followed by the tool name:
pye <tool> [args...]| Tool | Command | Purpose |
|---|---|---|
| Ruff | pye fmt |
Code formatter for consistent code style. |
| Ruff | pye ruff |
Lightning-fast linter covering style, complexity, and imports. |
| Mypy | pye mypy |
Verifies type hints and catches type errors. |
| Pylint | pye pylint |
Analyzes code quality and design patterns. |
| Bandit | pye bandit |
Detects common security vulnerabilities. |
| Semgrep | pye semgrep |
Advanced pattern matching for bugs and security issues. |
| Vulture | pye vulture |
Identifies unused code. |
Run a specific tool (e.g., Ruff):
pye ruffPass additional arguments (e.g., run Mypy on a specific directory):
pye mypy src/To use pyenforce with pre-commit, add the following to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/HH-MWB/pyenforce
rev: v0.1.0
hooks:
- id: ruff-format
- id: ruff-check
- id: mypy
- id: pylint
- id: bandit
- id: semgrep
- id: vultureIf you need to add extra dependencies (e.g., plugins) to a hook using additional_dependencies in your .pre-commit-config.yaml, you must re-include the base dependency. pre-commit overwrites the list instead of merging it.
Example: Adding a plugin to pylint:
- repo: https://github.com/HH-MWB/pyenforce
rev: v0.1.0
hooks:
- id: pylint
additional_dependencies:
- ".[pylint]" # Required: Re-adds Pylint
- "pylint-django" # Your extra dependencyThis repository is licensed under the MIT License.