Skip to content

Commit 2cae714

Browse files
Auto-format: cargo fmt --all
1 parent c35986a commit 2cae714

1 file changed

Lines changed: 29 additions & 26 deletions

File tree

‎src/interpreter.rs‎

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub type InitHook = Box<dyn FnOnce(&mut VirtualMachine)>;
77
/// # Basic Usage
88
/// ```no_run
99
/// use rustpython::InterpreterConfig;
10-
///
10+
///
1111
/// let interpreter = InterpreterConfig::new()
1212
/// .init_stdlib()
1313
/// .interpreter();
@@ -17,13 +17,13 @@ pub type InitHook = Box<dyn FnOnce(&mut VirtualMachine)>;
1717
/// ```no_run
1818
/// use rustpython_vm::Settings;
1919
/// use rustpython::InterpreterConfig;
20-
///
20+
///
2121
/// let mut settings = Settings::default();
2222
/// settings.debug = 1;
2323
/// // Add paths to allow importing Python libraries
2424
/// settings.path_list.push("Lib".to_owned()); // standard library directory
2525
/// settings.path_list.push("".to_owned()); // current working directory
26-
///
26+
///
2727
/// let interpreter = InterpreterConfig::new()
2828
/// .settings(settings)
2929
/// .interpreter();
@@ -33,12 +33,12 @@ pub type InitHook = Box<dyn FnOnce(&mut VirtualMachine)>;
3333
/// ```no_run
3434
/// use rustpython::InterpreterConfig;
3535
/// use rustpython_vm::{VirtualMachine, PyRef, builtins::PyModule};
36-
///
36+
///
3737
/// fn make_custom_module(vm: &VirtualMachine) -> PyRef<PyModule> {
3838
/// // Your module implementation
3939
/// # todo!()
4040
/// }
41-
///
41+
///
4242
/// let interpreter = InterpreterConfig::new()
4343
/// .init_stdlib()
4444
/// .add_native_module(
@@ -60,7 +60,7 @@ impl InterpreterConfig {
6060
}
6161

