Skip to content

[TEST] pyOpenMS: accept short-form Sphinx cross-reference roles in the docstring RST check - #9805

Merged
timosachsenberg merged 3 commits into
developfrom
test/pyopenms-docstring-sphinx-roles
Jul 27, 2026
Merged

timosachsenberg merged 3 commits into
developfrom
test/pyopenms-docstring-sphinx-roles

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

pyopenms_docstring_tests is currently red on develop, and has been since the FeatureFinderAlgorithmMetaboIdent addon landed:

FAILED tests/unittests/test_docstrings.py::TestAllClassDocstrings::test_method_docstrings_valid_rst[FeatureFinderAlgorithmMetaboIdent]
  RST ERROR: <docstring>:4: (ERROR/3) Unknown interpreted text role "meth".      (x5)
  RST ERROR: <docstring>:10: (ERROR/3) Unknown interpreted text role "meth".

The docstrings are fine — the allowlist was incomplete

test_docstrings.py validates that docstrings are "compatible with Sphinx documentation generation", and it validates them with plain docutils, which does not know Sphinx's roles and directives. _is_acceptable_error() already exists to paper over exactly that gap, and already filters:

  • unknown interpreted text role "py:…"
  • unknown directive type "py:…"
  • unknown directive type "deprecated"
  • unexpected section title (napoleon's NumPy-style Parameters / Returns headers)

What it did not cover is the short, default-domain spelling of those same roles. Python is the default domain in a Python project, so :meth:`foo` means exactly what :py:meth:`foo` means and is the idiomatic way to write it — but only the py:-prefixed form was accepted.

src/pyOpenMS/pyopenms/addons/featurefinderalgorithmmetaboident.py uses the short form (6 occurrences, the only Sphinx roles anywhere in pyOpenMS docstring sources), so it tripped the check.

The change

Accept the Sphinx Python-domain and standard cross-reference roles in their short spelling too. The roles are listed explicitly rather than accepting any unknown role, so a misspelt one is still reported — the check keeps its teeth:

_SPHINX_ROLES = frozenset({
    "mod", "func", "data", "const", "class", "meth", "attr", "exc", "obj",   # Python domain
    "ref", "doc", "term", "envvar", "option", "keyword", "token",            # standard
})

Verification

before after
pyopenms_docstring_tests 2738 passed, 1 failed 2739 passed, 0 failed
pyopenms_unittests 2501 passed 2501 passed (unaffected)

Negative controls, to confirm the check still catches real mistakes:

error accepted?
Unknown interpreted text role "meth" yes
Unknown interpreted text role "py:meth" yes
Unknown interpreted text role "ref" yes
Unknown interpreted text role "mehtod" (typo) no
Unknown interpreted text role "bogus" no

Notes

Summary by CodeRabbit

  • Bug Fixes
    • Improved docstring validation to accept only supported Sphinx Python cross-reference roles.
    • Reduced false-positive documentation errors when valid Sphinx markup is present.
  • Tests
    • Added/updated coverage to verify accepted roles pass validation, while unrelated RST parsing issues are still reported.

timosachsenberg and others added 2 commits July 26, 2026 19:14
…e docstring RST check

test_docstrings.py validates that every docstring is "compatible with Sphinx
documentation generation", and its _is_acceptable_error() allowlist already
filters the Sphinx constructs that the plain docutils parser cannot resolve:
py:-prefixed roles and directives, the deprecated directive, and napoleon
section headers.

It did not cover the short, default-domain spelling of the same roles. Python
is the default domain in a Python project, so :meth:`foo` is the idiomatic
form and means exactly what :py:meth:`foo` means -- but only the latter was
accepted. The FeatureFinderAlgorithmMetaboIdent addon uses the short form,
so pyopenms_docstring_tests failed on develop with six

  Unknown interpreted text role "meth".

The docstrings are correct; the allowlist was incomplete. Accept the Sphinx
Python-domain and standard cross-reference roles in their short spelling too.
The roles are listed explicitly rather than accepting any unknown role, so a
misspelt one is still reported.

Test-only change. pyopenms_docstring_tests goes from 2738 passed / 1 failed
to 2739 passed; the unittest suite is unaffected at 2501 passed.

Co-Authored-By: Claude Opus 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d47ad006-1c12-497c-88dc-7f4b5e0af9bf

📥 Commits

Reviewing files that changed from the base of the PR and between a5c4c58 and 2c8456d.

📒 Files selected for processing (1)
  • src/pyOpenMS/tests/unittests/test_docstrings.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pyOpenMS/tests/unittests/test_docstrings.py

📝 Walkthrough

Walkthrough

Docstring validation now accepts only whitelisted Sphinx cross-reference roles when filtering docutils errors. Other validation and RST parsing behavior remains unchanged.

Changes

Docstring validation

Layer / File(s) Summary
Whitelist docutils cross-reference roles
src/pyOpenMS/tests/unittests/test_docstrings.py
Defines accepted roles, extracts optional py: role prefixes from docutils errors, and updates _is_acceptable_error to accept only whitelisted roles.

Poem

A rabbit checks each docstring line,
While known Sphinx roles hop in time.
Unknown names wait beyond the gate,
As tidy docs grow clear and great.
With whiskers neat and errors few,
Tests keep hopping through.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific, concise, and accurately summarizes the main docstring RST validation change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/pyopenms-docstring-sphinx-roles

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pyOpenMS/tests/unittests/test_docstrings.py`:
- Around line 132-136: Update the role handling in test_docstrings.py so an
optional “py:” prefix is normalized before validating the role name against
_SPHINX_ROLES, rather than accepting every prefixed role. Preserve acceptance of
valid prefixed roles while rejecting misspellings such as py:methd, and add
regression coverage for both valid and invalid prefixed forms.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0f5ed328-b0b4-4261-abe2-824fe231dd13

📥 Commits

Reviewing files that changed from the base of the PR and between ed58560 and a5c4c58.

📒 Files selected for processing (1)
  • src/pyOpenMS/tests/unittests/test_docstrings.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@timosachsenberg
timosachsenberg merged commit cfc45ae into develop Jul 27, 2026
39 checks passed
@timosachsenberg
timosachsenberg deleted the test/pyopenms-docstring-sphinx-roles branch July 27, 2026 04:29
timosachsenberg added a commit that referenced this pull request Jul 30, 2026
Audited recently merged develop PRs against CHANGELOG (last backfill
attempt was #9811/#9806, covering up to #9803). Four merged PRs since
then were missing entries: #9824 (IsobaricWorkflow empty-feature
pruning fix), #9523 (new CI build/release workflows), #9812 (pyOpenMS
docstring fixes) and #9798 (Bioconda nightly deploy fix, whose two
prior backfill attempts were closed unmerged). #9821 (internal
TODO-comment correction, no behavior/doc change) and #9805/#9803
(test-only / already covered by the #9792 write-up) were left out,
consistent with this repo's convention of not logging
test-infrastructure-only or already-documented changes.


Claude-Session: https://claude.ai/code/session_01WU21QuzvxLH5BuSxatVikX

Co-authored-by: Claude <[email protected]>
timosachsenberg added a commit that referenced this pull request Aug 3, 2026
…9835, #9836 (#9841)

Backfills the QPX export spec-conformance series, the macOS PKG
notarization fix, and the Windows GUI DLL export fix that merged into
develop without changelog entries. #9805 and #9821 were intentionally
skipped (test-only / comment-only, no user-visible behavior change),
and #9818 was already documented.


Claude-Session: https://claude.ai/code/session_0118Yt3TZEMzhMhH6FwZPDVt

Co-authored-by: Claude <[email protected]>
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.

1 participant