mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Update find_uv_bin
to locate uv in the base prefix
This commit is contained in:
parent
1dbe750452
commit
db356ab8d4
1 changed files with 22 additions and 9 deletions
|
@ -10,20 +10,21 @@ def find_uv_bin() -> str:
|
|||
|
||||
uv_exe = "uv" + sysconfig.get_config_var("EXE")
|
||||
|
||||
# Search in the scripts directory for the current prefix
|
||||
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"
|
||||
# If in a virtual environment, also search in the base prefix's scripts directory
|
||||
if sys.prefix != sys.base_prefix:
|
||||
path = os.path.join(
|
||||
sysconfig.get_path("scripts", vars={"base": sys.base_prefix}), uv_exe
|
||||
)
|
||||
if os.path.isfile(path):
|
||||
return path
|
||||
|
||||
path = os.path.join(sysconfig.get_path("scripts", scheme=user_scheme), uv_exe)
|
||||
# Search in the user scheme scripts directory, e.g., `~/.local/bin`
|
||||
path = os.path.join(sysconfig.get_path("scripts", scheme=_user_scheme()), uv_exe)
|
||||
if os.path.isfile(path):
|
||||
return path
|
||||
|
||||
|
@ -34,3 +35,15 @@ def find_uv_bin() -> str:
|
|||
return target_path
|
||||
|
||||
raise FileNotFoundError(path)
|
||||
|
||||
|
||||
def _user_scheme() -> str:
|
||||
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"
|
||||
return user_scheme
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue