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

Uploaded Python 3

File details

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

File metadata

  • Download URL: spyq-0.1.7.tar.gz
  • Upload date:
  • Size: 24.3 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.7.tar.gz
Algorithm Hash digest
SHA256 022842d681aa4a109c9fc5fdcda8bf16cba387843251f96c1afe8cff1d49e6a1
MD5 4edf04992073e6ac51752bed2027b4f5
BLAKE2b-256 3b1a69f04aa2d9a4ca916e4b73bc0ff59df5c8d4642363e12924aadc0cfab1d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spyq-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 26.2 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ae459e32f93c96a6c6ef587aa420db4341c8f7ebb918536896cfae049b414ee1
MD5 2806f859aa42c1ef0d7afdb595c5fad7
BLAKE2b-256 206b0faae92476829e48a45d8b1abce23f34f96f4d178a614e6a9866da5f0c8b

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