Skip to content

fixed pre-commit docformatter error#1378

Merged
henrykironde merged 1 commit into
weecology:mainfrom
musaqlain:fix-docformatter-hook
Apr 26, 2026
Merged

fixed pre-commit docformatter error#1378
henrykironde merged 1 commit into
weecology:mainfrom
musaqlain:fix-docformatter-hook

Conversation

@musaqlain
Copy link
Copy Markdown
Contributor

@musaqlain musaqlain commented Apr 19, 2026

What

Fixes the docformatter pre-commit hook and pins language_version: python3.12
for hooks affected by Python 3.14 AST removals on pre-commit.ci.

Why

docformatter (InvalidManifestError)

nbQA (ast.Str removal)

  • In Python 3.14, ast.Str was removed
  • nbQA's notebook processing depends on ast.Str, so it fails on Python 3.14
  • On main, this was hidden by pre-commit.ci's cached environments, the nbQA
    environment was built on an older Python and reused across runs
    As you can in this image (this is from the last PR merged by Josh), the environment is actually using cached nbQA that is using 3.12 python version.
Screenshot 2026-04-20 011557 - Updating the docformatter config invalidated the cache, forcing a fresh rebuild on Python 3.14, which exposed the latent failure (as u cann see in the image, it is using python3.14, and eventually it get failed) Screenshot 2026-04-20 011758 Screenshot 2026-04-20 011901
  • Pinning language_version: python3.12 ensures both hooks build on a compatible Python

Changes

  • docformatter: repo: localrepo: https://github.com/PyCQA/docformatter at v1.7.7
  • docformatter: added language_version: python3.12 + additional_dependencies: [tomli]
  • nbQA hooks: added language_version: python3.12 to both nbqa-ruff-format and nbqa-ruff
  • Removed redundant local hook fields (name, entry, language, types)

Fixes #1266

@musaqlain musaqlain force-pushed the fix-docformatter-hook branch from 31e2f27 to 1090deb Compare April 19, 2026 18:00
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.92%. Comparing base (408e150) to head (60a3d96).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1378      +/-   ##
==========================================
+ Coverage   86.87%   86.92%   +0.04%     
==========================================
  Files          24       24              
  Lines        3064     3204     +140     
==========================================
+ Hits         2662     2785     +123     
- Misses        402      419      +17     
Flag Coverage Δ
unittests 86.92% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@musaqlain musaqlain force-pushed the fix-docformatter-hook branch from 92e6ac1 to 89a252f Compare April 19, 2026 19:50
@musaqlain musaqlain marked this pull request as ready for review April 19, 2026 20:23
@musaqlain
Copy link
Copy Markdown
Contributor Author

this pr precedes all the recent PRs' who are in queue and are getting pre-commit.ci error during building.

cc @henrykironde

Comment thread .pre-commit-config.yaml Outdated
Comment on lines +34 to +36
additional_dependencies: [tomli]
# TODO: remove language_version pin once docformatter drops the `untokenize` dependency
# which uses `ast.Constant.s` — removed in Python 3.14, causing pre-commit.ci to fail
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.

Could we clean this up and remove the comments?

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.

Could we minimize the changes here? Let’s try using the previous config and just add language_version: python3.12

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done, reverted to the previous repo: local config and only added language_version: python3.12

Also worth noting: docformatter released v1.7.8 yesterday with Python 3.14 support. what do you think, should we use it? if we use this new version then we could switch from repo: local to repo: https://github.com/PyCQA/docformatter at rev: v1.7.8 and remove the language_version pin for docformatter (nbQA pin would still be needed though).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

update: I tested v1.7.8 on my fork and it reformats some existing files due to bug fixes in the new version (#335, #336). so upgrading to v1.7.8 would be better as a separate follow-up PR. for now, the minimal language_version: python3.12 pin should be good.

what do you think? 👀

Comment thread .pre-commit-config.yaml Outdated
@musaqlain musaqlain force-pushed the fix-docformatter-hook branch from 89a252f to 59cfda7 Compare April 21, 2026 20:31
Copy link
Copy Markdown
Contributor

@henrykironde henrykironde left a comment

Choose a reason for hiding this comment

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

Can we try to undo line 20 and 25 and see if it passes

@musaqlain
Copy link
Copy Markdown
Contributor Author

Can we try to undo lines 20 and 25 and see if it passes?

Hello Henry, I already tested it without pinning the Python 3.12 version on lines 20 and 25, and it failed. This is because it then defaults to Python 3.14; since ast.Str was removed in 3.14, and nbQA depends on it, it triggers the following error:

nbQA failed to process docs/user_guide/examples/Bird_FineTuning.ipynb 
with exception "AttributeError("module 'ast' has no attribute 'Str'")"

The language_version: python3.12 pin is required for nbQA until they release a fix.

--
Previously, nbQA was running correctly because it was using a cached 3.12 version. However, once I updated .pre-commit-config.yaml, it triggered nbQA to run using Python 3.14, which is why it failed.

@henrykironde henrykironde merged commit 8770f65 into weecology:main Apr 26, 2026
9 checks passed
@henrykironde
Copy link
Copy Markdown
Contributor

Thanks @musaqlain for these tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Python 3.14

3 participants