6262
/// Build the interpreter with the current configuration
63-
///
63+
///
6464
/// # Panics
6565
/// May panic if initialization hooks encounter fatal errors
6666
pub fn interpreter(self) -> Interpreter {
@@ -73,27 +73,27 @@ impl InterpreterConfig {
7373
}
7474

7575
/// Set custom settings for the interpreter
76-
///
76+
///
7777
/// If called multiple times, only the last settings will be used
7878
pub fn settings(mut self, settings: Settings) -> Self {
7979
self.settings = Some(settings);
8080
self
8181
}
8282

8383
/// Add a custom initialization hook
84-
///
84+
///
8585
/// Hooks are executed in the order they are added during interpreter creation
8686
pub fn init_hook(mut self, hook: InitHook) -> Self {
8787
self.init_hooks.push(hook);
8888
self
8989
}
9090

9191
/// Add a native module to the interpreter
92-
///
92+
///
9393
/// # Arguments
9494
/// * `name` - The module name that will be used for imports
9595
/// * `make_module` - Function that creates the module when called
96-
///
96+
///
9797
/// # Example
9898
/// ```no_run
9999
/// # use rustpython::InterpreterConfig;
@@ -114,7 +114,7 @@ impl InterpreterConfig {
114114
}
115115

116116
/// Initialize the Python standard library
117-
///
117+
///
118118
/// This adds all standard library modules to the interpreter.
119119
/// Requires the `stdlib` feature to be enabled at compile time.
120120
#[cfg(feature = "stdlib")]
@@ -123,17 +123,19 @@ impl InterpreterConfig {
123123
}
124124

125125
/// Initialize the Python standard library (no-op without stdlib feature)
126-
///
126+
///
127127
/// When the `stdlib` feature is not enabled, this method does nothing
128128
/// and prints a warning. Enable the `stdlib` feature to use the standard library.
129129
#[cfg(not(feature = "stdlib"))]
130130
pub fn init_stdlib(self) -> Self {
131-
eprintln!("Warning: stdlib feature is not enabled. Standard library will not be available.");
131+
eprintln!(
132+
"Warning: stdlib feature is not enabled. Standard library will not be available."
133+
);
132134
self
133135
}
134136

135137
/// Convenience method to set the debug level
136-
///
138+
///
137139
/// # Example
138140
/// ```no_run
139141
/// # use rustpython::InterpreterConfig;
@@ -147,7 +149,7 @@ impl InterpreterConfig {
147149
}
148150

149151
/// Convenience method to add a single path to the module search paths
150-
///
152+
///
151153
/// # Example
152154
/// ```no_run
153155
/// # use rustpython::InterpreterConfig;
@@ -157,20 +159,23 @@ impl InterpreterConfig {
157159
/// .interpreter();
158160
/// ```
159161
pub fn add_path(mut self, path: impl Into<String>) -> Self {
160-
self.settings.get_or_insert_with(Default::default).path_list.push(path.into());
162+
self.settings
163+
.get_or_insert_with(Default::default)
164+
.path_list
165+
.push(path.into());
161166
self
162167
}
163168

164169
/// Add multiple paths to the module search paths at once
165-
///
170+
///
166171
/// # Example
167172
/// ```no_run
168173
/// # use rustpython::InterpreterConfig;
169174
/// let interpreter = InterpreterConfig::new()
170175
/// .add_paths(vec!["Lib", ".", "custom_modules"])
171176
/// .interpreter();
172177
/// ```
173-
pub fn add_paths<I, S>(mut self, paths: I) -> Self
178+
pub fn add_paths<I, S>(mut self, paths: I) -> Self
174179
where
175180
I: IntoIterator<Item = S>,
176181
S: Into<String>,
@@ -182,7 +187,7 @@ impl InterpreterConfig {
182187
}
183188

184189
/// Initialize the standard library modules
185-
///
190+
///
186191
/// This function sets up both native modules and handles frozen/dynamic stdlib loading
187192
#[cfg(feature = "stdlib")]
188193
pub fn init_stdlib(vm: &mut VirtualMachine) {
@@ -196,13 +201,13 @@ pub fn init_stdlib(vm: &mut VirtualMachine) {
196201
}
197202

198203
/// Setup frozen standard library
199-
///
204+
///
200205
/// Used when the stdlib is compiled into the binary
201206
#[cfg(all(feature = "stdlib", feature = "freeze-stdlib"))]
202207
fn setup_frozen_stdlib(vm: &mut VirtualMachine) {
203208
vm.add_frozen(rustpython_pylib::FROZEN_STDLIB);
204209

205-
// FIXME: Remove this hack once sys._stdlib_dir is properly implemented
210+
// FIXME: Remove this hack once sys._stdlib_dir is properly implemented
206211
// or _frozen_importlib doesn't depend on it anymore.
207212
// The assert ensures _stdlib_dir doesn't already exist before we set it
208213
assert!(vm.sys_module.get_attr("_stdlib_dir", vm).is_err());
@@ -216,7 +221,7 @@ fn setup_frozen_stdlib(vm: &mut VirtualMachine) {
216221
}
217222

218223
/// Setup dynamic standard library loading from filesystem
219-
///
224+
///
220225
/// Used when the stdlib is loaded from disk at runtime
221226
#[cfg(all(feature = "stdlib", not(feature = "freeze-stdlib")))]
222227
fn setup_dynamic_stdlib(vm: &mut VirtualMachine) {
@@ -233,7 +238,7 @@ fn setup_dynamic_stdlib(vm: &mut VirtualMachine) {
233238
}
234239

235240
/// Collect standard library paths from build-time configuration
236-
///
241+
///
237242
/// Checks BUILDTIME_RUSTPYTHONPATH environment variable or uses default pylib path
238243
#[cfg(all(feature = "stdlib", not(feature = "freeze-stdlib")))]
239244
fn collect_stdlib_paths() -> Vec<String> {
@@ -281,9 +286,7 @@ mod tests {
281286

282287
#[test]
283288
fn test_add_multiple_paths_sequential() {
284-
let config = InterpreterConfig::new()
285-
.add_path("path1")
286-
.add_path("path2");
289+
let config = InterpreterConfig::new().add_path("path1").add_path("path2");
287290
let settings = config.settings.unwrap();
288291
assert_eq!(settings.path_list.len(), 2);
289292
}

0 commit comments

Comments
 (0)