Set current working directory (cwd) to default project root in PyPI mode

This commit is contained in:
shenchucheng 2023-12-17 00:23:21 +08:00
parent 68f3865893
commit 355ee8faa8

View file

@ -23,6 +23,12 @@ OPTIONS = contextvars.ContextVar("OPTIONS", default={})
def get_metagpt_package_root():
"""Get the root directory of the installed package."""
package_root = Path(metagpt.__file__).parent.parent
for i in (".git", ".project_root", ".gitignore"):
if (package_root / i).exists():
break
else:
package_root = Path.cwd()
logger.info(f"Package root set to {str(package_root)}")
return package_root