polars_core/
config.rs

1use polars_error::{PolarsResult, polars_ensure};
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    polars_config::config().verbose()
34}
35
36/// Prints a log message if sensitive verbose logging has been enabled.
37pub fn verbose_print_sensitive<F: Fn() -> String>(create_log_message: F) {
38    fn do_log(create_log_message: &dyn Fn() -> String) {
39        if polars_config::config().verbose_sensitive() {
40            // Force the message to be a single line.
41            let msg = create_log_message().replace('\n', " ");
42            eprintln!("[SENSITIVE]: {msg}")
43        }
44    }
45
46    do_log(&create_log_message)
47}
48
49pub fn check_allow_importing_interval_as_struct(type_name: &'static str) -> PolarsResult<()> {
50    polars_ensure!(
51        polars_config::config().import_interval_as_struct(),
52        ComputeError:
53        "could not import from `{type_name}` type. \
54        Hint: This can be imported by setting \
55        POLARS_IMPORT_INTERVAL_AS_STRUCT=1 in the environment. \
56        Note however that this is unstable functionality \
57        that may change at any time."
58    );
59    Ok(())
60}