Skip to content

Should uv.find_uv_bin() be able to find /usr/bin/uv? #4451

Closed as not planned
Closed as not planned
@musicinmybrain

Description

@musicinmybrain

I have almost finished preparing a uv package for Fedora. As written, the uv.find_uv_bin() Python function would not be able to find the executable /usr/bin/uv that this package would provide:

  • First it checks
    path = os.path.join(sysconfig.get_path("scripts"), uv_exe)
    which evaluates to /usr/local/bin/uv.
  • Then it checks
    path = os.path.join(sysconfig.get_path("scripts", scheme=user_scheme), uv_exe)
    where user_scheme is "posix_user", which evaluates to '/home/myusername/.local/bin/uv'.
  • Then it checks

    uv/python/uv/__init__.py

    Lines 31 to 32 in 2288ff7

    pkg_root = os.path.dirname(os.path.dirname(__file__))
    target_path = os.path.join(pkg_root, "bin", uv_exe)
    which evaluates to something like /usr/lib/python3.13/bin/uv or /usr/lib64/python3.13/bin/uv. (I currently get the latter, but since the uv Python library is actually arch-independent when it doesn’t bundle the uv executable, I should probably ensure it’s the former.)

I should be able to fix this by something like:

diff --git a/python/uv/__init__.py b/python/uv/__init__.py
index 781eee4f..f2603785 100644
--- a/python/uv/__init__.py
+++ b/python/uv/__init__.py
@@ -10,6 +10,12 @@ def find_uv_bin() -> str:
 
     uv_exe = "uv" + sysconfig.get_config_var("EXE")
 
+    bindir_path = sysconfig.get_config_var("BINDIR")
+    if bindir_path is not None:
+        path = os.path.join(bindir_path, uv_exe)
+        if os.path.isfile(path):
+            return path
+
     path = os.path.join(sysconfig.get_path("scripts"), uv_exe)
     if os.path.isfile(path):
         return path

or, probably better,

diff --git a/python/uv/__init__.py b/python/uv/__init__.py
index 781eee4f..80953b2e 100644
--- a/python/uv/__init__.py
+++ b/python/uv/__init__.py
@@ -1,6 +1,7 @@
 from __future__ import annotations
 
 import os
+import shutil
 import sys
 import sysconfig
 
@@ -10,6 +11,10 @@ def find_uv_bin() -> str:
 
     uv_exe = "uv" + sysconfig.get_config_var("EXE")
 
+    path = shutil.which(uv_exe)
+    if path is not None:
+        return path
+
     path = os.path.join(sysconfig.get_path("scripts"), uv_exe)
     if os.path.isfile(path):
         return path

Is this a change that you think belongs in uv upstream, or is this something I should carry as a downstream patch?

Metadata

Metadata

Assignees

Labels

compatibilityCompatibility with a specification or another tool

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions