aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/find_root/__init__.py
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/python/find_root/__init__.py
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/python/find_root/__init__.py')
-rw-r--r--library/python/find_root/__init__.py20
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 0000000000..6da604d62e
--- /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