From 3738d0bd10c2215caeac63d03ac5ae61b980c8d7 Mon Sep 17 00:00:00 2001 From: Marie Date: Tue, 21 Jan 2025 16:46:50 +0100 Subject: [PATCH 01/12] feat(project): add clear function --- skore/src/skore/project/project.py | 8 ++++++++ skore/tests/unit/project/test_project.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/skore/src/skore/project/project.py b/skore/src/skore/project/project.py index c91dce954..0605afe2f 100644 --- a/skore/src/skore/project/project.py +++ b/skore/src/skore/project/project.py @@ -272,3 +272,11 @@ def delete_note(self, key: str, *, version=-1): >>> project.delete_note("key", version=0) # doctest: +SKIP """ return self.item_repository.delete_item_note(key=key, version=version) + + def clear(self): + """Delete all the contents of the project.""" + # delete all the items + for item_key in self.keys(): + self.delete(item_key) + for view_key in self.view_repository: + self.view_repository.delete_view(view_key) diff --git a/skore/tests/unit/project/test_project.py b/skore/tests/unit/project/test_project.py index eacd24d95..445c794f2 100644 --- a/skore/tests/unit/project/test_project.py +++ b/skore/tests/unit/project/test_project.py @@ -266,6 +266,13 @@ def test_put_wrong_key_and_value_raise(in_memory_project): in_memory_project.put(0, (lambda: "unsupported object")) +def test_clear(in_memory_project): + in_memory_project.put("an int", 1) + in_memory_project.put("a str", "some text here to have fun") + in_memory_project.clear() + assert len(in_memory_project.keys()) == 0 + + test_cases = [ ( "a" * 250, From 068ed47a697a0b82fd755c34a4b48a6273729738 Mon Sep 17 00:00:00 2001 From: Marie Date: Tue, 21 Jan 2025 16:57:24 +0100 Subject: [PATCH 02/12] doc(project): use clear instead of tempfile --- .../plot_skore_product_tour.py | 33 +++---------------- .../getting_started/plot_tracking_items.py | 19 +++-------- .../plot_working_with_projects.py | 19 +++-------- .../model_evaluation/plot_cross_validate.py | 19 +++-------- .../model_evaluation/plot_train_test_split.py | 20 +++-------- 5 files changed, 20 insertions(+), 90 deletions(-) diff --git a/examples/getting_started/plot_skore_product_tour.py b/examples/getting_started/plot_skore_product_tour.py index 63ae9c6b5..815dd6e62 100644 --- a/examples/getting_started/plot_skore_product_tour.py +++ b/examples/getting_started/plot_skore_product_tour.py @@ -35,38 +35,13 @@ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # %% -# .. note:: -# -# If we do not wish for our skore project to be stored in a *temporary* folder, we -# can simply create and load the project in the current directory with: -# -# .. code-block:: python -# -# import skore -# -# my_project = skore.open("my_project") -# -# This would create a skore project directory named ``my_project.skore`` in our +# Let's start by creating a skore project directory named ``my_project.skore`` in our # current directory. -# %% -# Here, we start by creating a temporary directory to store our project so that we can -# easily clean it after executing this example: - -# %% -import tempfile -from pathlib import Path - -temp_dir = tempfile.TemporaryDirectory(prefix="skore_example_") -temp_dir_path = Path(temp_dir.name) - -# %% -# Then, we create and load the skore project from this temporary directory: - # %% import skore -my_project = skore.open(temp_dir_path / "my_project") +my_project = skore.open("my_project", create=True) # %% # Now that the project exists, we can write some Python code (in the same @@ -288,7 +263,7 @@ # Cleanup the project # ------------------- # -# Removing the temporary directory: +# Let's clean the skore project to avoid conflict with other examples. # %% -temp_dir.cleanup() +my_project.clear() diff --git a/examples/getting_started/plot_tracking_items.py b/examples/getting_started/plot_tracking_items.py index ec24e45c1..a491dd29a 100644 --- a/examples/getting_started/plot_tracking_items.py +++ b/examples/getting_started/plot_tracking_items.py @@ -14,23 +14,12 @@ # ====================================== # %% -# We start by creating a temporary directory to store our project so that we can -# easily clean it after executing this example: - -# %% -import tempfile -from pathlib import Path - -temp_dir = tempfile.TemporaryDirectory(prefix="skore_example_") -temp_dir_path = Path(temp_dir.name) - -# %% -# We create and load the skore project from this temporary directory: +# We create and load the skore project in the current directory: # %% import skore -my_project = skore.open(temp_dir_path / "my_project") +my_project = skore.open("my_project", create=True) # %% # Tracking an integer @@ -130,7 +119,7 @@ # Cleanup the project # ------------------- # -# Removing the temporary directory: +# Let's clean the skore project to avoid conflict with other examples. # %% -temp_dir.cleanup() +my_project.clear() diff --git a/examples/getting_started/plot_working_with_projects.py b/examples/getting_started/plot_working_with_projects.py index 8863d5429..5492d127b 100644 --- a/examples/getting_started/plot_working_with_projects.py +++ b/examples/getting_started/plot_working_with_projects.py @@ -14,23 +14,12 @@ # ====================================== # %% -# We start by creating a temporary directory to store our project so that we can -# easily clean it after executing this example: - -# %% -import tempfile -from pathlib import Path - -temp_dir = tempfile.TemporaryDirectory(prefix="skore_example_") -temp_dir_path = Path(temp_dir.name) - -# %% -# We create and load the skore project from this temporary directory: +# We create and load the skore project from the current directory: # %% import skore -my_project = skore.open(temp_dir_path / "my_project") +my_project = skore.open("my_project", create=True) # %% # Storing integers @@ -369,7 +358,7 @@ def my_func(x): # Cleanup the project # ------------------- # -# Removing the temporary directory: +# Let's clean the skore project to avoid conflict with other examples. # %% -temp_dir.cleanup() +my_project.clear() diff --git a/examples/model_evaluation/plot_cross_validate.py b/examples/model_evaluation/plot_cross_validate.py index f198e72e9..810b35942 100644 --- a/examples/model_evaluation/plot_cross_validate.py +++ b/examples/model_evaluation/plot_cross_validate.py @@ -19,23 +19,12 @@ # ====================================== # %% -# We start by creating a temporary directory to store our project so that we can -# easily clean it after executing this example: - -# %% -import tempfile -from pathlib import Path - -temp_dir = tempfile.TemporaryDirectory(prefix="skore_example_") -temp_dir_path = Path(temp_dir.name) - -# %% -# We create and load the skore project from this temporary directory: +# We create and load the skore project from the current directory: # %% import skore -my_project = skore.open(temp_dir_path / "my_project") +my_project = skore.open("my_project", create=True) # %% # Cross-validation in scikit-learn @@ -170,7 +159,7 @@ # Cleanup the project # ------------------- # -# Removing the temporary directory: +# Let's clean the skore project to avoid conflict with other examples. # %% -temp_dir.cleanup() +my_project.clear() diff --git a/examples/model_evaluation/plot_train_test_split.py b/examples/model_evaluation/plot_train_test_split.py index 7a973e036..68ff47968 100644 --- a/examples/model_evaluation/plot_train_test_split.py +++ b/examples/model_evaluation/plot_train_test_split.py @@ -12,25 +12,13 @@ # %% # Creating and loading the skore project # ====================================== - -# %% -# We start by creating a temporary directory to store our project so that we can -# easily clean it after executing this example: - -# %% -import tempfile -from pathlib import Path - -temp_dir = tempfile.TemporaryDirectory(prefix="skore_example_") -temp_dir_path = Path(temp_dir.name) - # %% -# We create and load the skore project from this temporary directory: +# We create and load the skore project from the current directory: # %% import skore -my_project = skore.open(temp_dir_path / "my_project") +my_project = skore.open("my_project", create=True) # %% # Train-test split in scikit-learn @@ -258,7 +246,7 @@ # Cleanup the project # ------------------- # -# Removing the temporary directory: +# Let's clean the skore project to avoid conflict with other examples. # %% -temp_dir.cleanup() +my_project.clear() From cef1caa308c9ace8e41b4542cf2eeef95a9e75c6 Mon Sep 17 00:00:00 2001 From: Marie Date: Tue, 21 Jan 2025 18:08:49 +0100 Subject: [PATCH 03/12] chore: complete the tests --- skore/src/skore/project/project.py | 3 +++ skore/tests/unit/project/test_project.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/skore/src/skore/project/project.py b/skore/src/skore/project/project.py index 0605afe2f..3572b9745 100644 --- a/skore/src/skore/project/project.py +++ b/skore/src/skore/project/project.py @@ -7,6 +7,7 @@ from typing import TYPE_CHECKING, Any, Literal, Optional, Union from skore.persistence.item import item_to_object, object_to_item +from skore.persistence.view.view import View if TYPE_CHECKING: from skore.persistence import ( @@ -280,3 +281,5 @@ def clear(self): self.delete(item_key) for view_key in self.view_repository: self.view_repository.delete_view(view_key) + # recreate default view + self.view_repository.put_view("default", View(layout=[])) diff --git a/skore/tests/unit/project/test_project.py b/skore/tests/unit/project/test_project.py index 445c794f2..1c0b8bbb6 100644 --- a/skore/tests/unit/project/test_project.py +++ b/skore/tests/unit/project/test_project.py @@ -15,6 +15,7 @@ InvalidProjectNameError, ProjectCreationError, ) +from skore.persistence.view.view import View from skore.project.create import _create, _validate_project_name @@ -267,10 +268,16 @@ def test_put_wrong_key_and_value_raise(in_memory_project): def test_clear(in_memory_project): - in_memory_project.put("an int", 1) + in_memory_project.put("key1", 1) + in_memory_project.put("key1", 2) in_memory_project.put("a str", "some text here to have fun") + in_memory_project.view_repository.put_view( + "default_test_", View(layout=["key1", "key2"]) + ) in_memory_project.clear() assert len(in_memory_project.keys()) == 0 + assert len(in_memory_project.view_repository.keys()) == 1 + assert in_memory_project.view_repository.keys()[0] == "default" test_cases = [ From 8781e37452aea0e3d748946073847d2a6aff0999 Mon Sep 17 00:00:00 2001 From: Marie Date: Wed, 22 Jan 2025 11:45:16 +0100 Subject: [PATCH 04/12] test iter --- skore/src/skore/project/project.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skore/src/skore/project/project.py b/skore/src/skore/project/project.py index 3572b9745..fe0edcd4c 100644 --- a/skore/src/skore/project/project.py +++ b/skore/src/skore/project/project.py @@ -279,7 +279,7 @@ def clear(self): # delete all the items for item_key in self.keys(): self.delete(item_key) - for view_key in self.view_repository: + for view_key in self.view_repository.keys(): # noqa: SIM118 self.view_repository.delete_view(view_key) - # recreate default view - self.view_repository.put_view("default", View(layout=[])) + # recreate default view + self.view_repository.put_view("default", View(layout=[])) From d683ca76ee421760e0d31aa678b229bd43494406 Mon Sep 17 00:00:00 2001 From: Marie Date: Wed, 22 Jan 2025 13:57:10 +0100 Subject: [PATCH 05/12] docs: enable early abort on example error --- sphinx/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sphinx/Makefile b/sphinx/Makefile index af7ea0f5f..5f3ec5500 100644 --- a/sphinx/Makefile +++ b/sphinx/Makefile @@ -22,3 +22,8 @@ help: # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +html_abort_on_example_error: + $(SPHINXBUILD) -D abort_on_example_error=1 -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." \ No newline at end of file From edf1e576c1f132f3ac37a1faa26d21c7295f4380 Mon Sep 17 00:00:00 2001 From: Marie Date: Wed, 22 Jan 2025 14:02:48 +0100 Subject: [PATCH 06/12] docs: enable early abort on example error --- sphinx/Makefile | 7 +------ sphinx/conf.py | 1 + 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/sphinx/Makefile b/sphinx/Makefile index 5f3ec5500..c4f49cdf1 100644 --- a/sphinx/Makefile +++ b/sphinx/Makefile @@ -21,9 +21,4 @@ help: # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -html_abort_on_example_error: - $(SPHINXBUILD) -D abort_on_example_error=1 -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." \ No newline at end of file + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/sphinx/conf.py b/sphinx/conf.py index 7cf6afebc..a160b3a72 100644 --- a/sphinx/conf.py +++ b/sphinx/conf.py @@ -93,6 +93,7 @@ def reset_mpl(gallery_conf, fname): "doc_module": "skore", "default_thumb_file": "./_static/images/Logo_Skore_Light@2x.svg", "reset_modules": (reset_mpl, "seaborn"), + "abort_on_example_error": True, } # intersphinx configuration From 8089ce2aa886c9814a101f585915a548e4845415 Mon Sep 17 00:00:00 2001 From: Marie Date: Wed, 22 Jan 2025 15:20:20 +0100 Subject: [PATCH 07/12] doc: use clear instead of overwrite in quickstart example --- examples/getting_started/plot_quick_start.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/getting_started/plot_quick_start.py b/examples/getting_started/plot_quick_start.py index 5739bace0..bf917c57f 100644 --- a/examples/getting_started/plot_quick_start.py +++ b/examples/getting_started/plot_quick_start.py @@ -12,7 +12,7 @@ # %% import skore -my_project = skore.open("quick_start", overwrite=True) +my_project = skore.open("my_project", create=True) # %% # This will create a skore project directory named ``quick_start.skore`` in your @@ -69,3 +69,12 @@ # .. admonition:: What's next? # # For a more in-depth guide, see our :ref:`example_skore_getting_started` page! + +# %% +# Cleanup the project +# ------------------- +# +# Let's clean the skore project to avoid conflict with other examples. + +# %% +my_project.clear() From 5f0fd452a82697159f18324633f164cc2f103dd3 Mon Sep 17 00:00:00 2001 From: MarieS-WiMLDS <79304610+MarieS-WiMLDS@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:25:20 +0100 Subject: [PATCH 08/12] Update examples/getting_started/plot_skore_getting_started.py Co-authored-by: Sylvain Combettes <48064216+sylvaincom@users.noreply.github.com> --- examples/getting_started/plot_skore_getting_started.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/getting_started/plot_skore_getting_started.py b/examples/getting_started/plot_skore_getting_started.py index 0560d26eb..16893d8c6 100644 --- a/examples/getting_started/plot_skore_getting_started.py +++ b/examples/getting_started/plot_skore_getting_started.py @@ -322,7 +322,7 @@ # Cleanup the project # ------------------- # -# Let's clean the skore project to avoid conflict with other examples. +# Let's clear the skore project (to avoid conflict with other documentation examples). # %% my_project.clear() From 9320c454acabea3217f23dc1b520abe285b8a980 Mon Sep 17 00:00:00 2001 From: MarieS-WiMLDS <79304610+MarieS-WiMLDS@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:25:29 +0100 Subject: [PATCH 09/12] Update examples/getting_started/plot_quick_start.py Co-authored-by: Sylvain Combettes <48064216+sylvaincom@users.noreply.github.com> --- examples/getting_started/plot_quick_start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/getting_started/plot_quick_start.py b/examples/getting_started/plot_quick_start.py index bf917c57f..ed8456469 100644 --- a/examples/getting_started/plot_quick_start.py +++ b/examples/getting_started/plot_quick_start.py @@ -74,7 +74,7 @@ # Cleanup the project # ------------------- # -# Let's clean the skore project to avoid conflict with other examples. +# Let's clear the skore project (to avoid any conflict with other documentation examples). # %% my_project.clear() From 770cef724a9dbb3dd435db2ddd7ae9c782c05d80 Mon Sep 17 00:00:00 2001 From: MarieS-WiMLDS <79304610+MarieS-WiMLDS@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:29:55 +0100 Subject: [PATCH 10/12] Update examples/getting_started/plot_tracking_items.py Co-authored-by: Sylvain Combettes <48064216+sylvaincom@users.noreply.github.com> --- examples/getting_started/plot_tracking_items.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/getting_started/plot_tracking_items.py b/examples/getting_started/plot_tracking_items.py index a491dd29a..3eb82b0d1 100644 --- a/examples/getting_started/plot_tracking_items.py +++ b/examples/getting_started/plot_tracking_items.py @@ -119,7 +119,7 @@ # Cleanup the project # ------------------- # -# Let's clean the skore project to avoid conflict with other examples. +# Let's clear the skore project (to avoid any conflict with other documentation examples). # %% my_project.clear() From 56f0b79aabed3568e9aadb4cad3783ee0be8d7ff Mon Sep 17 00:00:00 2001 From: MarieS-WiMLDS <79304610+MarieS-WiMLDS@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:30:04 +0100 Subject: [PATCH 11/12] Update examples/model_evaluation/plot_cross_validate.py Co-authored-by: Sylvain Combettes <48064216+sylvaincom@users.noreply.github.com> --- examples/model_evaluation/plot_cross_validate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/model_evaluation/plot_cross_validate.py b/examples/model_evaluation/plot_cross_validate.py index 810b35942..27689b283 100644 --- a/examples/model_evaluation/plot_cross_validate.py +++ b/examples/model_evaluation/plot_cross_validate.py @@ -159,7 +159,7 @@ # Cleanup the project # ------------------- # -# Let's clean the skore project to avoid conflict with other examples. +# Let's clear the skore project (to avoid any conflict with other documentation examples). # %% my_project.clear() From dc28842c6ac7f7f0981f794a0b0266af74f818d4 Mon Sep 17 00:00:00 2001 From: MarieS-WiMLDS <79304610+MarieS-WiMLDS@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:30:14 +0100 Subject: [PATCH 12/12] Update examples/model_evaluation/plot_train_test_split.py Co-authored-by: Sylvain Combettes <48064216+sylvaincom@users.noreply.github.com> --- examples/model_evaluation/plot_train_test_split.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/model_evaluation/plot_train_test_split.py b/examples/model_evaluation/plot_train_test_split.py index 68ff47968..91fc0235d 100644 --- a/examples/model_evaluation/plot_train_test_split.py +++ b/examples/model_evaluation/plot_train_test_split.py @@ -246,7 +246,7 @@ # Cleanup the project # ------------------- # -# Let's clean the skore project to avoid conflict with other examples. +# Let's clear the skore project (to avoid any conflict with other documentation examples). # %% my_project.clear()