Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-core/src/config.rs
6939 views
1
use crate::POOL;
2
3
// Formatting environment variables (typically referenced/set from the python-side Config object)
4
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
5
pub(crate) const FMT_MAX_COLS: &str = "POLARS_FMT_MAX_COLS";
6
pub(crate) const FMT_MAX_ROWS: &str = "POLARS_FMT_MAX_ROWS";
7
pub(crate) const FMT_STR_LEN: &str = "POLARS_FMT_STR_LEN";
8
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
9
pub(crate) const FMT_TABLE_CELL_ALIGNMENT: &str = "POLARS_FMT_TABLE_CELL_ALIGNMENT";
10
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
11
pub(crate) const FMT_TABLE_CELL_NUMERIC_ALIGNMENT: &str = "POLARS_FMT_TABLE_CELL_NUMERIC_ALIGNMENT";
12
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
13
pub(crate) const FMT_TABLE_DATAFRAME_SHAPE_BELOW: &str = "POLARS_FMT_TABLE_DATAFRAME_SHAPE_BELOW";
14
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
15
pub(crate) const FMT_TABLE_FORMATTING: &str = "POLARS_FMT_TABLE_FORMATTING";
16
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
17
pub(crate) const FMT_TABLE_HIDE_COLUMN_DATA_TYPES: &str = "POLARS_FMT_TABLE_HIDE_COLUMN_DATA_TYPES";
18
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
19
pub(crate) const FMT_TABLE_HIDE_COLUMN_NAMES: &str = "POLARS_FMT_TABLE_HIDE_COLUMN_NAMES";
20
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
21
pub(crate) const FMT_TABLE_HIDE_COLUMN_SEPARATOR: &str = "POLARS_FMT_TABLE_HIDE_COLUMN_SEPARATOR";
22
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
23
pub(crate) const FMT_TABLE_HIDE_DATAFRAME_SHAPE_INFORMATION: &str =
24
"POLARS_FMT_TABLE_HIDE_DATAFRAME_SHAPE_INFORMATION";
25
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
26
pub(crate) const FMT_TABLE_INLINE_COLUMN_DATA_TYPE: &str =
27
"POLARS_FMT_TABLE_INLINE_COLUMN_DATA_TYPE";
28
#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
29
pub(crate) const FMT_TABLE_ROUNDED_CORNERS: &str = "POLARS_FMT_TABLE_ROUNDED_CORNERS";
30
pub(crate) const FMT_TABLE_CELL_LIST_LEN: &str = "POLARS_FMT_TABLE_CELL_LIST_LEN";
31
32
pub fn verbose() -> bool {
33
std::env::var("POLARS_VERBOSE").as_deref().unwrap_or("") == "1"
34
}
35
36
pub fn get_engine_affinity() -> String {
37
std::env::var("POLARS_ENGINE_AFFINITY").unwrap_or_else(|_| "auto".to_string())
38
}
39
40
/// Prints a log message if sensitive verbose logging has been enabled.
41
pub fn verbose_print_sensitive<F: Fn() -> String>(create_log_message: F) {
42
fn do_log(create_log_message: &dyn Fn() -> String) {
43
if std::env::var("POLARS_VERBOSE_SENSITIVE").as_deref() == Ok("1") {
44
// Force the message to be a single line.
45
let msg = create_log_message().replace('\n', " ");
46
eprintln!("[SENSITIVE]: {msg}")
47
}
48
}
49
50
do_log(&create_log_message)
51
}
52
53
pub fn get_file_prefetch_size() -> usize {
54
std::env::var("POLARS_PREFETCH_SIZE")
55
.map(|s| s.parse::<usize>().expect("integer"))
56
.unwrap_or_else(|_| std::cmp::max(POOL.current_num_threads() * 2, 16))
57
}
58
59
pub fn get_rg_prefetch_size() -> usize {
60
std::env::var("POLARS_ROW_GROUP_PREFETCH_SIZE")
61
.map(|s| s.parse::<usize>().expect("integer"))
62
// Set it to something big, but not unlimited.
63
.unwrap_or_else(|_| std::cmp::max(get_file_prefetch_size(), 128))
64
}
65
66
pub fn force_async() -> bool {
67
std::env::var("POLARS_FORCE_ASYNC")
68
.map(|value| value == "1")
69
.unwrap_or_default()
70
}
71
72