forked from Rust-related/RustPython
replace py_module! from errno and sysconfigdata
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
use crate::VirtualMachine;
|
||||
use crate::{ItemProtocol, PyObjectRef};
|
||||
|
||||
#[pymodule]
|
||||
mod errno {}
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let module = errno::make_module(vm);
|
||||
let errorcode = vm.ctx.new_dict();
|
||||
let module = py_module!(vm, "errno", {
|
||||
extend_module!(vm, module, {
|
||||
"errorcode" => errorcode.clone(),
|
||||
});
|
||||
for (name, code) in ERROR_CODES {
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
use super::sys::MULTIARCH;
|
||||
use crate::{function::IntoPyObject, ItemProtocol, PyObjectRef, VirtualMachine};
|
||||
pub(crate) use _sysconfigdata::make_module;
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let vars = vm.ctx.new_dict();
|
||||
macro_rules! sysvars {
|
||||
($($key:literal => $value:expr),*$(,)?) => {{
|
||||
$(vars.set_item($key, $value.into_pyobject(vm), vm).unwrap();)*
|
||||
}};
|
||||
}
|
||||
sysvars! {
|
||||
// fake shared module extension
|
||||
"EXT_SUFFIX" => format!(".rustpython-{}", MULTIARCH),
|
||||
"MULTIARCH" => MULTIARCH,
|
||||
// enough for tests to stop expecting urandom() to fail after restricting file resources
|
||||
"HAVE_GETRANDOM" => 1,
|
||||
}
|
||||
include!(concat!(env!("OUT_DIR"), "/env_vars.rs"));
|
||||
#[pymodule]
|
||||
pub(crate) mod _sysconfigdata {
|
||||
use crate::{
|
||||
builtins::PyDictRef, function::IntoPyObject, stdlib::sys::MULTIARCH, ItemProtocol,
|
||||
VirtualMachine,
|
||||
};
|
||||
|
||||
py_module!(vm, "_sysconfigdata", {
|
||||
"build_time_vars" => vars,
|
||||
})
|
||||
#[pyattr]
|
||||
fn build_time_vars(vm: &VirtualMachine) -> PyDictRef {
|
||||
let vars = vm.ctx.new_dict();
|
||||
macro_rules! sysvars {
|
||||
($($key:literal => $value:expr),*$(,)?) => {{
|
||||
$(vars.set_item($key, $value.into_pyobject(vm), vm).unwrap();)*
|
||||
}};
|
||||
}
|
||||
sysvars! {
|
||||
// fake shared module extension
|
||||
"EXT_SUFFIX" => format!(".rustpython-{}", MULTIARCH),
|
||||
"MULTIARCH" => MULTIARCH,
|
||||
// enough for tests to stop expecting urandom() to fail after restricting file resources
|
||||
"HAVE_GETRANDOM" => 1,
|
||||
}
|
||||
include!(concat!(env!("OUT_DIR"), "/env_vars.rs"));
|
||||
vars
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user