rustpython_stdlib/
lib.rs

1// to allow `mod foo {}` in foo.rs; clippy thinks this is a mistake/misunderstanding of
2// how `mod` works, but we want this sometimes for pymodule declarations
3#![allow(clippy::module_inception)]
4
5#[macro_use]
6extern crate rustpython_derive;
7
8pub mod array;
9mod binascii;
10mod bisect;
11mod cmath;
12mod contextvars;
13mod csv;
14mod dis;
15mod gc;
16
17mod blake2;
18mod hashlib;
19mod md5;
20mod sha1;
21mod sha256;
22mod sha3;
23mod sha512;
24
25mod json;
26#[cfg(not(any(target_os = "ios", target_os = "android", target_arch = "wasm32")))]
27mod locale;
28mod math;
29#[cfg(unix)]
30mod mmap;
31mod pyexpat;
32mod pystruct;
33mod random;
34mod statistics;
35// TODO: maybe make this an extension module, if we ever get those
36// mod re;
37#[cfg(feature = "bz2")]
38mod bz2;
39#[cfg(not(target_arch = "wasm32"))]
40pub mod socket;
41#[cfg(all(unix, not(target_os = "redox")))]
42mod syslog;
43mod unicodedata;
44mod zlib;
45
46mod faulthandler;
47#[cfg(any(unix, target_os = "wasi"))]
48mod fcntl;
49#[cfg(not(target_arch = "wasm32"))]
50mod multiprocessing;
51#[cfg(unix)]
52mod posixsubprocess;
53// libc is missing constants on redox
54#[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
55mod grp;
56#[cfg(windows)]
57mod overlapped;
58#[cfg(all(unix, not(target_os = "redox")))]
59mod resource;
60#[cfg(target_os = "macos")]
61mod scproxy;
62#[cfg(any(unix, windows, target_os = "wasi"))]
63mod select;
64#[cfg(not(any(target_os = "android", target_arch = "wasm32")))]
65mod sqlite;
66#[cfg(all(not(target_arch = "wasm32"), feature = "ssl"))]
67mod ssl;
68#[cfg(all(unix, not(target_os = "redox"), not(target_os = "ios")))]
69mod termios;
70#[cfg(not(any(
71    target_os = "android",
72    target_os = "ios",
73    target_os = "windows",
74    target_arch = "wasm32",
75    target_os = "redox",
76)))]
77mod uuid;
78
79use rustpython_common as common;
80use rustpython_vm as vm;
81
82use crate::vm::{builtins, stdlib::StdlibInitFunc};
83use std::borrow::Cow;
84
85pub fn get_module_inits() -> impl Iterator<Item = (Cow<'static, str>, StdlibInitFunc)> {
86    macro_rules! modules {
87        {
88            $(
89                #[cfg($cfg:meta)]
90                { $( $key:expr => $val:expr),* $(,)? }
91            )*
92        } => {{
93            [
94                $(
95                    $(#[cfg($cfg)] (Cow::<'static, str>::from($key), Box::new($val) as StdlibInitFunc),)*
96                )*
97            ]
98            .into_iter()
99        }};
100    }
101    modules! {
102        #[cfg(all())]
103        {
104            "array" => array::make_module,
105            "binascii" => binascii::make_module,
106            "_bisect" => bisect::make_module,
107            "cmath" => cmath::make_module,
108            "_contextvars" => contextvars::make_module,
109            "_csv" => csv::make_module,
110            "_dis" => dis::make_module,
111            "faulthandler" => faulthandler::make_module,
112            "gc" => gc::make_module,
113            "_hashlib" => hashlib::make_module,
114            "_sha1" => sha1::make_module,
115            "_sha3" => sha3::make_module,
116            "_sha256" => sha256::make_module,
117            "_sha512" => sha512::make_module,
118            "_md5" => md5::make_module,
119            "_blake2" => blake2::make_module,
120            "_json" => json::make_module,
121            "math" => math::make_module,
122            "pyexpat" => pyexpat::make_module,
123            "_random" => random::make_module,
124            "_statistics" => statistics::make_module,
125            "_struct" => pystruct::make_module,
126            "unicodedata" => unicodedata::make_module,
127            "zlib" => zlib::make_module,
128            "_statistics" => statistics::make_module,
129            // crate::vm::sysmodule::sysconfigdata_name() => sysconfigdata::make_module,
130        }
131        #[cfg(any(unix, target_os = "wasi"))]
132        {
133            "fcntl" => fcntl::make_module,
134        }
135        #[cfg(any(unix, windows, target_os = "wasi"))]
136        {
137            "select" => select::make_module,
138        }
139        #[cfg(not(target_arch = "wasm32"))]
140        {
141            "_multiprocessing" => multiprocessing::make_module,
142            "_socket" => socket::make_module,
143        }
144        #[cfg(not(any(target_os = "android", target_arch = "wasm32")))]
145        {
146            "_sqlite3" => sqlite::make_module,
147        }
148        #[cfg(feature = "ssl")]
149        {
150            "_ssl" => ssl::make_module,
151        }
152        #[cfg(feature = "bz2")]
153        {
154            "_bz2" => bz2::make_module,
155        }
156        #[cfg(windows)]
157        {
158            "_overlapped" => overlapped::make_module,
159        }
160        // Unix-only
161        #[cfg(unix)]
162        {
163            "_posixsubprocess" => posixsubprocess::make_module,
164            "mmap" => mmap::make_module,
165        }
166        #[cfg(all(unix, not(target_os = "redox")))]
167        {
168            "syslog" => syslog::make_module,
169            "resource" => resource::make_module,
170        }
171        #[cfg(all(unix, not(any(target_os = "ios", target_os = "redox"))))]
172        {
173            "termios" => termios::make_module,
174        }
175        #[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
176        {
177            "grp" => grp::make_module,
178        }
179        #[cfg(target_os = "macos")]
180        {
181            "_scproxy" => scproxy::make_module,
182        }
183        #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "windows", target_arch = "wasm32", target_os = "redox")))]
184        {
185            "_uuid" => uuid::make_module,
186        }
187        #[cfg(not(any(target_os = "ios", target_os = "android", target_arch = "wasm32")))]
188        {
189            "_locale" => locale::make_module,
190        }
191    }
192}