From 596c60287d3d3ee5b87675247f5ad24401273c67 Mon Sep 17 00:00:00 2001 From: Asherah Connor Date: Sat, 29 Jun 2024 19:20:54 +0300 Subject: [PATCH] project: find root by looking for pyproject.toml. --- src/niar/project.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/niar/project.py b/src/niar/project.py index 03d9324..5b6831f 100644 --- a/src/niar/project.py +++ b/src/niar/project.py @@ -101,8 +101,16 @@ class Project: def __init_subclass__(cls): # We expect to be called from project-root/module/__init.py__ or similar; - # self.origin is project-root. - cls.origin = Path(sys._getframe(1).f_code.co_filename).parent.parent.absolute() + # cls.origin is project-root. Keep going up until we find pyproject.toml. + origin = Path(sys._getframe(1).f_code.co_filename).absolute().parent + while True: + if (origin / "pyproject.toml").is_file(): + cls.origin = origin + break + if not any(origin.parents): + assert False, "could not find pyproject.toml" + origin = origin.parent + extras = cls.__dict__.keys() - {"__module__", "__doc__", "origin"} for prop in cls.PROPS: prop.validate(cls)