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.20.tar.gz (26.4 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.20-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spyq-0.1.20.tar.gz
  • Upload date:
  • Size: 26.4 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.20.tar.gz
Algorithm Hash digest
SHA256 dc50ae370584bca9e32ccbdd6a0de157b66cedabb5f672051059ecf9b6a17058
MD5 e8b328e8b4aab9644ac6fcdf5658740a
BLAKE2b-256 814f6c40f89011d0f3629e97d764fcfaf75306efaa16b90178004d9c0b638609

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spyq-0.1.20-py3-none-any.whl
  • Upload date:
  • Size: 29.1 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.20-py3-none-any.whl
Algorithm Hash digest
SHA256 2ae2c643d45833f6321285af5554774f0959094254dac918ea91372467562c9b
MD5 68bfaf000d04fa75c688f8fb762d2877
BLAKE2b-256 6f400ebf833a2fc2b90e2a13ddda25e158d8aac6b68833dbb19a8e0dfd5382a5

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