Skip to content

Commit

Permalink
Merge pull request #44 from probabl-ai/fix/webapp-resolve-relative-path
Browse files Browse the repository at this point in the history
In webapp, resolve dirpath coming from envvar and set 'InfoMander.path' as the first directory of 'MANDR_ROOT'
  • Loading branch information
thomass-dev authored Jul 16, 2024
2 parents 4183f11 + 921957b commit 438dbe0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/mandr/dashboard/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
@app.get("/api/mandrs")
async def list_mandrs(request: Request) -> list[str]:
"""Send the list of mandrs path below the current working directory."""
path = os.environ["MANDR_PATH"]
root = Path(os.environ["MANDR_ROOT"])
root = Path(os.environ["MANDR_ROOT"]).resolve()
directories = list(root.iterdir())

if len(directories) != 1 or (not directories[0].is_dir()):
raise ValueError("'{root}' is not a valid mandr root")

path = directories[0].stem
ims = [InfoMander(path, root=root)]
paths = []

Expand All @@ -36,7 +41,7 @@ async def list_mandrs(request: Request) -> list[str]:
@app.get("/api/mandrs/{path:path}")
async def get_mandr(request: Request, path: str):
"""Return one mandr."""
root = Path(os.environ["MANDR_ROOT"])
root = Path(os.environ["MANDR_ROOT"]).resolve()

if not (root / path).exists():
raise HTTPException(status_code=404, detail=f"No mandr found in '{path}'")
Expand Down
1 change: 0 additions & 1 deletion tests/integration/dashboard/test_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def test_index(client: TestClient):


def test_list_mandrs(client: TestClient, tmp_path):
os.environ["MANDR_PATH"] = "root"
os.environ["MANDR_ROOT"] = str(tmp_path)

InfoMander("root", root=tmp_path).add_info("key", "value")
Expand Down

0 comments on commit 438dbe0

Please sign in to comment.