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.
(start_path=os.path.abspath(__file__))
| 21 | |
| 22 | |
| 23 | def try_get_arcadia_root(start_path=os.path.abspath(__file__)): |
| 24 | """ |
| 25 | Extended Arcadia root lookup: use various env vars |
| 26 | :param start_path: initial path for lookup |
| 27 | Obtain Arcadia root or **empty string** when arcadia root cannot be found. |
| 28 | """ |
| 29 | env_root = os.getenv("ARCADIA_ROOT") |
| 30 | if env_root: |
| 31 | return env_root |
| 32 | |
| 33 | path = start_path |
| 34 | while path != "/" and not os.path.exists(os.path.join(path, ".arcadia.root")): |
| 35 | path = os.path.dirname(path) |
| 36 | |
| 37 | # if after all, we reached root, try to check up from ya path |
| 38 | # env variable "_" contains path to ya |
| 39 | if path == "/" and start_path == os.path.abspath(__file__): |
| 40 | path = try_get_arcadia_root(os.path.dirname(os.getenv("_"))) |
| 41 | |
| 42 | return path if path != "/" else "" |
| 43 | |
| 44 | |
| 45 | def get_arcadia_root(start_path=os.path.abspath(__file__)): |
no test coverage detected