SPYQ - Shell Python Quality Guard
Project description
๐ก๏ธ SPYQ - Shell Python Quality Guard
SPYQ is a powerful quality guard system that automatically validates Python code before execution. It ensures your code meets quality standards before it runs, preventing technical debt and maintaining high code quality across your projects.
๐ Table of Contents
- โจ Features
- ๐ Quick Start
- โ๏ธ Configuration
- ๐ฆ Advanced Usage
- ๐๏ธ Project Structure
- ๐งช Development Setup
- ๐ Troubleshooting
- ๐ License
- ๐ Acknowledgments
โจ Features
- ๐ Automatic Validation - Validates Python scripts before execution
- ๐ก๏ธ Zero Configuration - Works out of the box with sensible defaults
- โก Seamless Integration - No changes to your workflow needed
- ๐ง Configurable - Customize rules via
spyq.json - ๐ Detailed Feedback - Clear error messages with line numbers
- ๐ CI/CD Ready - Perfect for automated pipelines
- ๐ณ Docker Compatible - Works in containerized environments
- ๐งช Tested - Comprehensive test coverage
- ๐ Documented - Clear documentation and examples
๐ Quick Start
1. Install SPYQ
# Install from PyPI
pip install spyq
2. Run Python Scripts with Validation
# Run any Python script with automatic validation
python your_script.py
# Or use the explicit command
python -m spyq your_script.py
# Disable validation if needed
SPYQ_DISABLE=1 python your_script.py
3. Initialize Configuration
# Create a project-level config
spyq init --project
# Create a user-level config
spyq init --user
โ๏ธ Configuration
SPYQ uses a spyq.json configuration file to define validation rules. You can create one in your project root or in your home directory (~/.config/spyq/config.json).
Default Configuration
{
"version": "1.0.0",
"rules": {
"max_file_lines": 300,
"max_function_lines": 50,
"max_function_params": 4,
"max_nesting_depth": 4,
"require_docstrings": true,
"require_type_hints": true,
"forbid_global_vars": true,
"forbid_bare_except": true,
"forbid_print_statements": false
}
}
Available Rules
| Rule | Default | Description |
|---|---|---|
max_file_lines |
300 | Maximum lines per file |
max_function_lines |
50 | Maximum lines per function |
max_function_params |
4 | Maximum parameters per function |
max_nesting_depth |
4 | Maximum nesting depth |
require_docstrings |
true | Require docstrings |
require_type_hints |
true | Require type hints |
forbid_global_vars |
true | Forbid global variables |
forbid_bare_except |
true | Forbid bare except clauses |
forbid_print_statements |
false | Forbid print statements |
๐ฆ Advanced Usage
Manual Validation
# Validate a single file
spyq validate path/to/script.py
# Validate a directory
spyq validate path/to/directory
# Validate with strict mode (warnings become errors)
spyq validate --strict script.py
Integration with IDEs
Most IDEs allow you to configure the Python interpreter. You can set it to use SPYQ:
- VS Code: Update
python.pythonPathin settings - PyCharm: Set up a custom Python interpreter pointing to SPYQ
- Vim/Neovim: Use
:set makeprg=python\ -m\ spyq\ %
๐๏ธ Project Structure
spyq/
โโโ src/
โ โโโ spyq/
โ โโโ __init__.py
โ โโโ __main__.py # Main entry point
โ โโโ validator.py # Core validation logic
โ โโโ config.py # Configuration management
โ โโโ imphook.py # Import hook for validation
โ โโโ scripts/
โ โโโ spyq-python # Python wrapper script
โโโ tests/ # Test files
โโโ examples/ # Example scripts
โ โโโ bad_script.py # Example with issues
โ โโโ good_script.py # Example following best practices
โโโ pyproject.toml # Project configuration
โโโ README.md # This file
๐งช Development Setup
Install from Source
git clone https://github.com/wronai/quality.git
cd quality/spyq
pip install -e .[dev] # Install with development dependencies
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=spyq --cov-report=term-missing
# Run specific test file
pytest tests/test_validator.py -v
Code Quality Checks
# Run linter
flake8
# Format code with black
black .
# Sort imports
isort .
# Type checking
mypy .
๐ Troubleshooting
Common Issues
Import Errors
# If you get import errors, try reinstalling in development mode
pip install -e .
Permission Issues
# Make sure scripts are executable
chmod +x spyq/scripts/*
Debugging
# Enable debug output
SPYQ_DEBUG=1 python -m spyq script.py
# Or set the log level
import logging
logging.basicConfig(level=logging.DEBUG)
๐ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
๐ Acknowledgments
- Thanks to all contributors who have helped improve SPYQ
- Inspired by various Python quality tools and linters
- Built with โค๏ธ by the Wronai team
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 spyq-0.1.14.tar.gz.
File metadata
- Download URL: spyq-0.1.14.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a67e3b66f64976a59a2989de83c19e0f3a47d768d8a3cb12e1237cd1f7887389
|
|
| MD5 |
47ed4cd1ae2a512a346a893281b7454c
|
|
| BLAKE2b-256 |
531592b2cbb61308e1050b06fe96ac640c4eb46460634de5aa217a14da0b857c
|
File details
Details for the file spyq-0.1.14-py3-none-any.whl.
File metadata
- Download URL: spyq-0.1.14-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91ce1f947efb4239820729cb745bc2d00ba1a5e38afca2607a683531faa063e6
|
|
| MD5 |
ed77744ca8eb7062d3e87497a63a4b49
|
|
| BLAKE2b-256 |
ebbd1e84aae90852b8d7ecd3395633460c08d5dc191a1fd68e0f2549195d4d71
|