Skip to content

Commit 62d04f8

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

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tdp/find_tdp_lib_root_folder.py

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

0 commit comments

Comments
 (0)