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

Function py_main

examples/package_embed.rs:5–16  ·  view source on GitHub ↗
(interp: &Interpreter)

Source from the content-addressed store, hash-verified

3use vm::{Interpreter, builtins::PyStrRef};
4
5fn py_main(interp: &Interpreter) -> vm::PyResult<PyStrRef> {
6 interp.enter(|vm| {
7 // Add local library path
8 vm.insert_sys_path(vm.new_pyobj("examples"))
9 .expect("add examples to sys.path failed");
10 let module = vm.import("package_embed", 0)?;
11 let name_func = module.get_attr("context", vm)?;
12 let result = name_func.call((), vm)?;
13 let result: PyStrRef = result.get_attr("name", vm)?.try_into_value(vm)?;
14 vm::PyResult::Ok(result)
15 })
16}
17
18fn main() -> ExitCode {
19 // Add standard library path

Callers 1

mainFunction · 0.70

Calls 7

insert_sys_pathMethod · 0.80
new_pyobjMethod · 0.80
try_into_valueMethod · 0.80
enterMethod · 0.45
importMethod · 0.45
get_attrMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected