55 removed: list of (name, version) tuples
66 err: error string (empty on success)
77"""
8- import os as _os
9- import sys as _sys
10- _sys .path .insert (0 , _os .path .join (_os .path .dirname (__file__ ), '_native' ))
11- from uv_ffi import run as _run_native
8+ try :
9+ # Prefer the properly installed wheel
10+ from uv_ffi .uv_ffi import (
11+ run as _run_native ,
12+ get_site_packages_cache ,
13+ invalidate_site_packages_cache ,
14+ patch_site_packages_cache ,
15+ clear_registry_cache ,
16+ )
17+ except ImportError :
18+ # Fall back to vendored .so
19+ import os as _os , sys as _sys
20+ _sys .path .insert (0 , _os .path .join (_os .path .dirname (__file__ ), '_native' ))
21+ from uv_ffi import (
22+ run as _run_native ,
23+ get_site_packages_cache ,
24+ invalidate_site_packages_cache ,
25+ patch_site_packages_cache ,
26+ clear_registry_cache ,
27+ )
1228
1329def run (cmd : str ) -> tuple :
1430 """Call uv FFI directly — returns (rc, installed, removed, err).
15- Gracefully handles old 3-tuple .so builds by padding err='' ."""
31+ Gracefully handles old 3-tuple .so builds by padding err=''."""
1632 result = _run_native (cmd )
1733 if len (result ) == 3 :
1834 return (result [0 ], result [1 ], result [2 ], '' )
@@ -26,32 +42,12 @@ def run(cmd: str) -> tuple:
2642except Exception :
2743 __version__ = "unknown"
2844
29- # ── Optional exports: present only if the .so was built with them ────────────
30- # Imported lazily so that an older .so without these functions doesn't cause
31- # an ImportError on the whole module and break FFI availability detection.
32-
33- def _try_import (name : str ):
34- try :
35- import uv_ffi as _m
36- return getattr (_m , name )
37- except (ImportError , AttributeError ):
38- return None
39-
40- _invalidate = _try_import ('invalidate_site_packages_cache' )
41- if _invalidate is not None :
42- invalidate_site_packages_cache = _invalidate
43-
44- _patch = _try_import ('patch_site_packages_cache' )
45- if _patch is not None :
46- patch_site_packages_cache = _patch
47- _gspc = _try_import ('get_site_packages_cache' )
48- if _gspc is not None :
49- get_site_packages_cache = _gspc
50-
51- _clear_reg = _try_import ('clear_registry_cache' )
52- if _clear_reg is not None :
53- clear_registry_cache = _clear_reg
54-
55- _clear_reg = _try_import ('clear_registry_cache' )
56- if _clear_reg is not None :
57- clear_registry_cache = _clear_reg
45+ __all__ = [
46+ "run" ,
47+ "run_capture" ,
48+ "get_site_packages_cache" ,
49+ "invalidate_site_packages_cache" ,
50+ "patch_site_packages_cache" ,
51+ "clear_registry_cache" ,
52+ "__version__" ,
53+ ]
0 commit comments