"""A module to check the current environment."""importshutilimportsys
[docs]defis_jupyter_notebook()->bool:"""Check if code is run within a jupyter notebook. Returns: True if running inside a Jupyter-like environment (Notebook, JupyterLab, VSCode notebooks, ...?) """return"ipykernel"insys.modules
[docs]defis_google_colab()->bool:"""Check if code is run within google.colab. Returns: True if running inside google.colab) """return"google.colab"insys.modules
[docs]defis_static_width_environment()->bool:"""Check if one can trust dynamic width for tqdm. Returns: True if one can not trust dynamic width for tqdm. Return False if running in a normal terminal. """# return Falsereturnis_jupyter_notebook()oris_google_colab()
[docs]defget_static_terminal_width()->int:"""Get the width of the current terminal. Returns: the width of the current terminal """returnshutil.get_terminal_size()[0]