Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prepend current working directory when !safe_path
  • Loading branch information
youknowone committed Aug 30, 2023
commit 3fa877321488e1c1b119457a3cce707733858cfb
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ pub fn run(init: impl FnOnce(&mut VirtualMachine) + 'static) -> ExitCode {
}
}

// add current working directory to sys.path
let settings = settings.with_path("".to_owned());
let mut config = InterpreterConfig::new().settings(settings);
#[cfg(feature = "stdlib")]
{
Expand Down Expand Up @@ -167,8 +165,17 @@ fn run_rustpython(vm: &VirtualMachine, run_mode: RunMode, quiet: bool) -> PyResu

let scope = setup_main_module(vm)?;

let site_result = vm.import("site", None, 0);
if !vm.state.settings.safe_path {
// TODO: The prepending path depends on running mode
// See https://docs.python.org/3/using/cmdline.html#cmdoption-P
vm.run_code_string(
vm.new_scope_with_builtins(),
"import sys; sys.path.insert(0, '')",
"<embedded>".to_owned(),
)?;
}

let site_result = vm.import("site", None, 0);
if site_result.is_err() {
warn!(
"Failed to import site, consider adding the Lib directory to your RUSTPYTHONPATH \
Expand Down