Get tortoise orm config from env or pyproject.toml. :param file: toml file that contains tool.tortoise settings :return: module path and var name that stores the tortoise config
(file: str = "pyproject.toml")
| 27 | |
| 28 | |
| 29 | def tortoise_orm_config(file: str = "pyproject.toml") -> str: |
| 30 | """ |
| 31 | Get tortoise orm config from env or pyproject.toml. |
| 32 | |
| 33 | :param file: toml file that contains tool.tortoise settings |
| 34 | :return: module path and var name that stores the tortoise config |
| 35 | """ |
| 36 | if not (config := os.getenv("TORTOISE_ORM", "")) and (p := Path(file)).exists(): |
| 37 | doc = tomllib.loads(p.read_text("utf-8")) |
| 38 | config = doc.get("tool", {}).get("tortoise", {}).get("tortoise_orm", "") |
| 39 | return config |
| 40 | |
| 41 | |
| 42 | def get_tortoise_config(config: str) -> TortoiseConfig: |