Skip to content

build: pre-commit hook rejecting IPY2-incompatible **kwargs, - #3598

Draft
romangolev wants to merge 2 commits into
developfrom
build/reject-ipy2-kwargs-comma
Draft

build: pre-commit hook rejecting IPY2-incompatible **kwargs,#3598
romangolev wants to merge 2 commits into
developfrom
build/reject-ipy2-kwargs-comma

Conversation

@romangolev

@romangolev romangolev commented Aug 29, 2026

Copy link
Copy Markdown
Member

Problem

ruff format emits a trailing comma after **kwargs\ whenever a multi-line parameter list ends with **kwargs\ (PEP 448 grammar, Python 3.5+). IronPython 2.7.12 -- the default pyRevit runtime -- predates PEP 448 and rejects the syntax with \SyntaxError: unexpected token ','\ at parse time, which makes the entire \pyrevit.forms\ module unloadable.

Scope of this PR

Cross-file backstop that grep-checks \pyrevitlib/\ for the same pattern and fails the commit with a \ ile:line\ diagnosis.

The formatter exclusion for _ipy.py\ itself ([tool.ruff] extend-exclude) lives in \ eat/forms-dark-mode\ and is targeted to merge to \develop\ first. This hook is the durable line of defense for everything that loads before _ipy.py\ at IronPython startup -- the very first parse failure in \compat.py\ or \ ramework.py\ would break every script in the same way.

Changes

  • \dev/scripts/check_ipy2_compat.py\ (new): regex ^\s+\*\kwargs,\s$, exits non-zero with remediation message.
  • .pre-commit-config.yaml: registers the script under
    epo: local\ alongside \dotnet-format. Scoped to ^pyrevitlib/.*\.py$.

Test plan

  • Manual: \python dev/scripts/check_ipy2_compat.py clean.py\ -> exit 0.
  • Manual: \python dev/scripts/check_ipy2_compat.py bad.py\ -> exit 1 with file:line + remediation.
  • Run \pre-commit run ipy2-no-kwargs-trailing-comma --all-files\ against current \develop\ to confirm zero hits.
  • Confirm the hook fires on a deliberately-crafted bad signature in a PR.

ruff format emits a trailing comma after **kwargs whenever a multi-line parameter list ends with **kwargs (PEP 448 grammar, Python 3.5+). IronPython 2.7.12 -- the default pyRevit runtime -- predates PEP 448 and rejects the syntax with SyntaxError: unexpected token ',' at parse time, unloading the entire pyrevit.forms module.

The formatter is opted out for _ipy.py via [tool.ruff] extend-exclude in a separate PR. This hook is the cross-file backstop: it greps pyrevitlib/ for the same pattern and fails the commit with a file:line diagnosis if it ever reappears in a module that loads before _ipy.py at IronPython startup.
@devloai

devloai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Unable to trigger custom agent "Code Reviewer". You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a commit-time safety net to protect the pyRevit runtime library from an IronPython 2.7.12 incompatibility. ruff format emits a trailing comma after **kwargs at the end of a multi-line parameter list/call (PEP 448 grammar, Python 3.5+), which IronPython 2.7.12 — the default pyRevit runtime — rejects with SyntaxError: unexpected token ',', making affected modules (e.g. pyrevit.forms) unloadable. Since the per-file formatter opt-out is limited, this adds a repository-wide backstop that greps pyrevitlib/ for the pattern and fails the commit with a file:line diagnosis.

Changes:

  • Adds dev/scripts/check_ipy2_compat.py, a standalone/pre-commit script that scans given files for a line-anchored **kwargs, pattern and exits non-zero with a remediation message.
  • Registers the script as a repo: local, language: system pre-commit hook scoped to ^pyrevitlib/.*\.py$.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dev/scripts/check_ipy2_compat.py New hook script: regex-scans files for IPY2-incompatible trailing-comma **kwargs, and reports file:line with remediation.
.pre-commit-config.yaml Registers the new local hook alongside dotnet-format, scoped to pyrevitlib Python files.
Suppressed comments (1)

dev/scripts/check_ipy2_compat.py:32

  • The file handle from open(...) is never closed here; it lingers until garbage collection. The sibling hook dev/scripts/format_staged_csharp.py reads via Path.read_bytes(), which closes deterministically. Consider using a with block so the handle is released promptly and consistently with the sibling script.
        text = open(path, encoding="utf-8", errors="replace").read()

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread dev/scripts/check_ipy2_compat.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants