Fix project lookup on windows.

This commit is contained in:
Sleepy Monax 2023-10-31 14:22:07 +01:00
parent 8a2024bc1c
commit 548a35ffa1

View file

@ -1,13 +1,14 @@
import os
from typing import Optional
from pathlib import Path
def root() -> Optional[str]:
cwd = os.getcwd()
while cwd != "/":
if os.path.isfile(os.path.join(cwd, "project.json")):
return cwd
cwd = os.path.dirname(cwd)
def root() -> str | None:
cwd = Path.cwd()
while cwd != Path.root:
if (cwd / "project.json").is_file():
return str(cwd)
cwd = cwd.parent
return None
@ -15,6 +16,7 @@ def chdir() -> None:
projectRoot = root()
if projectRoot is None:
raise RuntimeError(
"No project.json found in this directory or any parent directory")
"No project.json found in this directory or any parent directory"
)
os.chdir(projectRoot)