Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions crates/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ crate-type = ["cdylib", "rlib"]
bitflags = { workspace = true }
itertools = { workspace = true }
num-complex = { workspace = true }
rustpython-vm = { workspace = true, features = ["threading", "compiler"] }
rustpython-vm = { workspace = true, features = ["threading", "compiler", "importlib", "host_env"] }
rustpython-stdlib = {workspace = true, features = ["threading"] }
rustpython-pylib = { workspace = true }

[dev-dependencies]
pyo3 = { workspace = true, features = ["auto-initialize", "abi3"] }

[lints]
workspace = true

[package.metadata.cargo-shear]
# Not a direct dependency (yet), but we need to enable threading support in the stdlib.
ignored = ["rustpython-stdlib"]
7 changes: 7 additions & 0 deletions crates/capi/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ mod tests {
let _module = py.import("sys").unwrap();
})
}

#[test]
fn import_stdlib() {
Python::attach(|py| {
let _module = py.import("types").unwrap();
})
}
}
15 changes: 14 additions & 1 deletion crates/capi/src/pylifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::get_main_interpreter;
use crate::pyerrors::init_exception_statics;
use crate::pystate::ensure_thread_has_vm_attached;
use core::ffi::c_int;
use rustpython_vm::common::rc::PyRc;
use rustpython_vm::vm::thread::ThreadedVirtualMachine;
use rustpython_vm::{Context, Interpreter};
use std::sync::Mutex;
Expand Down Expand Up @@ -32,7 +33,19 @@ pub extern "C" fn Py_InitializeEx(_initsigs: c_int) {
if interp.is_none() {
// Safety: Interpreter was not initialized before, so we can safely assume the statics are not used
unsafe { init_exception_statics(&Context::genesis().exceptions) };
*interp = Interpreter::with_init(Default::default(), |_vm| {}).into();
let builder = Interpreter::builder(Default::default());
let defs = rustpython_stdlib::stdlib_module_defs(&builder.ctx);
*interp = builder
.add_native_modules(&defs)
.init_hook(|vm| {
let state = PyRc::get_mut(&mut vm.state).unwrap();
let path = rustpython_pylib::LIB_PATH.to_owned();

state.config.paths.stdlib_dir = Some(path.clone());
state.config.paths.module_search_paths.insert(0, path);
})
.build()
.into();
drop(interp);
ensure_thread_has_vm_attached();
}
Expand Down
Loading