build: pre-commit hook rejecting IPY2-incompatible **kwargs, - #3598
build: pre-commit hook rejecting IPY2-incompatible **kwargs,#3598romangolev wants to merge 2 commits into
Conversation
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.
|
Unable to trigger custom agent "Code Reviewer". You have run out of credits 😔 |
There was a problem hiding this comment.
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: systempre-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 hookdev/scripts/format_staged_csharp.pyreads viaPath.read_bytes(), which closes deterministically. Consider using awithblock 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
epo: local\ alongside \dotnet-format. Scoped to ^pyrevitlib/.*\.py$.
Test plan