aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/find_root/__init__.py
blob: a53252c6e7d3dba960a60be036eca178d19722d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os 
 
 
def is_root(path): 
    return os.path.exists(os.path.join(path, ".arcadia.root")) or os.path.exists(os.path.join(path, 'devtools', 'ya', 'ya.conf.json'))
 
 
def detect_root(path, detector=is_root): 
    return _find_path(path, detector) 
 
 
def _find_path(starts_from, check): 
    p = os.path.realpath(starts_from) 
    while True: 
        if check(p): 
            return p 
        next_p = os.path.dirname(p) 
        if next_p == p: 
            return None 
        p = next_p