From 5b4e4e695e5b167a180df3b1cbd3a251cd50513e Mon Sep 17 00:00:00 2001 From: Thomas S Date: Tue, 10 Sep 2024 09:51:05 +0200 Subject: [PATCH] mob next [ci-skip] [ci skip] [skip ci] lastFile:src/skore/api/routes/stores.py --- src/skore/api/routes/stores.py | 18 ++++++++++++++++++ src/skore/project.py | 9 ++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/skore/api/routes/stores.py b/src/skore/api/routes/stores.py index 1f41a431a..195745946 100644 --- a/src/skore/api/routes/stores.py +++ b/src/skore/api/routes/stores.py @@ -1,6 +1,7 @@ """The definition of API routes to list stores and get them.""" import os +import josn from pathlib import Path from typing import Any, Iterable @@ -128,3 +129,20 @@ async def put_layout(uri: str, payload: Layout): return serialize_store(store) raise HTTPException(status_code=404, detail=f"No store found in '{uri}'") + + +@SKORES_ROUTER.get("/") +async def get_items(uri: str): + directory = None + project = load(directory) + serialized = {} + + for key in project.list_keys(): + item = project.get_item(key) + serialized[key] = { + "serialized": json.loads(item.serialized), + "raw_class_name": item.raw_class_name, + "media_type": item.media_type, + } + + return serialized diff --git a/src/skore/project.py b/src/skore/project.py index e9f92d572..af2bf9f2a 100644 --- a/src/skore/project.py +++ b/src/skore/project.py @@ -2,6 +2,7 @@ import base64 import json +from pathlib import Path from dataclasses import dataclass from io import StringIO from typing import Any, List @@ -148,6 +149,8 @@ def delete_item(self, key: str): self.storage.delitem(key) -def load(project_name: str) -> Project: - """Load a project from a file.""" - filepath = get_filepath_from_project_name(project_name) +def load(directory: str | Path) -> Project: + storage = FileSystem(directory=directory) + project = Project(storage=storage) + + return project