MCPcopy
hub / github.com/astral-sh/ty / find_ty_bin

Function find_ty_bin

python/ty/_find_ty.py:11–53  ·  view source on GitHub ↗

Return the ty binary path.

()

Source from the content-addressed store, hash-verified

9
10
11def 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
56def _module_path() -> str | None:

Callers 1

_runFunction · 0.90

Calls 5

_joinFunction · 0.85
_matching_parentsFunction · 0.85
_module_pathFunction · 0.85
_user_schemeFunction · 0.85
TyNotFoundClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…