Skip to content

[TASK] Replace pip pre-commit framework with plain .githooks pre-commit hook #78

Closed

Description

Problem

CI on #77 failed at the black --check . step because hand-authored changes to inference_gateway/models.py and tests/test_client.py were pushed without being formatted. The fix was trivial (two whitespace-only reformattings), but the failure only surfaced after the code reached CI.

Root cause

The repo ships a .pre-commit-config.yaml backed by the pip pre-commit framework (black, isort, mypy, etc.), but it is opt-in: it only runs once a contributor has run pre-commit install. When a change is authored in an environment where the hooks were never installed or can't be installed (e.g. a sandbox with pip/network blocked), unformatted code sails straight through git commit/git push and is caught only by CI.

The ci: block in .pre-commit-config.yaml targets pre-commit.ci with autofix_prs: true, but the pre-commit.ci GitHub App is not enabled on this repo, so server-side auto-fix never fires either.

Proposal

Replace the pip pre-commit framework with a plain .githooks/pre-commit shell script, following the same pattern used in inference-gateway/cli. This eliminates the pip dependency, works in sandboxed environments, and is trivially installable.

What to build

  1. .githooks/pre-commit - a plain shell script that runs task format (black + isort) on staged Python files. No pip pre-commit framework, no YAML config, no network calls.

  2. task precommit:install - sets git config core.hooksPath .githooks so git picks up the hook automatically.

  3. task precommit:run - runs ./.githooks/pre-commit directly (for manual invocation or CI checks).

What to clean up

  • Delete .pre-commit-config.yaml - no longer needed.
  • Delete pre-commit:install, pre-commit:run, pre-commit:update tasks from Taskfile.yml.
  • Update dev:setup in Taskfile.yml to call precommit:install instead of pre-commit:install.
  • Update AGENTS.md / CLAUDE.md / CONTRIBUTING.md to reference task precommit:install and task precommit:run instead of the old pre-commit commands.

What stays

  • task format (black + isort) - the hook calls this.
  • task lint (black --check, isort --check-only, mypy) - CI still runs this independently.

Acceptance criteria

  • .githooks/pre-commit exists as a plain shell script that runs task format on staged files.
  • task precommit:install configures git to use .githooks as the hooks path.
  • task precommit:run runs the hook directly.
  • .pre-commit-config.yaml is deleted.
  • Old pre-commit:* tasks are removed from Taskfile.yml.
  • dev:setup calls precommit:install instead of pre-commit:install.
  • Dev docs are updated to reference the new commands.
  • An unformatted commit is blocked locally at commit time (not just in CI).

Context

Activity

  1. changed the title [-]feat: add pre-push pre-commit gate to catch formatting before CI[/-] [+]feat: replace pip pre-commit framework with plain .githooks pre-commit hook[/+] on Jul 18, 2026
  2. changed the title [-]feat: replace pip pre-commit framework with plain .githooks pre-commit hook[/-] [+][FEATURE] Replace pip pre-commit framework with plain .githooks pre-commit hook[/+] on Jul 18, 2026
  3. added theissue type on Jul 18, 2026
  4. changed the title [-][FEATURE] Replace pip pre-commit framework with plain .githooks pre-commit hook[/-] [+][TASK] Replace pip pre-commit framework with plain .githooks pre-commit hook[/+] on Jul 18, 2026
  5. moved this to Todo in 2026on Jul 18, 2026
  6. edenreich commented on Jul 18, 2026

    @edenreich
    Contributor

    @claude Can you work on this?

  7. inference-gateway-maintainer commented on Jul 18, 2026

    @inference-gateway-maintainer
    ContributorAuthor

    Claude finished @edenreich's task in 9m 32s —— View job • feat/issue-78-20260718-2111 • [Create PR ➔](https://github.com/inference-gateway/python-sdk/compare/main...feat/issue-78-20260718-2111?quick_pull=1&title=Issue%20%2378%3A%20Changes%20from%20Claude&body=This%20PR%20addresses%20issue%20%2378%0A%0AGenerated%20with%20%5BClaude%20Code%5D(https%3A%2F%2Fclaude.ai%2Fcode)


    Task: Replace pip pre-commit framework with plain .githooks/pre-commit ✅

    Opened PR #80.

    • Gather context (Taskfile, docs, inference-gateway/cli pattern source)
    • Create .githooks/pre-commit shell script (runs task format on staged Python files, blocks commit on reformat)
    • Add precommit:install + precommit:run tasks to Taskfile.yml
    • Remove old pre-commit:* tasks; update dev:setup
    • Delete .pre-commit-config.yaml
    • Drop pre-commit pip dep from pyproject.toml
    • Update dev docs (AGENTS.md / CLAUDE.md)
    • Store hook as 100755 so git actually executes it
    • Open PR

    What changed

    .githooks/pre-commit (new, mode 100755) - plain POSIX shell, no pip framework/YAML/network:

    staged_py="$(git diff --cached --name-only --diff-filter=ACM -- '*.py')"
    [ -z "$staged_py" ] && exit 0
    task format
    git diff --quiet -- $staged_py || { echo "reformatted; git add and retry" >&2; exit 1; }

    Taskfile.yml - replaced pre-commit:{install,run,update} with:

    • precommit:install → git config core.hooksPath .githooks + chmod +x .githooks/pre-commit
    • precommit:run → ./.githooks/pre-commit
    • dev:setup now calls precommit:install.

    Also: deleted .pre-commit-config.yaml, removed pre-commit>=4.6.0 from pyproject.toml dev extras (eliminates the pip dependency), documented the new commands in CLAUDE.md + AGENTS.md. CONTRIBUTING.md doesn't exist in this repo, so nothing to update there.

    Notes

    • The hook calls task format, then blocks the commit only if a staged .py file was reformatted - so an unformatted commit is stopped locally at commit time, not just in CI. task lint (with mypy) still runs independently in CI.
    • Stored the hook as 100755: git silently ignores non-executable hooks, so a 644 hook would recreate the exact "unformatted code slips to CI" bug this fixes. precommit:install re-applies chmod +x defensively.
    • Verification: the sandbox blocks chmod/test-script execution, so I traced the hook logic rather than running it live - block-on-unformatted, pass-when-formatted, and skip-when-no-.py-staged all hold (commands in if conditions are exempt from set -e; a task format failure also blocks the commit). The mode fix was confirmed via the Git Data API (.githooks/pre-commit = 100755).
      · Branch: feat/issue-78-20260718-2111
  8. moved this from Todo to In progress in 2026on Jul 18, 2026
  9. moved this from In progress to QA in 2026on Jul 18, 2026
  10. inference-gateway-releaser commented on Jul 18, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.8.0 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

  11. moved this from QA to Done in 2026on Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementreleased

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions