Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Remove tempfiles from docs #1193

Merged
merged 14 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions examples/getting_started/plot_skore_getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,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)
sylvaincom marked this conversation as resolved.
Show resolved Hide resolved

# %%
# Now that the project exists, we can write some Python code (in the same
Expand Down Expand Up @@ -347,7 +322,7 @@
# Cleanup the project
# -------------------
#
# Removing the temporary directory:
# Let's clean the skore project to avoid conflict with other examples.
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved

# %%
temp_dir.cleanup()
my_project.clear()
19 changes: 4 additions & 15 deletions examples/getting_started/plot_tracking_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
sylvaincom marked this conversation as resolved.
Show resolved Hide resolved

# %%
# Tracking an integer
Expand Down Expand Up @@ -130,7 +119,7 @@
# Cleanup the project
# -------------------
#
# Removing the temporary directory:
# Let's clean the skore project to avoid conflict with other examples.
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved

# %%
temp_dir.cleanup()
my_project.clear()
19 changes: 4 additions & 15 deletions examples/getting_started/plot_working_with_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
sylvaincom marked this conversation as resolved.
Show resolved Hide resolved

# %%
# Storing integers
Expand Down Expand Up @@ -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()
19 changes: 4 additions & 15 deletions examples/model_evaluation/plot_cross_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
sylvaincom marked this conversation as resolved.
Show resolved Hide resolved

# %%
# Cross-validation in scikit-learn
Expand Down Expand Up @@ -170,7 +159,7 @@
# Cleanup the project
# -------------------
#
# Removing the temporary directory:
# Let's clean the skore project to avoid conflict with other examples.
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved

# %%
temp_dir.cleanup()
my_project.clear()
20 changes: 4 additions & 16 deletions examples/model_evaluation/plot_train_test_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
sylvaincom marked this conversation as resolved.
Show resolved Hide resolved

# %%
# Train-test split in scikit-learn
Expand Down Expand Up @@ -258,7 +246,7 @@
# Cleanup the project
# -------------------
#
# Removing the temporary directory:
# Let's clean the skore project to avoid conflict with other examples.
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved

# %%
temp_dir.cleanup()
my_project.clear()
11 changes: 11 additions & 0 deletions skore/src/skore/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -272,3 +273,13 @@ 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.keys(): # noqa: SIM118
self.view_repository.delete_view(view_key)
# recreate default view
self.view_repository.put_view("default", View(layout=[]))
14 changes: 14 additions & 0 deletions skore/tests/unit/project/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
InvalidProjectNameError,
ProjectCreationError,
)
from skore.persistence.view.view import View
from skore.project.create import _create, _validate_project_name


Expand Down Expand Up @@ -266,6 +267,19 @@ 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("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 = [
(
"a" * 250,
Expand Down
2 changes: 1 addition & 1 deletion sphinx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +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)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1 change: 1 addition & 0 deletions sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def reset_mpl(gallery_conf, fname):
"doc_module": "skore",
"default_thumb_file": "./_static/images/[email protected]",
"reset_modules": (reset_mpl, "seaborn"),
"abort_on_example_error": True,
}

# intersphinx configuration
Expand Down
Loading