Skip to content

Commit

Permalink
GET /mandrs/{path}
Browse files Browse the repository at this point in the history
  • Loading branch information
rouk1 committed Jul 10, 2024
1 parent 11afa4d commit 205bb4e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/mandr/dashboard/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from pathlib import Path

from fastapi import FastAPI, Request
from fastapi import FastAPI, HTTPException, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates

Expand Down Expand Up @@ -41,7 +41,10 @@ async def list_mandrs(request: Request) -> list[str]:
return [f"{p}" for p in InfoManderRepository.get_all_paths()]


@app.get("/mandrs/{path:path}")
async def get_mandr(request: Request):
@app.get("/mandrs/{mander_path:path}")
async def get_mandr(request: Request, mander_path: str):
"""Return on mandr."""
return ""
mander = InfoManderRepository.get(path=mander_path)
if mander is None:
raise HTTPException(status_code=404, detail=f"No mandr found in {mander_path}")
return {"path": mander.project_path}
22 changes: 22 additions & 0 deletions src/mandr/infomander.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,25 @@ def get_all_paths(cls) -> list[Path]:

# return as relative to `root_path` Path objects
return sorted([Path(p).relative_to(storage_path) for p in matching_paths])

@classmethod
def get(cls, path: str) -> InfoMander | None:
"""Get an `InfoMander` by it's path."""
mander_path = _get_storage_path() / path
sub_folder_names = [
f"{p.relative_to(mander_path)}" for p in mander_path.iterdir()
]
does_path_contain_mander_folder = any(
[
STATS_FOLDER in sub_folder_names,
ARTIFACTS_FOLDER in sub_folder_names,
LOGS_FOLDER in sub_folder_names,
]
)
if (
not mander_path.exists()
or not mander_path.is_dir()
or not does_path_contain_mander_folder
):
return None
return InfoMander(path)
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ def test_get_mandrs(client: TestClient):
mander_paths = response.json()
assert len(mander_paths) == number_of_manders
assert response.status_code == 200


def test_get_mandr(client: TestClient):
mander_path = "probabl-ai/test-mandr/42"
mander = InfoMander(mander_path)
mander.add_info("hey", "ho let's go")

response = client.get(f"/mandrs/{mander_path}")
mander_json = response.json()
assert mander_path in mander_json.get("path")
assert response.status_code == 200

0 comments on commit 205bb4e

Please sign in to comment.