Skip to content

[rntuple] Fix the circular import when rootfilespec.rntuple is imported first - #126

Open
sathabbott wants to merge 2 commits into
nsmith-:mainfrom
sathabbott:fix/119-circular-import
Open

sathabbott wants to merge 2 commits into
nsmith-:mainfrom
sathabbott:fix/119-circular-import

Conversation

@sathabbott

Copy link
Copy Markdown
Collaborator

🤖 AI generated content

Fixes #119.

import rootfilespec.rntuple.schema (or any rootfilespec.rntuple.* module) in a fresh interpreter failed: rntuple.envelope imports bootstrap.compression, which runs bootstrap/__init__.py, which imports RAnchor, which imported the half-initialized rntuple.envelope.

RAnchor only needs REnvelopeLocator, HeaderEnvelope, FooterEnvelope and LargeLocator inside header_locator, footer_locator, get_header and get_footer, so they are now imported there, and under TYPE_CHECKING for the annotations. No behaviour change.

Test: tests/test_imports.py imports every module of the package in its own interpreter (35 modules). On main, all the rntuple modules fail.

Found along the way, not fixed here: rootfilespec.container has the same kind of cycle (container → bootstrap/__init__ → bootstrap.array → container). It is marked xfail(strict=True) in the new test, so it will flag when fixed. Happy to fix it here or in a follow-up if you'd like; it isn't RNTuple, so I left it.

Full suite: 389 passed, 53 skipped, 47 xfailed.

Assisted-by: claude-code:claude-opus-5-5

Importing any rootfilespec.rntuple module before rootfilespec.bootstrap
failed with a circular import: rntuple.envelope imports
bootstrap.compression, which runs bootstrap/__init__, which imports RAnchor,
which imported the half-initialized rntuple.envelope.

RAnchor only needs the rntuple names inside header_locator, footer_locator,
get_header and get_footer, so import them there (and under TYPE_CHECKING
for the annotations).

tests/test_imports.py imports every module in a fresh interpreter.
rootfilespec.container has the same kind of cycle through
bootstrap.array and is marked as a strict expected failure.

Fixes nsmith-#119

Assisted-by: claude-code:claude-opus-5-5
The repository's pinned ruff (0.9.2, pre-commit) does not enable PLC0415,
so it reports these as unused noqa directives (RUF100).

Assisted-by: claude-code:claude-opus-5-5
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.83%. Comparing base (3f43287) to head (a64b38e).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #126   +/-   ##
=======================================
  Coverage   91.82%   91.83%           
=======================================
  Files          37       37           
  Lines        2962     2964    +2     
=======================================
+ Hits         2720     2722    +2     
  Misses        242      242           

☔ View full report in Codecov by Harness.
📢 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.

@nsmith-

nsmith- commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Found along the way, not fixed here: rootfilespec.container has the same kind of cycle (container → bootstrap/init → bootstrap.array → container). It is marked xfail(strict=True) in the new test, so it will flag when fixed. Happy to fix it here or in a follow-up if you'd like; it isn't RNTuple, so I left it.

Go ahead and fix the other case

This branch has not been deployed

No deployments
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.

[rntuple] Importing rootfilespec.rntuple before rootfilespec.bootstrap fails with a circular import

3 participants