5752817494
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary [ruff's `find_bin` implementation](https://github.com/astral-sh/ruff/blob/19cd9d7d8a849cc6e0da65e58fb8c7b6a7a9cb9f/python/ruff/__main__.py#L31) can find the binary in relative to the package root. It'd be nice to have the same functionality for `uv`.
42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
import sysconfig
|
|
|
|
|
|
def find_uv_bin() -> str:
|
|
"""Return the uv binary path."""
|
|
|
|
uv_exe = "uv" + sysconfig.get_config_var("EXE")
|
|
|
|
path = os.path.join(sysconfig.get_path("scripts"), uv_exe)
|
|
if os.path.isfile(path):
|
|
return path
|
|
|
|
if sys.version_info >= (3, 10):
|
|
user_scheme = sysconfig.get_preferred_scheme("user")
|
|
elif os.name == "nt":
|
|
user_scheme = "nt_user"
|
|
elif sys.platform == "darwin" and sys._framework:
|
|
user_scheme = "osx_framework_user"
|
|
else:
|
|
user_scheme = "posix_user"
|
|
|
|
path = os.path.join(sysconfig.get_path("scripts", scheme=user_scheme), uv_exe)
|
|
if os.path.isfile(path):
|
|
return path
|
|
|
|
# Search in `bin` adjacent to package root (as created by `pip install --target`).
|
|
pkg_root = os.path.dirname(os.path.dirname(__file__))
|
|
target_path = os.path.join(pkg_root, "bin", uv_exe)
|
|
if os.path.isfile(target_path):
|
|
return target_path
|
|
|
|
raise FileNotFoundError(path)
|
|
|
|
|
|
__all__ = [
|
|
"find_uv_bin",
|
|
]
|