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

Skip to content

Commit c11f37d

Browse files
committed
fix more site
1 parent 5955d1f commit c11f37d

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

Lib/test/test_cmd_line_script.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ def test_issue8202(self):
411411
script_name, script_name, script_dir, 'test_pkg',
412412
importlib.machinery.SourceFileLoader)
413413

414-
# TODO: RUSTPYTHON
415-
@unittest.expectedFailure
416414
def test_issue8202_dash_c_file_ignored(self):
417415
# Make sure a "-c" file in the current directory
418416
# does not alter the value of sys.path[0]
@@ -713,8 +711,6 @@ def test_syntaxerror_null_bytes_in_multiline_string(self):
713711
]
714712
)
715713

716-
# TODO: RUSTPYTHON
717-
@unittest.expectedFailure
718714
def test_consistent_sys_path_for_direct_execution(self):
719715
# This test case ensures that the following all give the same
720716
# sys.path configuration:

src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,18 @@ fn run_rustpython(vm: &VirtualMachine, run_mode: RunMode) -> PyResult<()> {
169169

170170
let scope = setup_main_module(vm)?;
171171

172-
// _PyPathConfig_ComputeSysPath0
172+
// Import site first, before setting sys.path[0]
173+
// This matches CPython's behavior where site.removeduppaths() runs
174+
// before sys.path[0] is set, preventing '' from being converted to cwd
175+
let site_result = vm.import("site", 0);
176+
if site_result.is_err() {
177+
warn!(
178+
"Failed to import site, consider adding the Lib directory to your RUSTPYTHONPATH \
179+
environment variable",
180+
);
181+
}
182+
183+
// _PyPathConfig_ComputeSysPath0 - set sys.path[0] after site import
173184
if !vm.state.config.settings.safe_path {
174185
let path0: Option<String> = match &run_mode {
175186
RunMode::Command(_) => Some(String::new()),
@@ -185,14 +196,6 @@ fn run_rustpython(vm: &VirtualMachine, run_mode: RunMode) -> PyResult<()> {
185196
}
186197
}
187198

188-
let site_result = vm.import("site", 0);
189-
if site_result.is_err() {
190-
warn!(
191-
"Failed to import site, consider adding the Lib directory to your RUSTPYTHONPATH \
192-
environment variable",
193-
);
194-
}
195-
196199
// Enable faulthandler if -X faulthandler, PYTHONFAULTHANDLER or -X dev is set
197200
// _PyFaulthandler_Init()
198201
if vm.state.config.settings.faulthandler {

0 commit comments

Comments
 (0)