File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -169,14 +169,20 @@ fn run_rustpython(vm: &VirtualMachine, run_mode: RunMode) -> PyResult<()> {
169169
170170 let scope = setup_main_module ( vm) ?;
171171
172+ // _PyPathConfig_ComputeSysPath0
172173 if !vm. state . config . settings . safe_path {
173- // TODO: The prepending path depends on running mode
174- // See https://docs.python.org/3/using/cmdline.html#cmdoption-P
175- vm. run_code_string (
176- vm. new_scope_with_builtins ( ) ,
177- "import sys; sys.path.insert(0, '')" ,
178- "<embedded>" . to_owned ( ) ,
179- ) ?;
174+ let path0: Option < String > = match & run_mode {
175+ RunMode :: Command ( _) => Some ( String :: new ( ) ) ,
176+ RunMode :: Module ( _) => env:: current_dir ( )
177+ . ok ( )
178+ . and_then ( |p| p. to_str ( ) . map ( |s| s. to_owned ( ) ) ) ,
179+ RunMode :: Script ( _) | RunMode :: InstallPip ( _) => None , // handled by run_script
180+ RunMode :: Repl => Some ( String :: new ( ) ) ,
181+ } ;
182+
183+ if let Some ( path) = path0 {
184+ vm. insert_sys_path ( vm. new_pyobj ( path) ) ?;
185+ }
180186 }
181187
182188 let site_result = vm. import ( "site" , 0 ) ;
You can’t perform that action at this time.
0 commit comments