1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
#[cfg(feature = "flame-it")]
use std::ffi::OsString;
/// Struct containing all kind of settings for the python vm.
#[non_exhaustive]
pub struct Settings {
/// -d command line switch
pub debug: bool,
/// -i
pub inspect: bool,
/// -i, with no script
pub interactive: bool,
/// -O optimization switch counter
pub optimize: u8,
/// Not set SIGINT handler(i.e. for embedded mode)
pub no_sig_int: bool,
/// -s
pub no_user_site: bool,
/// -S
pub no_site: bool,
/// -E
pub ignore_environment: bool,
/// verbosity level (-v switch)
pub verbose: u8,
/// -q
pub quiet: bool,
/// -B
pub dont_write_bytecode: bool,
/// -P
pub safe_path: bool,
/// -b
pub bytes_warning: u64,
/// -Xfoo[=bar]
pub xopts: Vec<(String, Option<String>)>,
/// -X int_max_str_digits
pub int_max_str_digits: i64,
/// -I
pub isolated: bool,
/// -Xdev
pub dev_mode: bool,
/// -X warn_default_encoding, PYTHONWARNDEFAULTENCODING
pub warn_default_encoding: bool,
/// -Wfoo
pub warnopts: Vec<String>,
/// Environment PYTHONPATH and RUSTPYTHONPATH:
pub path_list: Vec<String>,
/// sys.argv
pub argv: Vec<String>,
/// PYTHONHASHSEED=x
pub hash_seed: Option<u32>,
/// -u, PYTHONUNBUFFERED=x
// TODO: use this; can TextIOWrapper even work with a non-buffered?
pub stdio_unbuffered: bool,
/// --check-hash-based-pycs
pub check_hash_based_pycs: String,
/// false for wasm. Not a command-line option
pub allow_external_library: bool,
pub utf8_mode: u8,
#[cfg(feature = "flame-it")]
pub profile_output: Option<OsString>,
#[cfg(feature = "flame-it")]
pub profile_format: Option<String>,
}
impl Settings {
pub fn with_path(mut self, path: String) -> Self {
self.path_list.push(path);
self
}
}
/// Sensible default settings.
impl Default for Settings {
fn default() -> Self {
Settings {
debug: false,
inspect: false,
interactive: false,
optimize: 0,
no_sig_int: false,
no_user_site: false,
no_site: false,
ignore_environment: false,
verbose: 0,
quiet: false,
dont_write_bytecode: false,
safe_path: false,
bytes_warning: 0,
xopts: vec![],
isolated: false,
dev_mode: false,
warn_default_encoding: false,
warnopts: vec![],
path_list: vec![],
argv: vec![],
hash_seed: None,
stdio_unbuffered: false,
check_hash_based_pycs: "default".to_owned(),
allow_external_library: cfg!(feature = "importlib"),
utf8_mode: 1,
int_max_str_digits: -1,
#[cfg(feature = "flame-it")]
profile_output: None,
#[cfg(feature = "flame-it")]
profile_format: None,
}
}
}