Return the ty binary path.
()
| 9 | |
| 10 | |
| 11 | def find_ty_bin() -> str: |
| 12 | """Return the ty binary path.""" |
| 13 | |
| 14 | ty_exe = "ty" + sysconfig.get_config_var("EXE") |
| 15 | |
| 16 | targets = [ |
| 17 | # The scripts directory for the current Python |
| 18 | sysconfig.get_path("scripts"), |
| 19 | # The scripts directory for the base prefix |
| 20 | sysconfig.get_path("scripts", vars={"base": sys.base_prefix}), |
| 21 | # Above the package root, e.g., from `pip install --prefix` or `uv run --with` |
| 22 | ( |
| 23 | # On Windows, with module path `<prefix>/Lib/site-packages/ty` |
| 24 | _join(_matching_parents(_module_path(), "Lib/site-packages/ty"), "Scripts") |
| 25 | if sys.platform == "win32" |
| 26 | # On Unix, with module path `<prefix>/lib/python3.13/site-packages/ty` |
| 27 | else _join( |
| 28 | _matching_parents(_module_path(), "lib/python*/site-packages/ty"), |
| 29 | "bin", |
| 30 | ) |
| 31 | ), |
| 32 | # Adjacent to the package root, e.g., from `pip install --target` |
| 33 | # with module path `<target>/ty` |
| 34 | _join(_matching_parents(_module_path(), "ty"), "bin"), |
| 35 | # The user scheme scripts directory, e.g., `~/.local/bin` |
| 36 | sysconfig.get_path("scripts", scheme=_user_scheme()), |
| 37 | ] |
| 38 | |
| 39 | seen = [] |
| 40 | for target in targets: |
| 41 | if not target: |
| 42 | continue |
| 43 | if target in seen: |
| 44 | continue |
| 45 | seen.append(target) |
| 46 | path = os.path.join(target, ty_exe) |
| 47 | if os.path.isfile(path): |
| 48 | return path |
| 49 | |
| 50 | locations = "\n".join(f" - {target}" for target in seen) |
| 51 | raise TyNotFound( |
| 52 | f"Could not find the ty binary in any of the following locations:\n{locations}\n" |
| 53 | ) |
| 54 | |
| 55 | |
| 56 | def _module_path() -> str | None: |
no test coverage detected
searching dependent graphs…