You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix encodings related error messages to be less confusing (RustPython#5049)
* Move cwd setup to interpreter code
* rework import encodings failure message
* try import_encodings only when `path_list` is set
* std::mem::take instead of drain(..).collect()
* Add empty path_list warnings to import_encodings
* Prepend current working directory when !safe_path
Co-authored-by: fanninpm <fanninpm@miamioh.edu>
"Neither RUSTPYTHONPATH nor PYTHONPATH is set. Try setting one of them to the stdlib directory."
235
+
}elseif path_contains_env {
236
+
"RUSTPYTHONPATH or PYTHONPATH is set, but it doesn't contain the encodings library. If you are customizing the RustPython vm/interpreter, try adding the stdlib directory to the path. If you are developing the RustPython interpreter, it might be a bug during development."
231
237
}else{
232
-
"Could not import encodings. Try adding your path to Setting struct's path_list field. If you don't have \
233
-
access to a consistent external environment (e.g. if you're embedding \
234
-
rustpython in another application), try enabling the freeze-stdlib feature"
235
-
.to_owned()
238
+
"RUSTPYTHONPATH or PYTHONPATH is set, but it wasn't loaded to `Settings::path_list`. If you are going to customize the RustPython vm/interpreter, those environment variables are not loaded in the Settings struct by default. Please try creating a customized instance of the Settings struct. If you are developing the RustPython interpreter, it might be a bug during development."
236
239
};
237
240
241
+
let msg = format!(
242
+
"RustPython could not import the encodings module. It usually means something went wrong. Please carefully read the following messages and follow the steps.\n\
243
+
\n\
244
+
{guide_message}\n\
245
+
If you don't have access to a consistent external environment (e.g. targeting wasm, embedding \
246
+
rustpython in another application), try enabling the `freeze-stdlib` feature.\n\
247
+
If this is intended and you want to exclude the encodings module from your interpreter, please remove the `encodings` feature from `rustpython-vm` crate."
"encodings initialization failed. Only utf-8 encoding will be supported."
343
+
);
344
+
self.print_exception(e);
345
+
}
346
+
}else{
347
+
// Here may not be the best place to give general `path_list` advice,
348
+
// but bare rustpython_vm::VirtualMachine users skipped proper settings must hit here while properly setup vm never enters here.
349
+
eprintln!(
350
+
"feature `encodings` is enabled but `settings.path_list` is empty. \
351
+
Please add the library path to `settings.path_list`. If you intended to disable the entire standard library (including the `encodings` feature), please also make sure to disable the `encodings` feature.\n\
352
+
Tip: You may also want to add `\"\"` to `settings.path_list` in order to enable importing from the current working directory."
0 commit comments