Skip to content

Commit 274ffde

Browse files
committed
feat: add function which finds tdp-lib root folder
1 parent 1767a10 commit 274ffde

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tdp/find_tdp_lib_root_folder.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pathlib import Path
2+
from typing import Optional
3+
4+
5+
def find_tdp_lib_root_folder(current_path: Optional[Path] = None):
6+
# If current_path is not provided, start from the directory of this file
7+
if current_path is None:
8+
current_path = Path(__file__).parent
9+
10+
while True:
11+
# Check if 'pyproject.toml' exists in the current directory
12+
if (current_path / "pyproject.toml").exists():
13+
return current_path.resolve()
14+
15+
parent_path = current_path.parent
16+
# If the parent path is the same as the current path, we have reached the root directory
17+
if parent_path == current_path:
18+
return None
19+
20+
current_path = parent_path
21+
22+
23+
if __name__ == "__main__":
24+
print(find_tdp_lib_root_folder())

0 commit comments

Comments
 (0)