From 2ebb2103b8b8a5fea03948ac09a5a27af082e05a Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 16 Apr 2025 16:52:12 +0200 Subject: [PATCH 1/5] ci: add pre-commit.yml for GitHub Actions This commit adds a new GitHub Actions workflow configuration file (`pre-commit.yml`) to automate the execution of pre-commit hooks on pull requests and pushes. The workflow includes steps to install dependencies, cache pre-commit hooks, run the hooks, convert logs to Checkstyle format, save the cache, and upload logs as artifacts. This setup ensures that code quality checks are enforced consistently across the repository. --- .github/workflows/pre-commit.yml | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 000000000..5de58d77d --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,48 @@ +--- +name: pre-commit +on: + pull_request: + push: + workflow_dispatch: +jobs: + pre-commit: + runs-on: ubuntu-latest + env: + RAW_LOG: pre-commit.log + CS_XML: pre-commit.xml + steps: + - run: sudo apt-get update && sudo apt-get install cppcheck uncrustify + if: false + - uses: actions/checkout@v4 + - run: python -m pip install pre-commit + - uses: actions/cache/restore@v4 + with: + path: ~/.cache/pre-commit/ + key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + - name: Run pre-commit hooks + env: + SKIP: no-commit-to-branch + run: | + set -o pipefail + pre-commit gc + pre-commit run --show-diff-on-failure --color=always --all-files | tee ${RAW_LOG} + - name: Convert Raw Log to Checkstyle format (launch action) + uses: mdeweerd/logToCheckStyle@v2025.1.1 + if: ${{ failure() }} + with: + in: ${{ env.RAW_LOG }} + # out: ${{ env.CS_XML }} + - uses: actions/cache/save@v4 + if: ${{ ! cancelled() }} + with: + path: ~/.cache/pre-commit/ + key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + - name: Provide log as artifact + uses: actions/upload-artifact@v4 + if: ${{ ! cancelled() }} + with: + name: precommit-logs + path: | + ${{ env.RAW_LOG }} + ${{ env.CS_XML }} + retention-days: 2 From d127d456694cb10adc6deaab6194d34c166fe835 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 16 Apr 2025 17:36:09 +0200 Subject: [PATCH 2/5] chore: update codespell skip patterns Update the `skip` patterns in the `pyproject.toml` file to exclude `tests/fixtures/*` and `aider/website/*`. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f7b25eee8..928c5fee2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,5 +48,5 @@ build-backend = "setuptools.build_meta" write_to = "aider/_version.py" [tool.codespell] -skip = "*.svg,Gemfile.lock" +skip = "*.svg,Gemfile.lock,tests/fixtures/*,aider/website/*" write-changes = true From 09acfc8147bf210d9206ebe40186d2a3b94c38a2 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 16 Apr 2025 17:40:01 +0200 Subject: [PATCH 3/5] style(pre-commit): apply python style from pre-commit hooks --- aider/coders/editblock_fenced_coder.py | 1 + aider/coders/help_coder.py | 1 + aider/linter.py | 3 ++- tests/basic/test_watch.py | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/aider/coders/editblock_fenced_coder.py b/aider/coders/editblock_fenced_coder.py index 80e5036ea..cd09e27c5 100644 --- a/aider/coders/editblock_fenced_coder.py +++ b/aider/coders/editblock_fenced_coder.py @@ -5,5 +5,6 @@ from .editblock_fenced_prompts import EditBlockFencedPrompts class EditBlockFencedCoder(EditBlockCoder): """A coder that uses fenced search/replace blocks for code modifications.""" + edit_format = "diff-fenced" gpt_prompts = EditBlockFencedPrompts() diff --git a/aider/coders/help_coder.py b/aider/coders/help_coder.py index fcb1e6aa1..311805af7 100644 --- a/aider/coders/help_coder.py +++ b/aider/coders/help_coder.py @@ -5,6 +5,7 @@ from .help_prompts import HelpPrompts class HelpCoder(Coder): """Interactive help and documentation about aider.""" + edit_format = "help" gpt_prompts = HelpPrompts() diff --git a/aider/linter.py b/aider/linter.py index 51ed40b70..9c980366d 100644 --- a/aider/linter.py +++ b/aider/linter.py @@ -1,10 +1,11 @@ import os +import oslex import re +import shlex import subprocess import sys import traceback import warnings -import oslex from dataclasses import dataclass from pathlib import Path diff --git a/tests/basic/test_watch.py b/tests/basic/test_watch.py index 524f80e08..16e4f8206 100644 --- a/tests/basic/test_watch.py +++ b/tests/basic/test_watch.py @@ -155,7 +155,7 @@ def test_ai_comment_pattern(): assert ( question_js_has_bang == "?" ), "Expected at least one bang (!) comment in watch_question.js fixture" - + # Test Lisp fixture lisp_path = fixtures_dir / "watch.lisp" lisp_lines, lisp_comments, lisp_has_bang = watcher.get_ai_comments(str(lisp_path)) From 40a5a88d56c2728f693c0ef25e991699b9d74270 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 16 Apr 2025 18:29:07 +0200 Subject: [PATCH 4/5] style: remove or ignore unused imports The following files had unused imports removed: - `scripts/30k-image.py` - `scripts/dl_icons.py` - `scripts/redact-cast.py` --- benchmark/refactor_tools.py | 2 +- scripts/30k-image.py | 1 - scripts/dl_icons.py | 1 - scripts/redact-cast.py | 2 -- 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/benchmark/refactor_tools.py b/benchmark/refactor_tools.py index 117770a67..03812b0c1 100755 --- a/benchmark/refactor_tools.py +++ b/benchmark/refactor_tools.py @@ -132,7 +132,7 @@ def find_non_self_methods(path): with open(filename, "r") as file: try: node = ast.parse(file.read(), filename=filename) - except: + except: # noqa: E722 pass checker = SelfUsageChecker() checker.visit(node) diff --git a/scripts/30k-image.py b/scripts/30k-image.py index 9a62206e4..4921b3c20 100644 --- a/scripts/30k-image.py +++ b/scripts/30k-image.py @@ -7,7 +7,6 @@ This creates a shareable social media graphic with confetti animation. import argparse import base64 import math -import os import random from pathlib import Path diff --git a/scripts/dl_icons.py b/scripts/dl_icons.py index 8240ca641..7d878c907 100644 --- a/scripts/dl_icons.py +++ b/scripts/dl_icons.py @@ -3,7 +3,6 @@ Download Material Design Icons SVGs used in the README and save to local assets. """ -import os from pathlib import Path import requests diff --git a/scripts/redact-cast.py b/scripts/redact-cast.py index 91f230e87..c7a1e4ea8 100755 --- a/scripts/redact-cast.py +++ b/scripts/redact-cast.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 import json -import os -import re import sys import pyte From 1f6f48086438f747b7b1fcc5a86b882e148a04e6 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 16 Apr 2025 18:32:50 +0200 Subject: [PATCH 5/5] style(scripts): add flake8 noqa directive to 30k-image.py This commit adds a flake8 directive to disable the E501 line length check for the 30k-image.py script. --- scripts/30k-image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/30k-image.py b/scripts/30k-image.py index 4921b3c20..29924d424 100644 --- a/scripts/30k-image.py +++ b/scripts/30k-image.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# flake8: noqa: E501 """ Generate a celebratory SVG image for Aider reaching 30,000 GitHub stars. This creates a shareable social media graphic with confetti animation.