polars_core/
config.rs

1use 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"))]
5pub(crate) const FMT_MAX_COLS: &str = "POLARS_FMT_MAX_COLS";
6pub(crate) const FMT_MAX_ROWS: &str = "POLARS_FMT_MAX_ROWS";
7pub(crate) const FMT_STR_LEN: &str = "POLARS_FMT_STR_LEN";
8#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
9pub(crate) const FMT_TABLE_CELL_ALIGNMENT: &str = "POLARS_FMT_TABLE_CELL_ALIGNMENT";
10#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
11pub(crate) const FMT_TABLE_CELL_NUMERIC_ALIGNMENT: &str = "POLARS_FMT_TABLE_CELL_NUMERIC_ALIGNMENT";
12#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
13pub(crate) const FMT_TABLE_DATAFRAME_SHAPE_BELOW: &str = "POLARS_FMT_TABLE_DATAFRAME_SHAPE_BELOW";
14#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
15pub(crate) const FMT_TABLE_FORMATTING: &str = "POLARS_FMT_TABLE_FORMATTING";
16#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
17pub(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"))]
19pub(crate) const FMT_TABLE_HIDE_COLUMN_NAMES: &str = "POLARS_FMT_TABLE_HIDE_COLUMN_NAMES";
20#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
21pub(crate) const FMT_TABLE_HIDE_COLUMN_SEPARATOR: &str = "POLARS_FMT_TABLE_HIDE_COLUMN_SEPARATOR";
22#[cfg(any(feature = "fmt", feature = "fmt_no_tty"))]
23pub(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"))]
26pub(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"))]
29pub(crate) const FMT_TABLE_ROUNDED_CORNERS: &str = "POLARS_FMT_TABLE_ROUNDED_CORNERS";
30pub(crate) const FMT_TABLE_CELL_LIST_LEN: &str = "POLARS_FMT_TABLE_CELL_LIST_LEN";
31
32pub fn verbose() -> bool {
33    std::env::var("POLARS_VERBOSE").as_deref().unwrap_or("") == "1"
34}
35
36pub 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.
41pub 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")
44            .as_deref()
45            .unwrap_or("")
46            == "1"
47        {
48            // Force the message to be a single line.
49            let msg = create_log_message().replace('\n', "");
50            eprintln!("[SENSITIVE]: {}", msg)
51        }
52    }
53
54    do_log(&create_log_message)
55}
56
57pub fn get_file_prefetch_size() -> usize {
58    std::env::var("POLARS_PREFETCH_SIZE")
59        .map(|s| s.parse::<usize>().expect("integer"))
60        .unwrap_or_else(|_| std::cmp::max(POOL.current_num_threads() * 2, 16))
61}
62
63pub fn get_rg_prefetch_size() -> usize {
64    std::env::var("POLARS_ROW_GROUP_PREFETCH_SIZE")
65        .map(|s| s.parse::<usize>().expect("integer"))
66        // Set it to something big, but not unlimited.
67        .unwrap_or_else(|_| std::cmp::max(get_file_prefetch_size(), 128))
68}
69
70pub fn force_async() -> bool {
71    std::env::var("POLARS_FORCE_ASYNC")
72        .map(|value| value == "1")
73        .unwrap_or_default()
74}