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.12.tar.gz (25.6 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.12-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spyq-0.1.12.tar.gz
  • Upload date:
  • Size: 25.6 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.12.tar.gz
Algorithm Hash digest
SHA256 9724d040d23d5779a6ea4bcf3d90007cfe29ae731238e9535a27e45efa9a28f0
MD5 25df26165ef4396d96bbfa1e1ae20413
BLAKE2b-256 df7d69dc2d3d82617e2148164b9733d9046dde5a6ebb31ef29cbea7e9649125b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spyq-0.1.12-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

Hashes for spyq-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 b3b08d3569dce27fdceccc8038cc61347d2d749f54c0fbcb97c5cb821eb7c90d
MD5 1a08e6a9c8b31a412fc029fc583a1531
BLAKE2b-256 199c8a062f91e24696aff01481513ff010615c1587ab9f6f0b8a497409cd3c58

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