Files
Reithan-negative_rejection_…/CONTRIBUTING.md
T
Reithan ee6dc40393 Add git hooks and development infrastructure (#32)
## Summary

Establishes a complete development infrastructure for the project with
automated quality checks, testing, and contributor guidelines.

- Add pre-commit hooks for automated linting and quality checks
- Configure ruff for code linting and formatting (120 char line length,
Python 3.10+)
- Set up pytest with mocked torch/gradio dependencies for CI/CD
compatibility
- Create comprehensive CONTRIBUTING.md with setup instructions and
workflow guidance
- Add uv.lock for reproducible dependency resolution
- Replace trivial tests with functional interface tests

## Key Components

### Git Hooks (.pre-commit-config.yaml)
- Pre-commit: ruff linting/formatting, trailing whitespace, YAML
validation, prevents direct commits to main
- Pre-push: runs pytest test suite, prevents direct pushes to main

### Testing (tests/)
- Functional tests for ComfyUI node and WebUI script interfaces
- Mock torch, gradio, and WebUI modules via conftest.py (no heavy
dependencies in dev env)
- Tests verify API contracts without requiring full ComfyUI/WebUI
runtime

### Documentation (CONTRIBUTING.md)
- Development setup with uv package manager
- Git workflow and branch protection guidelines
- Linting, testing, and pre-commit hook usage
- Code style guidelines and commit message conventions

## Test Plan

- [x] Pre-commit hooks run on commit (linting, formatting, checks)
- [x] Pre-push hooks run pytest successfully
- [x] All tests pass in isolated venv
- [x] CONTRIBUTING.md instructions verified
- [x] No IDE diagnostics or issues
2026-05-15 16:08:45 -07:00

5.8 KiB

Contributing to Negative Rejection Steering

Thank you for your interest in contributing! This document provides guidelines for setting up your development environment and contributing to the project.

Development Setup

Prerequisites

  • Python 3.10 or higher
  • uv package manager
  • Git

Initial Setup

  1. Clone the repository (if you haven't already):

    git clone https://github.com/Reithan/negative_rejection_steering.git
    cd negative_rejection_steering
    
  2. Create virtual environment with uv:

    uv venv
    
  3. Activate virtual environment:

    # Git Bash (Windows)
    source .venv/Scripts/activate
    
    # Linux/Mac
    source .venv/bin/activate
    
    # Windows CMD
    .venv\Scripts\activate.bat
    
    # Windows PowerShell
    .venv\Scripts\Activate.ps1
    
  4. Install development dependencies:

    uv pip install -e ".[dev]"
    
  5. Install git hooks:

    pre-commit install
    pre-commit install --hook-type pre-push
    
  6. Verify setup:

    # Run hooks manually on all files
    pre-commit run --all-files
    
    # Check that ruff works
    ruff check .
    

Git Workflow

Protected Branches

  • Direct commits to main are blocked by git hooks
  • Direct pushes to main are blocked by git hooks
  • All changes must go through feature branches and pull requests
  1. Create a feature branch:

    git checkout -b feature/your-feature-name
    

    Or for bug fixes:

    git checkout -b fix/bug-description
    
  2. Make your changes and commit:

    git add <files>
    git commit -m "Your commit message"
    

    The pre-commit hook will automatically:

    • Run ruff linting and auto-fix issues
    • Check for trailing whitespace, missing final newlines, etc.
    • Block the commit if you're on the main branch

    If the linter auto-fixes files, you'll need to re-stage and commit again.

  3. Push your branch:

    git push origin feature/your-feature-name
    

    The pre-push hook will:

    • Run tests (if pytest is available)
    • Block the push if you're on the main branch
  4. Create a pull request on GitHub

  5. Merge after review

Bypassing Hooks (Emergency Only)

If you must bypass hooks (NOT recommended):

git commit --no-verify    # Skip pre-commit hooks
git push --no-verify      # Skip pre-push hooks

Warning: Only use --no-verify in emergencies. Bypassing hooks may:

  • Introduce linting issues
  • Break Continuous Integration/Continuous Deployment pipelines
  • Allow untested code to be pushed

Development Commands

Linting

# Check for linting issues
ruff check .

# Auto-fix linting issues
ruff check --fix .

# Format code
ruff format .

# Check a specific file
ruff check NRS/nodes_NRS.py

Testing

# Run all tests
pytest

# Run with verbose output
pytest -v

# Run specific test file
pytest tests/test_smoke.py

# Run specific test function
pytest tests/test_smoke.py::test_file_structure

Note: Tests use mocked versions of torch and gradio (via conftest.py) since these dependencies are provided by ComfyUI/WebUI at runtime.

Pre-commit Hooks

# Run all hooks manually
pre-commit run --all-files

# Run specific hook
pre-commit run ruff --all-files
pre-commit run ruff-format --all-files

# Update hook versions
pre-commit autoupdate

Code Style Guidelines

This project uses ruff for linting and formatting with the following configuration:

  • Line length: 120 characters
  • Target Python version: 3.10+
  • Enabled checks: pycodestyle (E/W), pyflakes (F), isort (I), pep8-naming (N), pyupgrade (UP)

Special Cases

  • ComfyUI API conventions: The INPUT_TYPES method and s parameter naming are required by ComfyUI's API and are exempted from normal naming rules
  • Star imports in __init__.py: Required for ComfyUI node discovery

Commit Message Guidelines

Write clear, concise commit messages:

  • Use imperative mood ("Add feature" not "Added feature")
  • Keep first line under 72 characters
  • Add detailed description in the body if needed

Good examples:

Add support for XYZ model type
Fix crash when prediction type is unknown
Update README with installation instructions

Bad examples:

fixed stuff
WIP
Updated code

Pull Request Guidelines

When submitting a pull request:

  1. Keep PRs focused: One feature or fix per PR
  2. Update documentation: If you add features, update README.md
  3. Test your changes: Ensure the extension works in ComfyUI/reForge
  4. Run pre-commit hooks: Make sure all checks pass
  5. Describe your changes: Explain what and why in the PR description

Project Structure

negative_rejection_steering/
├── NRS/
│   └── nodes_NRS.py          # Main NRS node implementation
├── scripts/
│   └── negative_rejection_steering_script.py  # Gradio UI for reForge
├── tests/
│   └── test_smoke.py         # Smoke tests
├── __init__.py               # ComfyUI node exports
├── pyproject.toml            # Project config, dependencies, tool config
├── .pre-commit-config.yaml   # Git hooks configuration
├── .gitignore
├── README.md
├── LICENSE
└── CONTRIBUTING.md           # This file

Getting Help

  • Issues: Report bugs or request features via GitHub Issues
  • Discussions: For questions or general discussion
  • Pull Requests: Review the PR guidelines above before submitting

License

By contributing to this project, you agree that your contributions will be licensed under the same license as the project (see LICENSE file).


Thank you for contributing to Negative Rejection Steering!