diff options
author | robot-piglet <[email protected]> | 2025-09-01 18:37:05 +0300 |
---|---|---|
committer | robot-piglet <[email protected]> | 2025-09-01 19:06:57 +0300 |
commit | 6f768e78a7bbc89778e9b2764e7f85bdeb64f034 (patch) | |
tree | b7d88b0f418957da9eee57a85c81edefe83990f2 /library/python | |
parent | a8b4824e60974c2562979da8a101385095519b1d (diff) |
Intermediate changes
commit_hash:1623077a586fe91fb5d853b4efee5d1e623189cb
Diffstat (limited to 'library/python')
-rw-r--r-- | library/python/find_root/README.md | 9 | ||||
-rw-r--r-- | library/python/find_root/__init__.py | 33 | ||||
-rw-r--r-- | library/python/find_root/ya.make | 4 |
3 files changed, 45 insertions, 1 deletions
diff --git a/library/python/find_root/README.md b/library/python/find_root/README.md new file mode 100644 index 00000000000..9a370d2f2ff --- /dev/null +++ b/library/python/find_root/README.md @@ -0,0 +1,9 @@ +# find_root + +A simple library for Arcadia root detection. + +Простая библиотека для обнаружения корня Аркадии. + +Имеется два варианта детектора: +- каноническая версия `detect_root` (смотрит только на файловую систему) +- расширенная `get_arcadia_root` + `try_get_arcadia_root` (смотрит на переменные окружения) diff --git a/library/python/find_root/__init__.py b/library/python/find_root/__init__.py index 6da604d62e1..5cf6625ad95 100644 --- a/library/python/find_root/__init__.py +++ b/library/python/find_root/__init__.py @@ -18,3 +18,36 @@ def _find_path(starts_from, check): if next_p == p: return None p = next_p + + +def try_get_arcadia_root(start_path=os.path.abspath(__file__)): + """ + Extended Arcadia root lookup: use various env vars + :param start_path: initial path for lookup + Obtain Arcadia root or **empty string** when arcadia root cannot be found. + """ + env_root = os.getenv("ARCADIA_ROOT") + if env_root: + return env_root + + path = start_path + while path != "/" and not os.path.exists(os.path.join(path, ".arcadia.root")): + path = os.path.dirname(path) + + # if after all, we reached root, try to check up from ya path + # env variable "_" contains path to ya + if path == "/" and start_path == os.path.abspath(__file__): + path = try_get_arcadia_root(os.path.dirname(os.getenv("_"))) + + return path if path != "/" else "" + + +def get_arcadia_root(start_path=os.path.abspath(__file__)): + """ + :param start_path: initial path for lookup + Obtain Arcadia root or raise exception when root cannot be found. + """ + arcadia_root = try_get_arcadia_root(start_path=start_path) + if not arcadia_root: + raise Exception("Cannot find Arcadia root") + return arcadia_root diff --git a/library/python/find_root/ya.make b/library/python/find_root/ya.make index 35821361805..235c6295674 100644 --- a/library/python/find_root/ya.make +++ b/library/python/find_root/ya.make @@ -1,5 +1,7 @@ PY23_LIBRARY() -PY_SRCS(__init__.py) +ALL_PY_SRCS() + +STYLE_RUFF() END() |