Skip to main content

🛡️ SPYQ - Shell Python Quality Guard

License Python Version Code style: black Documentation

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

  • 🚀 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:

  1. VS Code: Update python.pythonPath in settings
  2. PyCharm: Set up a custom Python interpreter pointing to SPYQ
  3. 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

Metadata

Release files for spyq 0.1.32

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spyq 0.1.32
File Size Uploaded
spyq-0.1.32.tar.gz 26.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spyq 0.1.32
File Interpreter ABI Platform
spyq-0.1.32-py3-none-any.whl Python 3 none any Details

Total release size: 56.7 kB

Release files / spyq-0.1.32.tar.gz

Download URL spyq-0.1.32.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ec19065bdc8223e4391f77c28ade907bb5509a851e0b50aafca3c668ff8138c2
BLAKE2b-256 checksum
How to use checksums
ef838444ce29c45504ecb22b08bd9c7e35f17a0e9f3f9f9fc0dd27e2c6e12d18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / spyq-0.1.32-py3-none-any.whl

Download URL spyq-0.1.32-py3-none-any.whl
Size 29.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9439ce695ea67839778b74f490cda9d75cca1812597d0698d831ce4632f6d121
BLAKE2b-256 checksum
How to use checksums
b24c46e2e9cc9ad88e13c6e3479ebe860cf4ed65a5683923e9b82de80316222e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.1.32 This release

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page