1use core::num::NonZeroI32;
2#[cfg(feature = "flame-it")]
3use std::ffi::OsString;
4
5#[derive(Debug, Clone, Default)]
7pub struct Paths {
8 pub executable: String,
10 pub base_executable: String,
12 pub prefix: String,
14 pub base_prefix: String,
16 pub exec_prefix: String,
18 pub base_exec_prefix: String,
20 pub stdlib_dir: Option<String>,
22 pub module_search_paths: Vec<String>,
24}
25
26#[derive(Clone)]
30pub struct PyConfig {
31 pub settings: Settings,
32 pub paths: Paths,
33}
34
35impl PyConfig {
36 #[must_use]
37 pub fn new(settings: Settings, paths: Paths) -> Self {
38 Self { settings, paths }
39 }
40}
41
42#[non_exhaustive]
44#[derive(Clone)]
45pub struct Settings {
46 pub isolated: bool,
48
49 pub dev_mode: bool,
52
53 pub install_signal_handlers: bool,
55
56 pub hash_seed: Option<u32>,
59
60 pub faulthandler: bool,
62
63 pub code_debug_ranges: bool,
68 pub argv: Vec<String>,
79
80 pub xoptions: Vec<(String, Option<String>)>,
83
84 pub warnoptions: Vec<String>,
87
88 pub import_site: bool,
90
91 pub bytes_warning: u64,
93
94 pub warn_default_encoding: bool,
96
97 pub thread_inherit_context: bool,
99
100 pub context_aware_warnings: bool,
102
103 pub inspect: bool,
105
106 pub interactive: bool,
108
109 pub write_bytecode: bool,
113
114 pub verbose: u8,
116
117 pub quiet: bool,
119
120 pub user_site_directory: bool,
122
123 pub buffered_stdio: bool,
126
127 pub stdio_encoding: Option<String>,
129 pub stdio_errors: Option<String>,
131 pub utf8_mode: i8,
132 pub check_hash_pycs_mode: CheckHashPycsMode,
134
135 pub safe_path: bool,
138
139 pub int_max_str_digits: i64,
141
142 pub cpu_count: Option<NonZeroI32>,
144
145 pub path_list: Vec<String>,
150
151 pub debug: u8,
155
156 pub optimize: u8,
158
159 pub ignore_environment: bool,
161
162 pub allow_external_library: bool,
164
165 #[cfg(feature = "flame-it")]
166 pub profile_output: Option<OsString>,
167 #[cfg(feature = "flame-it")]
168 pub profile_format: Option<String>,
169}
170
171#[derive(Debug, Default, Copy, Clone, strum_macros::Display, strum_macros::EnumString)]
172#[strum(serialize_all = "lowercase")]
173pub enum CheckHashPycsMode {
174 #[default]
175 Default,
176 Always,
177 Never,
178}
179
180impl Settings {
181 #[must_use]
182 pub fn with_path(mut self, path: String) -> Self {
183 self.path_list.push(path);
184 self
185 }
186}
187
188impl Default for Settings {
190 fn default() -> Self {
191 Self {
192 debug: 0,
193 inspect: false,
194 interactive: false,
195 optimize: 0,
196 install_signal_handlers: true,
197 user_site_directory: true,
198 import_site: true,
199 ignore_environment: false,
200 verbose: 0,
201 quiet: false,
202 write_bytecode: true,
203 safe_path: false,
204 bytes_warning: 0,
205 xoptions: vec![],
206 isolated: false,
207 dev_mode: false,
208 warn_default_encoding: false,
209 thread_inherit_context: false,
210 context_aware_warnings: false,
211 warnoptions: vec![],
212 path_list: vec![],
213 argv: vec![],
214 hash_seed: None,
215 faulthandler: false,
216 code_debug_ranges: true,
217 buffered_stdio: true,
218 check_hash_pycs_mode: CheckHashPycsMode::Default,
219 allow_external_library: cfg!(feature = "importlib"),
220 stdio_encoding: None,
221 stdio_errors: None,
222 utf8_mode: -1,
223 int_max_str_digits: 4300,
224 cpu_count: None,
225 #[cfg(feature = "flame-it")]
226 profile_output: None,
227 #[cfg(feature = "flame-it")]
228 profile_format: None,
229 }
230 }
231}