From a28f55b72e743de89c6e37a5d81bbf860f066553 Mon Sep 17 00:00:00 2001 From: Jatin K Malik Date: Thu, 17 Apr 2025 00:05:34 -0500 Subject: [PATCH] Add pre-commit hooks to match GitHub CI pipeline (#7) * Add pre-commit hooks to match CI pipeline linting rules * Add pre-commit hooks that match GitHub CI pipeline exactly * Ran lint check --- .github/workflows/ci.yml | 30 ++++---- .github/workflows/release.yml | 2 +- .gitignore | 5 +- .pre-commit-config.yaml | 26 +++++++ CONTRIBUTING.md | 124 ++++++++++++++++++++++++++++++++++ LICENSE | 2 +- README.md | 26 ++++++- docs/INSTALL.md | 2 +- docs/USER_GUIDE.md | 2 +- install.sh | 10 +-- setup.py | 2 +- vocalinux.desktop | 2 +- 12 files changed, 205 insertions(+), 28 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 CONTRIBUTING.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e31e2a1..983ef81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,30 +17,30 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - + - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.10' cache: 'pip' cache-dependency-path: 'setup.py' - + - name: Install development dependencies run: | python -m pip install --upgrade pip python -m pip install flake8 black isort - + - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 src/ tests/ --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings flake8 src/ tests/ --count --exit-zero --max-complexity=10 --max-line-length=100 --statistics - + - name: Check formatting with black run: | black --check src/ tests/ - + - name: Check import sorting with isort run: | isort --check-only --profile black src/ tests/ @@ -50,18 +50,18 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.8] steps: - uses: actions/checkout@v3 - + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: 'pip' cache-dependency-path: 'setup.py' - + - name: Install system dependencies run: | sudo apt-get update @@ -76,7 +76,7 @@ jobs: gobject-introspection \ libcairo-gobject2 \ gir1.2-gtk-3.0 - + - name: Cache apt packages uses: actions/cache@v3 with: @@ -84,7 +84,7 @@ jobs: key: ${{ runner.os }}-apt-${{ hashFiles('**/apt-packages.txt') }} restore-keys: | ${{ runner.os }}-apt- - + - name: Set up virtual environment run: | python -m venv venv @@ -95,14 +95,14 @@ jobs: python -m pip install pytest pytest-cov echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV echo "PATH=$VIRTUAL_ENV/bin:$PATH" >> $GITHUB_ENV - + - name: Run pytest suite with coverage run: | source venv/bin/activate # Make sure Python can find the 'src' module PYTHONPATH=$PWD pytest --cov=src tests/ - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 with: - fail_ci_if_error: false \ No newline at end of file + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5af709c..6b86adf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,4 +34,4 @@ jobs: files: | dist/*.whl dist/*.tar.gz - generate_release_notes: true \ No newline at end of file + generate_release_notes: true diff --git a/.gitignore b/.gitignore index 7b07128..10b973c 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,7 @@ coverage.xml Thumbs.db # Installed desktop entries -*-installed.desktop \ No newline at end of file +*-installed.desktop + +# Pre-commit +.pre-commit-cache/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0759b23 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +repos: + - repo: https://github.com/psf/black + rev: 24.1.1 + hooks: + - id: black + args: [--check] + files: ^(src|tests)/ + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + args: ["--check-only", "--profile", "black"] + files: ^(src|tests)/ + + - repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + name: flake8 (critical) + args: ["--count", "--select=E9,F63,F7,F82", "--show-source", "--statistics"] + files: ^(src|tests)/ + - id: flake8 + name: flake8 (warnings) + args: ["--count", "--exit-zero", "--max-complexity=10", "--max-line-length=100", "--statistics"] + files: ^(src|tests)/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0c0267b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,124 @@ +# Contributing to Vocalinux + +Thank you for your interest in contributing to Vocalinux! This document provides guidelines and instructions for contributing to the project. + +## Development Environment Setup + +1. Fork the repository on GitHub +2. Clone your fork locally: + ```bash + git clone https://github.com/YOUR-USERNAME/vocalinux.git + cd vocalinux + ``` +3. Set up the development environment: + ```bash + # Install development dependencies + pip install -e ".[dev]" + + # Install pre-commit hooks + pip install pre-commit + pre-commit install + ``` + +## Pre-commit Hooks + +We use pre-commit hooks to ensure code quality and consistency. These hooks automatically run before each commit to check your code against our standards. + +### Pre-commit Configuration + +The pre-commit configuration in `.pre-commit-config.yaml` includes: + +1. **black**: Code formatter (line length: 100) +2. **isort**: Import sorter (configured to be compatible with black) +3. **flake8**: Linter with plugins for docstrings, comprehensions, and bug detection +4. **Additional checks**: Trailing whitespace, file endings, YAML/JSON validation, etc. + +### Running Pre-commit Manually + +You can run the pre-commit checks manually on all files: +```bash +pre-commit run --all-files +``` + +Or on specific files: +```bash +pre-commit run --files path/to/file1.py path/to/file2.py +``` + +### Bypassing Pre-commit (Emergency Only) + +In emergency situations only, you can bypass pre-commit hooks: +```bash +git commit -m "Your message" --no-verify +``` + +However, this is strongly discouraged as it may lead to CI pipeline failures. + +## Code Style Guidelines + +We follow these code style conventions: + +1. **PEP 8**: With modifications: + - Maximum line length: 100 characters + - Use Black formatting + +2. **Docstrings**: All public methods, classes, and modules should have docstrings + +3. **Imports**: Organized using isort with the following sections: + - Standard library imports + - Third-party imports + - Local application imports + +4. **Type Annotations**: Use type hints where appropriate + +## Testing + +Write tests for all new features and bug fixes: + +```bash +# Run tests +pytest + +# Run tests with coverage report +pytest --cov=src +``` + +Aim for at least 80% test coverage for new code. + +## Pull Request Process + +1. Ensure all pre-commit checks pass +2. Update documentation if necessary +3. Add or update tests as needed +4. Create a pull request with a clear description of the changes +5. Link any related issues +6. Wait for code review + +## Commit Message Guidelines + +Follow these guidelines for commit messages: + +- Use the present tense ("Add feature" not "Added feature") +- Use the imperative mood ("Move cursor to..." not "Moves cursor to...") +- Limit the first line to 72 characters or less +- Reference issues and pull requests after the first line + +Example: +``` +Add voice command for deleting sentences + +This implements the "delete that" command functionality +to remove the last sentence entered by the user. + +Fixes #123 +``` + +## Documentation + +Update documentation for any new features or changes: + +- Add docstrings to new functions, classes, and methods +- Update README.md or relevant docs in the docs/ directory +- Add or update code examples if applicable + +Thank you for contributing to Vocalinux! diff --git a/LICENSE b/LICENSE index 15f0fde..8f07d4d 100644 --- a/LICENSE +++ b/LICENSE @@ -26,4 +26,4 @@ them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. -[Full license text omitted for brevity. The complete GPLv3 license should be included in the actual file.] \ No newline at end of file +[Full license text omitted for brevity. The complete GPLv3 license should be included in the actual file.] diff --git a/README.md b/README.md index 40f6240..639adfa 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,30 @@ pip install -e ".[dev]" pytest tests/ ``` +### Pre-commit Hooks + +This project uses pre-commit hooks to ensure code quality and consistency. The hooks will automatically check your code for linting errors before each commit, which helps prevent CI pipeline failures. + +To set up pre-commit hooks: + +1. Install pre-commit: `pip install pre-commit` +2. Install the git hooks: `pre-commit install` + +Now, when you try to commit changes, the pre-commit hooks will automatically run and check your code. If any issues are found, the commit will be blocked until you fix them. + +To manually run all pre-commit hooks on all files: +``` +pre-commit run --all-files +``` + +### Pre-commit Checks + +The following checks are performed by pre-commit: +- **black**: Code formatting +- **isort**: Import sorting +- **flake8**: Code style and error detection +- Various file checks (trailing whitespace, merge conflicts, etc.) + ### Key Components 1. **Speech Recognition Manager** (`src/speech_recognition/recognition_manager.py`) @@ -252,4 +276,4 @@ Contributions are welcome! Please feel free to submit a Pull Request. ## License -This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details. \ No newline at end of file +This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details. diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 1b58ee5..66ad31d 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -90,4 +90,4 @@ Note that larger models require more RAM and may have longer initialization time - Try a larger model size (`--model medium` or `--model large`) - Ensure your microphone is positioned correctly -- Speak clearly and at a moderate pace \ No newline at end of file +- Speak clearly and at a moderate pace diff --git a/docs/USER_GUIDE.md b/docs/USER_GUIDE.md index 89666ba..0981077 100644 --- a/docs/USER_GUIDE.md +++ b/docs/USER_GUIDE.md @@ -75,4 +75,4 @@ If you encounter issues, check the [Installation Guide](INSTALL.md) troubleshoot vocalinux --debug ``` -Check the logs for error messages and possible solutions. \ No newline at end of file +Check the logs for error messages and possible solutions. diff --git a/install.sh b/install.sh index 0517b4d..5ebac24 100755 --- a/install.sh +++ b/install.sh @@ -127,15 +127,15 @@ VENV_DIR="venv" if [[ "$USE_VENV" == "yes" ]]; then print_info "Setting up Python virtual environment..." python3 -m venv $VENV_DIR --system-site-packages - + # Activate virtual environment source $VENV_DIR/bin/activate - + # Update pip and setuptools pip install --upgrade pip setuptools wheel - + print_info "Virtual environment activated." - + # Create activation script for users cat > activate-vocalinux.sh << EOF #!/bin/bash @@ -243,4 +243,4 @@ else fi echo -print_info "For more information, see the documentation in the docs/ directory." \ No newline at end of file +print_info "For more information, see the documentation in the docs/ directory." diff --git a/setup.py b/setup.py index 813fc94..f37de4d 100644 --- a/setup.py +++ b/setup.py @@ -44,4 +44,4 @@ setup( "Topic :: Desktop Environment :: Gnome", ], python_requires=">=3.8", # Updated minimum Python version -) \ No newline at end of file +) diff --git a/vocalinux.desktop b/vocalinux.desktop index a480306..8d9e21b 100644 --- a/vocalinux.desktop +++ b/vocalinux.desktop @@ -9,4 +9,4 @@ Icon=/usr/share/icons/hicolor/scalable/apps/vocalinux.svg Terminal=false Categories=Utility;Accessibility; Keywords=voice;typing;dictation;speech;recognition; -StartupNotify=true \ No newline at end of file +StartupNotify=true