获取项目根目录 Returns: 项目根目录 Path 对象
()
| 381 | |
| 382 | |
| 383 | def get_project_root() -> Path: |
| 384 | """ |
| 385 | 获取项目根目录 |
| 386 | |
| 387 | Returns: |
| 388 | 项目根目录 Path 对象 |
| 389 | """ |
| 390 | # 当前文件所在目录 |
| 391 | current_dir = Path(__file__).parent |
| 392 | |
| 393 | # 向上查找直到找到项目根目录(包含 pyproject.toml 或 setup.py) |
| 394 | for parent in [current_dir] + list(current_dir.parents): |
| 395 | if (parent / "pyproject.toml").exists() or (parent / "setup.py").exists(): |
| 396 | return parent |
| 397 | |
| 398 | # 如果找不到,返回当前目录的父目录 |
| 399 | return current_dir.parent |
| 400 | |
| 401 | |
| 402 | def get_data_dir() -> Path: |
nothing calls this directly
no outgoing calls
no test coverage detected