rustpython_vm/stdlib/
mod.rs1#[cfg(feature = "rustpython-ast")]
2pub(crate) mod ast;
3pub mod atexit;
4pub mod builtins;
5mod codecs;
6mod collections;
7pub mod errno;
8mod functools;
9mod imp;
10pub mod io;
11mod itertools;
12mod marshal;
13mod operator;
14mod sre;
17mod string;
18#[cfg(feature = "rustpython-compiler")]
19mod symtable;
20mod sysconfigdata;
21#[cfg(feature = "threading")]
22pub mod thread;
23pub mod time;
24pub mod typing;
25pub mod warnings;
26mod weakref;
27
28#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
29#[macro_use]
30pub mod os;
31#[cfg(windows)]
32pub mod nt;
33#[cfg(unix)]
34pub mod posix;
35#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
36#[cfg(not(any(unix, windows)))]
37#[path = "posix_compat.rs"]
38pub mod posix;
39
40#[cfg(windows)]
41pub(crate) mod msvcrt;
42#[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
43mod pwd;
44pub(crate) mod signal;
45pub mod sys;
46#[cfg(windows)]
47mod winapi;
48#[cfg(windows)]
49mod winreg;
50
51use crate::{builtins::PyModule, PyRef, VirtualMachine};
52use std::{borrow::Cow, collections::HashMap};
53
54pub type StdlibInitFunc = Box<py_dyn_fn!(dyn Fn(&VirtualMachine) -> PyRef<PyModule>)>;
55pub type StdlibMap = HashMap<Cow<'static, str>, StdlibInitFunc, ahash::RandomState>;
56
57pub fn get_module_inits() -> StdlibMap {
58 macro_rules! modules {
59 {
60 $(
61 #[cfg($cfg:meta)]
62 { $( $key:expr => $val:expr),* $(,)? }
63 )*
64 } => {{
65 let modules = [
66 $(
67 $(#[cfg($cfg)] (Cow::<'static, str>::from($key), Box::new($val) as StdlibInitFunc),)*
68 )*
69 ];
70 modules.into_iter().collect()
71 }};
72 }
73 modules! {
74 #[cfg(all())]
75 {
76 "atexit" => atexit::make_module,
77 "_codecs" => codecs::make_module,
78 "_collections" => collections::make_module,
79 "errno" => errno::make_module,
80 "_functools" => functools::make_module,
81 "itertools" => itertools::make_module,
82 "_io" => io::make_module,
83 "marshal" => marshal::make_module,
84 "_operator" => operator::make_module,
85 "_signal" => signal::make_module,
86 "_sre" => sre::make_module,
87 "_string" => string::make_module,
88 "time" => time::make_module,
89 "_typing" => typing::make_module,
90 "_weakref" => weakref::make_module,
91 "_imp" => imp::make_module,
92 "_warnings" => warnings::make_module,
93 sys::sysconfigdata_name() => sysconfigdata::make_module,
94 }
95 #[cfg(feature = "rustpython-ast")]
97 {
98 "_ast" => ast::make_module,
99 }
100 #[cfg(feature = "rustpython-compiler")]
102 {
103 "symtable" => symtable::make_module,
104 }
105 #[cfg(any(unix, target_os = "wasi"))]
106 {
107 "posix" => posix::make_module,
108 }
110 #[cfg(feature = "threading")]
111 {
112 "_thread" => thread::make_module,
113 }
114 #[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
116 {
117 "pwd" => pwd::make_module,
118 }
119 #[cfg(windows)]
121 {
122 "nt" => nt::make_module,
123 "msvcrt" => msvcrt::make_module,
124 "_winapi" => winapi::make_module,
125 "winreg" => winreg::make_module,
126 }
127 }
128}