cutekit/cutekit/project.py

17 lines
No EOL
417 B
Python

import os
def root() -> str | None:
cwd = os.getcwd()
while cwd != "/":
if os.path.isfile(os.path.join(cwd, "project.json")):
return cwd
cwd = os.path.dirname(cwd)
return None
def chdir() -> None:
projectRoot = root()
if projectRoot is None:
raise RuntimeError("No project.json found in this directory or any parent directory")
os.chdir(projectRoot)