1#[cfg(feature = "flame-it")]
2use std::ffi::OsString;
3
4#[derive(Debug, Clone, Default)]
6pub struct Paths {
7 pub executable: String,
9 pub base_executable: String,
11 pub prefix: String,
13 pub base_prefix: String,
15 pub exec_prefix: String,
17 pub base_exec_prefix: String,
19 pub stdlib_dir: Option<String>,
21 pub module_search_paths: Vec<String>,
23}
24
25pub struct PyConfig {
29 pub settings: Settings,
30 pub paths: Paths,
31}
32
33impl PyConfig {
34 pub fn new(settings: Settings, paths: Paths) -> Self {
35 Self { settings, paths }
36 }
37}
38
39#[non_exhaustive]
41pub struct Settings {
42 pub isolated: bool,
44
45 pub dev_mode: bool,
48
49 pub install_signal_handlers: bool,
51
52 pub hash_seed: Option<u32>,
55
56 pub faulthandler: bool,
58
59 pub code_debug_ranges: bool,
64 pub argv: Vec<String>,
75
76 pub xoptions: Vec<(String, Option<String>)>,
79
80 pub warnoptions: Vec<String>,
83
84 pub import_site: bool,
86
87 pub bytes_warning: u64,
89
90 pub warn_default_encoding: bool,
92
93 pub thread_inherit_context: bool,
95
96 pub context_aware_warnings: bool,
98
99 pub inspect: bool,
101
102 pub interactive: bool,
104
105 pub write_bytecode: bool,
109
110 pub verbose: u8,
112
113 pub quiet: bool,
115
116 pub user_site_directory: bool,
118
119 pub buffered_stdio: bool,
122
123 pub stdio_encoding: Option<String>,
125 pub stdio_errors: Option<String>,
127 pub utf8_mode: i8,
128 pub check_hash_pycs_mode: CheckHashPycsMode,
130
131 pub safe_path: bool,
134
135 pub int_max_str_digits: i64,
137
138 pub path_list: Vec<String>,
143
144 pub debug: u8,
148
149 pub optimize: u8,
151
152 pub ignore_environment: bool,
154
155 pub allow_external_library: bool,
157
158 #[cfg(feature = "flame-it")]
159 pub profile_output: Option<OsString>,
160 #[cfg(feature = "flame-it")]
161 pub profile_format: Option<String>,
162}
163
164#[derive(Debug, Default, Copy, Clone, strum_macros::Display, strum_macros::EnumString)]
165#[strum(serialize_all = "lowercase")]
166pub enum CheckHashPycsMode {
167 #[default]
168 Default,
169 Always,
170 Never,
171}
172
173impl Settings {
174 pub fn with_path(mut self, path: String) -> Self {
175 self.path_list.push(path);
176 self
177 }
178}
179
180impl Default for Settings {
182 fn default() -> Self {
183 Self {
184 debug: 0,
185 inspect: false,
186 interactive: false,
187 optimize: 0,
188 install_signal_handlers: true,
189 user_site_directory: true,
190 import_site: true,
191 ignore_environment: false,
192 verbose: 0,
193 quiet: false,
194 write_bytecode: true,
195 safe_path: false,
196 bytes_warning: 0,
197 xoptions: vec![],
198 isolated: false,
199 dev_mode: false,
200 warn_default_encoding: false,
201 thread_inherit_context: false,
202 context_aware_warnings: false,
203 warnoptions: vec![],
204 path_list: vec![],
205 argv: vec![],
206 hash_seed: None,
207 faulthandler: false,
208 code_debug_ranges: true,
209 buffered_stdio: true,
210 check_hash_pycs_mode: CheckHashPycsMode::Default,
211 allow_external_library: cfg!(feature = "importlib"),
212 stdio_encoding: None,
213 stdio_errors: None,
214 utf8_mode: -1,
215 int_max_str_digits: 4300,
216 #[cfg(feature = "flame-it")]
217 profile_output: None,
218 #[cfg(feature = "flame-it")]
219 profile_format: None,
220 }
221 }
222}