Skip to content

Honor no-site mode before importing site - #9045

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-no-site-import
Oct 10, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-no-site-import

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extract the Python 3.14-compatible startup site-import guard from #8954. Honor the existing import_site setting before importing site, preserving existing comments and error logging.

One concise regression in the existing sys snippet checks that -S leaves site absent from sys.modules. Existing canonical tests cover flag acceptance and customization side effects, which do not catch this missing behavior.

Validation

  • Independent source review against exact CPython 3.14.7 and duplicate check.
  • Full updated snippet passes CPython 3.14.7 and the freshly built native extraction head; unchanged source fails the new assertion.
  • Native pytest snippet selection: 1 passed.
  • Seven native startup flag combinations passed, including normal startup, -S, -E/-S and -I/-S.
  • Existing canonical test_cmd_line site-flag test passed with an isolated writable history directory.
  • Broader test_site execution could not complete locally because debug stack/recursion limits prevented importing its dependencies; hosted release coverage remains pending. No canonical assertions or skips were changed.
  • Normal hooks, root-library Clippy and separate CAPI Clippy passed.

Extraction, regression and validation were AI-assisted with OpenAI Codex. Draft pending full hosted platform/workspace/CAPI CI and review. README unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Running Python with -S now reliably skips importing site, consistent with the option’s behavior. Python’s startup flags correctly indicate that site was not loaded.

Extract the startup import_site guard from RustPython#8954. Preserve existing logging and comments, and cover the missing sys.modules behavior under -S in the existing sys snippet.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a477d3f-7a91-44f2-bfba-e3cfc88eff85

📥 Commits

Reviewing files that changed from the base of the PR and between 3af5f8a and 8ee5a6b.


📒 Files selected for processing (2)
  • extra_tests/snippets/stdlib_sys.py
  • src/lib.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

run_rustpython now imports site only when settings.import_site is enabled. A subprocess test checks that Python's -S option sets no_site and leaves site unimported.

Changes

Conditional site import

Layer / File(s) Summary
Gate the site import and test -S behavior
src/lib.rs, extra_tests/snippets/stdlib_sys.py
run_rustpython skips importing site when settings.import_site is false. The subprocess test checks that -S sets sys.flags.no_site and leaves site out of sys.modules.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: youknowone


Merge Risk: ⚪ Minimal · up to 8ee5a

The change preserves -S startup behavior by avoiding the site import and adds a regression check. No actionable merge-blocking risk is identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing the site import when no-site mode is enabled.
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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@youknowone
youknowone marked this pull request as ready for review October 10, 2026 10:54
@youknowone
youknowone enabled auto-merge (squash) October 10, 2026 10:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T10:57:16.267707Z 8ee5a6b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ee5a6be60

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

sys.executable,
"-S",
"-c",
"import sys; assert sys.flags.no_site; assert 'site' not in sys.modules",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the newly added test logic

The new subprocess assertion adds test logic to a test file, but the repository's critical AGENTS.md policy explicitly forbids modifying test assertions or test logic. Keep the production guard, but remove this regression block rather than changing extra_tests/snippets/stdlib_sys.py.

AGENTS.md reference: AGENTS.md:L273-L275

Useful? React with 👍 / 👎.

@youknowone
youknowone merged commit c770c41 into RustPython:main Oct 10, 2026
30 checks passed
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.

2 participants