|
| 1 | +# Pre-commit Setup for CometX |
| 2 | + |
| 3 | +This document describes the pre-commit setup for the CometX repository. |
| 4 | + |
| 5 | +## What's Included |
| 6 | + |
| 7 | +The pre-commit configuration includes the following hooks: |
| 8 | + |
| 9 | +### Automatic Hooks (run on every commit) |
| 10 | +- **Black**: Code formatting (88 character line length) |
| 11 | +- **isort**: Import sorting (compatible with Black) |
| 12 | +- **flake8**: Linting (with Black-compatible settings) |
| 13 | +- **pre-commit hooks**: Various general checks: |
| 14 | + - Merge conflict detection |
| 15 | + - YAML/JSON validation |
| 16 | + - Large file detection |
| 17 | + - Case conflict detection |
| 18 | + - Docstring placement |
| 19 | + - AST validation |
| 20 | + - Debug statement detection |
| 21 | + - End-of-file fixing |
| 22 | + - Trailing whitespace removal |
| 23 | + - TOML validation |
| 24 | + - VCS permalink checking |
| 25 | + - Mixed line ending detection |
| 26 | + - Requirements.txt sorting |
| 27 | + |
| 28 | +### Manual Hooks (run only when explicitly called) |
| 29 | +- **mypy**: Type checking (basic mode) |
| 30 | +- **pydocstyle**: Documentation style checking |
| 31 | + |
| 32 | +## Setup Instructions |
| 33 | + |
| 34 | +1. Install development dependencies: |
| 35 | + ```bash |
| 36 | + pip install -r requirements-dev.txt |
| 37 | + ``` |
| 38 | + |
| 39 | +2. Install pre-commit hooks: |
| 40 | + ```bash |
| 41 | + pre-commit install |
| 42 | + ``` |
| 43 | + |
| 44 | +3. (Optional) Run the setup script: |
| 45 | + ```bash |
| 46 | + ./setup-pre-commit.sh |
| 47 | + ``` |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +### Automatic Checks |
| 52 | +The automatic hooks will run every time you commit. If any fail, the commit will be blocked until the issues are fixed. |
| 53 | + |
| 54 | +### Manual Checks |
| 55 | +To run the manual hooks: |
| 56 | + |
| 57 | +```bash |
| 58 | +# Run all manual hooks |
| 59 | +pre-commit run --all-files --hook-stage manual |
| 60 | + |
| 61 | +# Run specific manual hooks |
| 62 | +pre-commit run mypy --all-files |
| 63 | +pre-commit run pydocstyle --all-files |
| 64 | +``` |
| 65 | + |
| 66 | +### Running Specific Hooks |
| 67 | +```bash |
| 68 | +# Run all hooks on all files |
| 69 | +pre-commit run --all-files |
| 70 | + |
| 71 | +# Run specific hooks |
| 72 | +pre-commit run black --all-files |
| 73 | +pre-commit run flake8 --all-files |
| 74 | +pre-commit run isort --all-files |
| 75 | +``` |
| 76 | + |
| 77 | +## Configuration Files |
| 78 | + |
| 79 | +- `.pre-commit-config.yaml`: Main pre-commit configuration |
| 80 | +- `.flake8`: Flake8 linting configuration |
| 81 | +- `pyproject.toml`: Black, isort, and mypy configuration |
| 82 | + |
| 83 | +## Current Status |
| 84 | + |
| 85 | +✅ **Working Hooks:** |
| 86 | +- Black (code formatting) |
| 87 | +- isort (import sorting) |
| 88 | +- flake8 (linting) |
| 89 | +- All pre-commit general hooks |
| 90 | + |
| 91 | +⚠️ **Manual Hooks:** |
| 92 | +- mypy (type checking) - set to manual due to existing type issues |
| 93 | +- pydocstyle (documentation) - set to manual due to extensive docstring issues |
| 94 | + |
| 95 | +## Known Issues |
| 96 | + |
| 97 | +1. **Line Length Violations**: Some files exceed the 88-character line limit |
| 98 | +2. **Type Annotations**: Some files have syntax errors in type annotations |
| 99 | +3. **Documentation**: Many functions and classes lack proper docstrings |
| 100 | +4. **Code Quality**: Focus on formatting, imports, and linting |
| 101 | + |
| 102 | +## Next Steps |
| 103 | + |
| 104 | +To improve the code quality: |
| 105 | + |
| 106 | +1. **Fix line length violations**: Run `pre-commit run black --all-files` to auto-format |
| 107 | +2. **Fix type annotations**: Address mypy errors in `cometx/framework/comet/download_manager.py` |
| 108 | +3. **Add docstrings**: Gradually add proper documentation to functions and classes |
| 109 | +4. **Improve code quality**: Focus on formatting, imports, and linting issues |
| 110 | + |
| 111 | +## Disabling Hooks |
| 112 | + |
| 113 | +If you need to bypass pre-commit hooks temporarily: |
| 114 | + |
| 115 | +```bash |
| 116 | +git commit --no-verify -m "Your commit message" |
| 117 | +``` |
| 118 | + |
| 119 | +**Note**: This should only be used in emergencies, not as a regular practice. |
0 commit comments