From e021c224a7334054d8250db627eba76dbbe10af7 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Sun, 18 Jan 2026 17:54:01 +0900 Subject: [PATCH] init warnings before site --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 11f6dc01c3..cf5227a70d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,6 +208,12 @@ fn run_rustpython(vm: &VirtualMachine, run_mode: RunMode) -> PyResult<()> { let scope = vm.new_scope_with_main()?; + // Initialize warnings module to process sys.warnoptions + // _PyWarnings_Init() + if vm.import("warnings", 0).is_err() { + warn!("Failed to import warnings module"); + } + // Import site first, before setting sys.path[0] // This matches CPython's behavior where site.removeduppaths() runs // before sys.path[0] is set, preventing '' from being converted to cwd @@ -219,12 +225,6 @@ fn run_rustpython(vm: &VirtualMachine, run_mode: RunMode) -> PyResult<()> { ); } - // Initialize warnings module to process sys.warnoptions - // _PyWarnings_Init() - if vm.import("warnings", 0).is_err() { - warn!("Failed to import warnings module"); - } - // _PyPathConfig_ComputeSysPath0 - set sys.path[0] after site import if !vm.state.config.settings.safe_path { let path0: Option = match &run_mode {