MCPcopy Index your code
hub / github.com/RustPython/RustPython / run

Function run

src/lib.rs:86–124  ·  view source on GitHub ↗

The main cli of the `rustpython` interpreter. This function will return `std::process::ExitCode` based on the return code of the python code ran through the cli. Note**: This function provides no way to further initialize the VM after the builder is applied. All VM initialization (adding native modules, init hooks, etc.) must be done through the [`InterpreterBuilder`] parameter before calling thi

(mut builder: InterpreterBuilder)

Source from the content-addressed store, hash-verified

84/// All VM initialization (adding native modules, init hooks, etc.) must be done through the
85/// [`InterpreterBuilder`] parameter before calling this function.
86pub fn run(mut builder: InterpreterBuilder) -> ExitCode {
87 env_logger::init();
88
89 // NOTE: This is not a WASI convention. But it will be convenient since POSIX shell always defines it.
90 #[cfg(target_os = "wasi")]
91 {
92 if let Ok(pwd) = env::var("PWD") {
93 let _ = env::set_current_dir(pwd);
94 };
95 }
96
97 let (settings, run_mode) = match parse_opts() {
98 Ok(x) => x,
99 Err(e) => {
100 println!("{e}");
101 return ExitCode::FAILURE;
102 }
103 };
104
105 // don't translate newlines (\r\n <=> \n)
106 #[cfg(windows)]
107 {
108 unsafe extern "C" {
109 fn _setmode(fd: i32, flags: i32) -> i32;
110 }
111 unsafe {
112 _setmode(0, libc::O_BINARY);
113 _setmode(1, libc::O_BINARY);
114 _setmode(2, libc::O_BINARY);
115 }
116 }
117
118 builder = builder.settings(settings);
119
120 let interp = builder.interpreter();
121 let exitcode = interp.run(move |vm| run_rustpython(vm, run_mode));
122
123 rustpython_vm::common::os::exit_code(exitcode)
124}
125
126fn get_pip(scope: Scope, vm: &VirtualMachine) -> PyResult<()> {
127 let get_getpip = rustpython_vm::py_compile!(

Callers 1

mainFunction · 0.70

Calls 7

parse_optsFunction · 0.85
run_rustpythonFunction · 0.85
exit_codeFunction · 0.85
settingsMethod · 0.80
initFunction · 0.50
interpreterMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected