Skip to main content

SPYQ - Shell Python Quality Guard

Project description

๐Ÿ›ก๏ธ 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

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

spyq-0.1.29.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spyq-0.1.29-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file spyq-0.1.29.tar.gz.

File metadata

  • Download URL: spyq-0.1.29.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for spyq-0.1.29.tar.gz
Algorithm Hash digest
SHA256 eb6abdb5ca251b2a960ac340dc6108d3da2a343a848b1bc5122c222d9b4f093a
MD5 afefbd6de4ed4de3cd400c6e3a44331f
BLAKE2b-256 eb985b040156d0cda069c79c7f48fbda55fc7d8b706812ecd3474dd276512e71

See more details on using hashes here.

File details

Details for the file spyq-0.1.29-py3-none-any.whl.

File metadata

  • Download URL: spyq-0.1.29-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for spyq-0.1.29-py3-none-any.whl
Algorithm Hash digest
SHA256 5e4770fedd1756737b00a19b747115d73b546cb07e73e0418340b495ff1aa2b7
MD5 752df1237e1e8a137399c9160019e008
BLAKE2b-256 63448a94c83689b3f72efe1c567749e0f2f89040620e64d16b984114933f8ef7

See more details on using hashes here.

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