diff --git a/skore/src/skore/__init__.py b/skore/src/skore/__init__.py index 14e06e4fc4..f9af5c29f4 100644 --- a/skore/src/skore/__init__.py +++ b/skore/src/skore/__init__.py @@ -37,6 +37,7 @@ from skore._sklearn._plot.inspection.permutation_importance import ( PermutationImportanceDisplay, ) +from skore._utils._environment import is_environment_notebook_like from skore._utils._patch import setup_jupyter_display from skore._utils._show_versions import show_versions @@ -54,20 +55,18 @@ ) +__version__ = version("skore") __all__ = [ "Check", - "CoefficientsDisplay", - "DiagnosticDisplay", "CheckNotApplicable", + "CoefficientsDisplay", "ComparisonReport", - "compare", "ConfusionMatrixDisplay", "CrossValidationReport", + "DiagnosticDisplay", "Display", "EstimatorReport", - "evaluate", "ImpurityDecreaseDisplay", - "TrainTestSplit", "MetricsSummaryDisplay", "PermutationImportanceDisplay", "PrecisionRecallCurveDisplay", @@ -75,7 +74,11 @@ "Project", "RocCurveDisplay", "TableReportDisplay", + "TrainTestSplit", + "compare", "configuration", + "console", + "evaluate", "login", "show_versions", "train_test_split", @@ -87,14 +90,11 @@ logger.setLevel(INFO) -skore_console_theme = Theme( - { - "repr.str": "cyan", - "rule.line": "orange1", - "repr.url": "orange1", - } +console = Console( + width=88, + theme=Theme({"repr.str": "cyan", "rule.line": "orange1", "repr.url": "orange1"}), + # FIXME: + # Force `force_jupyter` on Jupyterlite. + # Waiting for the merge of https://github.com/Textualize/rich/pull/4104. + force_jupyter=(is_environment_notebook_like() or None), ) - - -console = Console(theme=skore_console_theme, width=88) -__version__ = version("skore") diff --git a/skore/src/skore/_utils/_environment.py b/skore/src/skore/_utils/_environment.py index db6b81ce35..905790b550 100644 --- a/skore/src/skore/_utils/_environment.py +++ b/skore/src/skore/_utils/_environment.py @@ -22,16 +22,21 @@ def get_environment_info() -> dict[str, Any]: try: # get_ipython() is defined when running in Jupyter or IPython # there is no need to import IPython here - shell = get_ipython().__class__.__name__ # type: ignore + ipython = get_ipython() # type: ignore[name-defined] + except NameError: + pass + else: + shell = ipython.__class__.__name__ + env_info["details"]["ipython_shell"] = shell - if shell == "ZMQInteractiveShell": # Jupyter notebook/lab + # Jupyter notebook/lab or Jupyterlite + if (shell == "ZMQInteractiveShell") or ("pyodide" in str(ipython.__class__)): env_info["is_jupyter"] = True env_info["environment_name"] = "jupyter" - elif shell == "TerminalInteractiveShell": # IPython terminal + # IPython terminal + elif shell == "TerminalInteractiveShell": env_info["environment_name"] = "ipython_terminal" - except NameError: - pass if "VSCODE_PID" in os.environ: env_info["is_vscode"] = True diff --git a/skore/src/skore/_utils/_progress_bar.py b/skore/src/skore/_utils/_progress_bar.py index 4dfc6bf264..9a1f22b963 100644 --- a/skore/src/skore/_utils/_progress_bar.py +++ b/skore/src/skore/_utils/_progress_bar.py @@ -2,14 +2,7 @@ from operator import length_hint from typing import Any, TypeVar -from rich.progress import ( - BarColumn, - Progress, - SpinnerColumn, - TextColumn, -) - -from skore._config import configuration +from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn T = TypeVar("T") @@ -18,6 +11,9 @@ class ProgressBar: """Simplified progress bar based on ``rich.Progress``.""" def __init__(self, description: str, total: float | None): + from skore import console + from skore._config import configuration + progress = Progress( SpinnerColumn(), TextColumn("[bold cyan]{task.description}"), @@ -27,6 +23,7 @@ def __init__(self, description: str, total: float | None): pulse_style="orange1", ), TextColumn("[orange1]{task.percentage:>3.0f}%"), + console=console, expand=False, transient=True, disable=(not configuration.show_progress),