@@ -248,6 +248,38 @@ fn add_stdlib(vm: &mut VirtualMachine) {
248248 let _ = vm;
249249 #[ cfg( feature = "stdlib" ) ]
250250 vm. add_native_modules ( rustpython_stdlib:: get_module_inits ( ) ) ;
251+
252+ // if we're on freeze-stdlib, the core stdlib modules will be included anyway
253+ #[ cfg( feature = "freeze-stdlib" ) ]
254+ vm. add_frozen ( rustpython_pylib:: frozen_stdlib ( ) ) ;
255+
256+ #[ cfg( not( feature = "freeze-stdlib" ) ) ]
257+ {
258+ use rustpython_vm:: common:: rc:: PyRc ;
259+ let state = PyRc :: get_mut ( & mut vm. state ) . unwrap ( ) ;
260+
261+ #[ allow( clippy:: needless_collect) ] // false positive
262+ let path_list: Vec < _ > = state. settings . path_list . drain ( ..) . collect ( ) ;
263+
264+ // add the current directory to sys.path
265+ state. settings . path_list . push ( "" . to_owned ( ) ) ;
266+
267+ // BUILDTIME_RUSTPYTHONPATH should be set when distributing
268+ if let Some ( paths) = option_env ! ( "BUILDTIME_RUSTPYTHONPATH" ) {
269+ state
270+ . settings
271+ . path_list
272+ . extend ( split_paths ( paths) . map ( |path| path. into_os_string ( ) . into_string ( ) . unwrap ( ) ) )
273+ } else {
274+ #[ cfg( feature = "rustpython-pylib" ) ]
275+ state
276+ . settings
277+ . path_list
278+ . push ( rustpython_pylib:: LIB_PATH . to_owned ( ) )
279+ }
280+
281+ state. settings . path_list . extend ( path_list. into_iter ( ) ) ;
282+ }
251283}
252284
253285/// Create settings by examining command line arguments and environment
@@ -264,21 +296,6 @@ fn create_settings(matches: &ArgMatches) -> Settings {
264296
265297 let ignore_environment = settings. ignore_environment || settings. isolated ;
266298
267- // when rustpython-vm/pylib is enabled, Settings::default().path_list has pylib::LIB_PATH
268- let maybe_pylib = settings. path_list . pop ( ) ;
269-
270- // add the current directory to sys.path
271- settings. path_list . push ( "" . to_owned ( ) ) ;
272-
273- // BUILDTIME_RUSTPYTHONPATH should be set when distributing
274- if let Some ( paths) = option_env ! ( "BUILDTIME_RUSTPYTHONPATH" ) {
275- settings
276- . path_list
277- . extend ( split_paths ( paths) . map ( |path| path. into_os_string ( ) . into_string ( ) . unwrap ( ) ) )
278- } else {
279- settings. path_list . extend ( maybe_pylib) ;
280- }
281-
282299 if !ignore_environment {
283300 settings. path_list . extend ( get_paths ( "RUSTPYTHONPATH" ) ) ;
284301 settings. path_list . extend ( get_paths ( "PYTHONPATH" ) ) ;
0 commit comments