Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ShaharNaveh
Copy link
Collaborator

@ShaharNaveh ShaharNaveh commented Sep 5, 2025

Summary by CodeRabbit

  • New Features
    • Added a built-in Python module "_sysconfig" exposing runtime configuration.
    • Provides config_vars() which returns a dict of interpreter config flags (e.g., Py_GIL_DISABLED=True).
    • Allows packages and scripts to query interpreter configuration programmatically.

Copy link
Contributor

coderabbitai bot commented Sep 5, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • Lib/test/test_faulthandler.py is excluded by !Lib/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds a new internal stdlib module _sysconfig (unconditionally compiled), registers it in the VM’s stdlib initializer map, and exposes a config_vars function that returns a dict with Py_GIL_DISABLED: True.

Changes

Cohort / File(s) Summary
Stdlib module registration
vm/src/stdlib/mod.rs
Adds mod sysconfig; and registers "_sysconfig" => sysconfig::make_module in get_module_inits().
_sysconfig module implementation & re-export
vm/src/stdlib/sysconfig.rs
Adds new PyO3-backed module pub(crate) mod sysconfig annotated #[pymodule(name = "_sysconfig")] exposing config_vars(vm) -> PyDictRef that returns a dict with Py_GIL_DISABLED: True, and re-exports make_module via pub(crate) use sysconfig::make_module;.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor App
    participant VM
    participant StdlibRegistry as "Stdlib Init Map"
    participant Sysconfig as "_sysconfig Module"

    App->>VM: import _sysconfig
    VM->>StdlibRegistry: lookup make_module("_sysconfig")
    StdlibRegistry-->>VM: sysconfig::make_module
    VM->>Sysconfig: initialize module
    VM-->>App: _sysconfig handle

    App->>Sysconfig: config_vars()
    activate Sysconfig
    Note over Sysconfig: Build dict {"Py_GIL_DISABLED": True}
    Sysconfig-->>App: PyDict
    deactivate Sysconfig
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble bytes where tunnels wind,
A tiny module I designed—
I set a flag, then hop away,
Py_GIL_DISABLED, yes, hooray! 🐇

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@ShaharNaveh ShaharNaveh marked this pull request as ready for review September 5, 2025 18:33
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
vm/src/stdlib/sysconfig.rs (2)

1-4: Avoid a redundant sysconfig::sysconfig path; use a conventional inner module name.

Align with existing pattern (module/decl) to improve clarity.

-pub(crate) use sysconfig::make_module;
-
-#[pymodule(name = "_sysconfig")]
-pub(crate) mod sysconfig {
+pub(crate) use module::make_module;
+
+#[pymodule(name = "_sysconfig")]
+pub(crate) mod module {

7-13: Return PyResult and drop unwrap for better error hygiene.

Matches common style in stdlib shims and keeps exceptions propagatable.

-    #[pyfunction]
-    fn config_vars(vm: &VirtualMachine) -> PyDictRef {
-        let vars = vm.ctx.new_dict();
-        vars.set_item("Py_GIL_DISABLED", false.to_pyobject(vm), vm)
-            .unwrap();
-        vars
-    }
+    use crate::PyResult;
+
+    #[pyfunction]
+    fn config_vars(vm: &VirtualMachine) -> PyResult<PyDictRef> {
+        let vars = vm.ctx.new_dict();
+        vars.set_item("Py_GIL_DISABLED", vm.ctx.new_bool(false), vm)?;
+        Ok(vars)
+    }
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 85ca280 and 02320d5.

⛔ Files ignored due to path filters (5)
  • Lib/site.py is excluded by !Lib/**
  • Lib/sysconfig/__init__.py is excluded by !Lib/**
  • Lib/sysconfig/__main__.py is excluded by !Lib/**
  • Lib/test/test_site.py is excluded by !Lib/**
  • Lib/test/test_sysconfig.py is excluded by !Lib/**
📒 Files selected for processing (2)
  • vm/src/stdlib/mod.rs (2 hunks)
  • vm/src/stdlib/sysconfig.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

Files:

  • vm/src/stdlib/mod.rs
  • vm/src/stdlib/sysconfig.rs
🧬 Code graph analysis (1)
vm/src/stdlib/mod.rs (2)
vm/src/stdlib/nt.rs (1)
  • make_module (7-11)
vm/src/stdlib/time.rs (1)
  • make_module (10-17)
🔇 Additional comments (3)
vm/src/stdlib/mod.rs (2)

21-21: Wiring the new stdlib module looks correct.

Unconditional mod sysconfig; is consistent with other always-available stdlib shims.


101-101: Registered initializer for "_sysconfig".

Entry points to sysconfig::make_module as expected; ordering among other entries is fine.

vm/src/stdlib/sysconfig.rs (1)

7-13: Verify that all required sysconfig config_vars keys are provided
Could not locate the vendored Python 3.13.7 sysconfig.py in this repo; please manually confirm that no additional keys beyond Py_GIL_DISABLED are expected by config_vars to prevent runtime failures.

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

👍

@@ -270,23 +282,26 @@ def check_enableusersite():
#
# See https://bugs.python.org/issue29585

# Copy of sysconfig._get_implementation()
def _get_implementation():
Copy link
Member

Choose a reason for hiding this comment

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

👍 finally this is shipped

@youknowone youknowone merged commit 7044d43 into RustPython:main Sep 8, 2025
12 checks passed
@ShaharNaveh ShaharNaveh deleted the update-site branch September 12, 2025 07:47
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