-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.py
More file actions
40 lines (32 loc) · 1.31 KB
/
header.py
File metadata and controls
40 lines (32 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## \file header.py
# -*- coding: utf-8 -*-
#! venv/bin/python/python3.12
"""
.. module:: header
:platform: Windows, Unix
:synopsis: Модуль определяющий корневой путь к проекту. Все импорты строятся относительно этого пути.
"""
import sys
from pathlib import Path
def set_project_root(marker_files=('__root__','.git')) -> Path:
"""
Finds the root directory of the project starting from the current file's directory,
searching upwards and stopping at the first directory containing any of the marker files.
Args:
marker_files (tuple): Filenames or directory names to identify the project root.
Returns:
Path: Path to the root directory if found, otherwise the directory where the script is located.
"""
__root__:Path
current_path:Path = Path(__file__).resolve().parent
__root__ = current_path
for parent in [current_path] + list(current_path.parents):
if any((parent / marker).exists() for marker in marker_files):
__root__ = parent
break
if __root__ not in sys.path:
sys.path.insert(0, str(__root__))
return __root__
# Get the root directory of the project
__root__ = set_project_root()
"""__root__ (Path): Path to the root directory of the project"""