Repository navigation
Feat/add ruff linting #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| name: Linting | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, dev ] | ||
|
|
||
| # Temporarily disabled until merge | ||
| # pull_request: | ||
| # branches: [ main, dev ] | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| python-version: ["3.12"] | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install uv | ||
| run: | | ||
| curl -LsSf https://astral.sh/uv/install.sh | sh | ||
| echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
|
|
||
| - name: Cache uv | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cache/uv | ||
| key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml', '**/uv.lock') }} | ||
| restore-keys: | | ||
| uv-${{ runner.os }}-${{ matrix.python-version }}- | ||
|
|
||
| - name: Install dependencies with uv | ||
| run: | | ||
| uv sync --group lint | ||
|
|
||
| - name: Run Ruff linting | ||
| run: | | ||
| uv run ruff check . --output-format=github | ||
|
|
||
| - name: Check formatting | ||
| run: | | ||
| uv run ruff format --check . | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| # Linting Setup Guide | ||
|
|
||
| This project uses **Ruff** for Python linting and code formatting. All developers must ensure their code passes linting checks before submitting pull requests. | ||
|
|
||
| ## Installation | ||
|
|
||
| The linting dependencies are already included in `pyproject.toml`. Install them with: | ||
|
|
||
| ```bash | ||
| uv sync --group lint | ||
| ``` | ||
|
|
||
| Or install all groups including dev: | ||
|
|
||
| ```bash | ||
| uv sync | ||
| ``` | ||
|
|
||
| ## Running Linting Locally | ||
|
|
||
| ### Check for linting issues | ||
|
|
||
| ```bash | ||
| uv run ruff check . | ||
| ``` | ||
|
|
||
| ### Auto-fix linting issues | ||
|
|
||
| ```bash | ||
| uv run ruff check . --fix | ||
| ``` | ||
|
|
||
| ### Check code formatting | ||
|
|
||
| ```bash | ||
| uv run ruff format --check . | ||
| ``` | ||
|
|
||
| ### Auto-format code | ||
|
|
||
| ```bash | ||
| uv run ruff format . | ||
| ``` | ||
|
|
||
| ## Ruff Configuration | ||
|
|
||
| Ruff configuration is defined in `pyproject.toml` under `[tool.ruff]` and `[tool.ruff.lint]` sections. | ||
|
|
||
| ### Key Rules Enabled | ||
|
|
||
| - **E, W**: PEP 8 errors and warnings | ||
| - **F**: Pyflakes (undefined names, unused imports) | ||
| - **I**: isort-style import sorting | ||
| - **C4**: flake8-comprehensions (optimization suggestions) | ||
| - **UP**: pyupgrade (modernize Python code) | ||
| - **PIE**: flake8-pie (misc linting rules) | ||
| - **RUF**: Ruff-specific rules (**`not applied currently`**) | ||
|
|
||
| ### Excluded Directories | ||
|
|
||
| The following directories are excluded from linting: | ||
| - `.git`, `.venv`, `.pytest_cache`, `.ruff_cache`, `.vscode` | ||
| - `node_modules`, `vdb`, `ray_mount`, `model_weights`, `logs` | ||
| - `.astro`, `openrag.egg-info` | ||
|
|
||
| ## CI/CD Integration | ||
|
|
||
| A GitHub Actions workflow (`.github/workflows/lint.yml`) automatically runs on every push and pull request. The workflow: | ||
|
|
||
| 1. Checks for linting issues with `ruff check` | ||
| 2. Verifies code formatting with `ruff format --check` | ||
| 3. Reports results directly to GitHub (with file and line annotations) | ||
|
|
||
| ### Pull Request Requirements | ||
|
|
||
| All pull requests must pass the linting CI check. If your PR fails: | ||
|
|
||
| 1. Run `uv run ruff check . --fix` to auto-fix issues | ||
| 2. Run `uv run ruff format .` to format the code | ||
| 3. Review any remaining issues that require manual fixes | ||
| 4. Commit and push your changes | ||
|
|
||
| ## Pre-commit Hook (Optional) | ||
| One can also setup a pre-commit hook to run linting automatically before each commit. | ||
|
|
||
| ```bash | ||
| cat > .git/hooks/pre-commit << 'EOF' | ||
| #!/bin/bash | ||
|
|
||
| # Get list of staged Python files | ||
| FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$') | ||
|
|
||
| if [ -z "$FILES" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Run ruff check (will auto-fix if possible) | ||
| echo "Running ruff check..." | ||
| uv run ruff check $FILES --fix | ||
|
|
||
| # Run ruff format | ||
| echo "Running ruff format..." | ||
| uv run ruff format $FILES | ||
|
|
||
| # Re-add the modified files | ||
| git add $FILES | ||
|
|
||
| # Run ruff check again without --fix to catch remaining errors | ||
| echo "Checking for remaining issues..." | ||
| uv run ruff check $FILES | ||
|
|
||
| # If ruff check fails, block the commit | ||
| if [ $? -ne 0 ]; then | ||
| echo "Ruff check failed. Please fix errors before committing." | ||
| exit 1 | ||
| fi | ||
|
|
||
| exit 0 | ||
| EOF | ||
|
|
||
| chmod +x .git/hooks/pre-commit | ||
| ``` | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| * To disable pre-commit | ||
|
|
||
| ```bash | ||
| rm .git/hooks/pre-commit | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### "ruff: command not found" | ||
| Make sure you've installed the lint dependencies: | ||
| ```bash | ||
| uv sync --group lint | ||
| ``` | ||
|
|
||
| ### Auto-fix doesn't resolve all issues | ||
| Some issues require manual fixes. Review the error messages and fix them manually, then commit again. | ||
| Sometimes, you will have to ignore a particular check if deemed unnecessary | ||
|
|
||
| ```python | ||
| # Example: C417 rule suggest that map here is unnecessary | ||
|
Ahmath-Gadji marked this conversation as resolved.
|
||
|
|
||
|
|
||
| docs_with_tokens = list(map(lambda d: (_length_function(d.page_content), d), docs)) # noqa: C417 | ||
|
|
||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: linagora/openrag
Length of output: 88
🌐 Web query:
astral-sh/setup-uv GitHub Action documentation💡 Result:
I found the official documentation and README for the astral-sh/setup-uv GitHub Action:
Repository README (usage, inputs, outputs, advanced config, FAQ). Example install: uses: astral-sh/setup-uv@v7. Includes inputs like version, version-file, python-version, activate-environment, working-directory, checksum; outputs like uv-version, uv-path, venv, cache-hit. [1]
Astral docs guide for using uv in GitHub Actions (recommendation and example, showing pinning uv via the action). [2]
GitHub Marketplace entry for the action. [3]
If you want, I can paste the README sections (usage, inputs, outputs) or produce a ready-to-drop workflow snippet tailored to your OS and Python matrix.
🌐 Web query:
uv package manager latest version 2025 2026💡 Result:
As of Jan 15, 2026:
Sources: GitHub Releases (uv 0.9.25) [1], PyPI (uv 0.9.25) [2], GitHub release list showing 2025 tags (0.9.21 on Dec 30, 2025) [3].
🏁 Script executed:
# Let's examine the actual lint.yml workflow file cat -n ./.github/workflows/lint.ymlRepository: linagora/openrag
Length of output: 1568
Use the official
astral-sh/setup-uvaction for better reproducibility and maintenance.The
curl | shapproach installs the latest uv version, which lacks reproducibility. Instead, use the astral-sh/setup-uv action (v7), which provides version pinning, automatic caching, and is maintained by Astral.♻️ Suggested replacement
This eliminates the manual cache step since
setup-uvhandles caching automatically.🤖 Prompt for AI Agents