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.21.tar.gz (26.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.21-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spyq-0.1.21.tar.gz
  • Upload date:
  • Size: 26.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.21.tar.gz
Algorithm Hash digest
SHA256 23a4efc023c8207b8d9766264dce029ae73c75e65147b8ffcc2f50d6688a7c05
MD5 ce5969a23aaaf71bf4e49ae6746cd42e
BLAKE2b-256 f51cc94bb936cbea8c1abca5ece711ca208b57eb8a7530f4ad9dd6cd0848dd7c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spyq-0.1.21-py3-none-any.whl
  • Upload date:
  • Size: 29.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.21-py3-none-any.whl
Algorithm Hash digest
SHA256 d8e347ad91b4acc61762995261429d1c792e80359601cba27681fe22302e3b26
MD5 38d2f4b2f048a1a6a19e7a955ac38f4a
BLAKE2b-256 b9817e5404c446699eb42bfd7f33da12a74f897342cf936426fb780cacfbf811

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