diff options
author | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/python/find_root/__init__.py |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/python/find_root/__init__.py')
-rw-r--r-- | library/python/find_root/__init__.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/library/python/find_root/__init__.py b/library/python/find_root/__init__.py new file mode 100644 index 00000000000..6da604d62e1 --- /dev/null +++ b/library/python/find_root/__init__.py @@ -0,0 +1,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 |