Skip to content

Commit 9fc5a1d

Browse files
authored
feat(skore-hub-project): Add Project.delete function (#1775)
Partially addressing #1734 .
1 parent 7e3be81 commit 9fc5a1d

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

skore-hub-project/src/skore_hub_project/project/project.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import TYPE_CHECKING
99

1010
from .. import item as item_module
11-
from ..client.client import AuthenticatedClient
11+
from ..client.client import AuthenticatedClient, HTTPStatusError
1212
from ..item.item import lazy_is_instance
1313

1414
if TYPE_CHECKING:
@@ -207,4 +207,32 @@ def dto(summary):
207207
return self.run_id and SimpleNamespace(get=get, metadata=metadata)
208208

209209
def __repr__(self) -> str: # noqa: D105
210-
return f"Project(hub://{self.tenant}@{self.name})"
210+
return f"Project(mode='hub', name='{self.name}', tenant='{self.tenant}')"
211+
212+
@staticmethod
213+
def delete(tenant: str, name: str):
214+
"""
215+
Delete a hub project.
216+
217+
Parameters
218+
----------
219+
tenant : Path
220+
The tenant of the project.
221+
222+
A tenant is a ``skore hub`` concept that must be configured on the
223+
``skore hub`` interface. It represents an isolated entity managing users,
224+
projects, and resources. It can be a company, organization, or team that
225+
operates independently within the system.
226+
name : str
227+
The name of the project.
228+
"""
229+
with AuthenticatedClient(raises=True) as client:
230+
try:
231+
client.delete(f"projects/{tenant}/{name}")
232+
except HTTPStatusError as e:
233+
if e.response.status_code == 403:
234+
raise PermissionError(
235+
f"Failed to delete the project; "
236+
f"please contact the '{tenant}' owner"
237+
) from e
238+
raise

skore-hub-project/tests/unit/project/test_project.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,16 @@ def test_reports_metadata(self, nowstr, respx_mock):
340340
"predict_time": None,
341341
},
342342
]
343+
344+
def test_delete(self, respx_mock):
345+
respx_mock.delete("projects/<tenant>/<name>").mock(Response(204))
346+
Project.delete("<tenant>", "<name>")
347+
348+
def test_delete_exception(self, respx_mock):
349+
respx_mock.delete("projects/<tenant>/<name>").mock(Response(403))
350+
351+
with raises(
352+
PermissionError,
353+
match="Failed to delete the project; please contact the '<tenant>' owner",
354+
):
355+
Project.delete("<tenant>", "<name>")

0 commit comments

Comments
 (0)