`pre-commit` CI fails: cmake-format (cmakelang) crashes on Python 3.15

Open
#155 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cmake, github-actions, python

Research direction

Start by reading .pre-commit-config.yaml and the pre-commit GitHub workflow to see how the cmake-format hook and Python version are selected. Run pre-commit run --all-files under Python 3.15 to reproduce the failure. Compare the proposed gersemi replacement with pinning Python below 3.15, then confirm the selected approach works across all CMake files and hooks.

Written by the indexing model from the issue text.

Description

Issue applies to:
  • PFLOW
  • OPFLOW
  • TCOPFLOW
  • SCOPFLOW
  • SOPFLOW
  • CMake and build system
  • Spack
  • Visualization
  • Documentation
  • Other
Summary

The pre-commit GitHub workflow currently fails on every run because the cmake-format hook executes under Python 3.15.0 on the hosted runner.

The hook is backed by the cmakelang package (v0.6.13, pinned via cheshirekow/cmake-format-precommit). Its lexer builds an re.Scanner from regexes that contain capturing groups. Python 3.15 added a guard that rejects this:

ValueError: Cannot use capturing groups in re.Scanner

The scanner fails to construct before any formatting takes place, so every CMake file in the repository fails with the same traceback (e.g. src/CMakeLists.txt, buildsystem/clang-hip/cache.cmake, interfaces/python/CMakeLists.txt, tests/unit/opflow/objective/CMakeLists.txt). The CMake files themselves are not at fault.

cmakelang has had no release since 2021, so an upstream fix is unlikely. All other hooks (clang-format, check-toml, forbid-new-submodules, end-of-file-fixer, check-yaml) pass.

Description how to reproduce the issue

Observed in the pre-commit workflow on branch suggestion_gridkit_tapfix_precision_eve:

$ pre-commit run --show-diff-on-failure --color=always --all-files
cmake-format.............................................................Failed
- hook id: cmake-format
- exit code: 1
WARNING __main__.py:530: While processing src/CMakeLists.txt
Traceback (most recent call last):
  File ".../py_env-python3.15/bin/cmake-format", line 6, in <module>
    sys.exit(main())
  File ".../cmakelang/format/__main__.py", line 633, in main
    return inner_main()
  File ".../cmakelang/format/__main__.py", line 616, in inner_main
    onefile_main(infile_path, args, argparse_dict)
  File ".../cmakelang/format/__main__.py", line 526, in onefile_main
    outtext, reflow_valid = process_file(cfg, intext, args.dump)
  File ".../cmakelang/format/__main__.py", line 144, in process_file
    tokens = lex.tokenize(infile_content)
  File ".../cmakelang/lex/__init__.py", line 135, in tokenize
    scanner = re.Scanner([
    ...
    ], re.DOTALL)
  File "/opt/hostedtoolcache/Python/3.15.0/x64/lib/python3.15/re/__init__.py", line 406, in __init__
    raise ValueError("Cannot use capturing groups in re.Scanner")
ValueError: Cannot use capturing groups in re.Scanner

The same traceback repeats for every CMake file. Reproducible locally with pre-commit run --all-files under any Python >= 3.15.

ExaGO version

Branch suggestion_gridkit_tapfix_precision_eve (develop-based, untagged)

System and environment details
  • GitHub Actions hosted runner, ubuntu-latest
  • actions/setup-python resolving to Python 3.15.0 (/opt/hostedtoolcache/Python/3.15.0/x64)
  • pre-commit hooks pinned in .pre-commit-config.yaml:
    • cheshirekow/cmake-format-precommit v0.6.13 (cmakelang 0.6.13)
    • pre-commit/mirrors-clang-format v10.0.1
    • pre-commit/pre-commit-hooks v4.4.0
  • Not hardware/compiler dependent; this is a pure Python tooling failure in CI.
Additional information

Context: re.Scanner is an undocumented stdlib class; Python 3.15 started validating that the lexer patterns passed to it contain no capturing groups. cmakelang relies on capturing groups in its tokenizer patterns and is unmaintained (last release 0.6.13, 2021), so the hook will remain broken on 3.15+ runners.

Also noted in the same log (unrelated, harmless): pre-commit-hooks v4.4.0 uses deprecated stage names; pre-commit autoupdate would clear that warning.

Proposed solution

Preferred: replace the unmaintained hook with gersemi, which is actively maintained and runs on current Python:

  - repo: https://github.com/BlankSpruce/gersemi
    rev: 0.27.7   # run `pre-commit autoupdate` to pin latest
    hooks:
    - id: gersemi

Then run pre-commit run --all-files once and commit the resulting CMake reformat as a standalone commit. Style can be tuned via a .gersemirc if the default output differs too much from the current formatting; project-defined functions/macros can be registered via its definitions option.

Short-term alternative: pin the pre-commit interpreter to a Python < 3.15 (e.g. default_language_version: {python: python3.14} plus a matching actions/setup-python version), which keeps cmake-format working but leaves the dead dependency in place.

Dominant language
Python
Stars
17
Forks
11
Avg merge
2d 11h
Merged PRs (30d)
2

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ORNL/ExaGO

All issues in ORNL/ExaGO

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.