2626__all__ = []
2727
2828_RE_VERSION = "{name}==(?P<version>.+)"
29+ _UV_VERSION_MINIMA = "0.4.7" # uv export --output-file
2930logger = logging .getLogger ("sync_uv_pre_commit" )
3031logger .setLevel (logging .INFO )
3132handler = logging .StreamHandler ()
@@ -51,6 +52,7 @@ class ExitCode(IntEnum):
5152 MISSING = 127
5253 PARSING = 1
5354 MISMATCH = 2
55+ VERSION = 3
5456
5557
5658def create_version_pattern (name : str ) -> re .Pattern [str ]:
@@ -207,9 +209,33 @@ def process(
207209 sys .exit (ExitCode .MISMATCH )
208210
209211
212+ def check_uv_version () -> None :
213+ command = ["uv" , "--version" ]
214+ process = subprocess .run (command , check = False , capture_output = True , text = True ) # noqa: S603
215+
216+ try :
217+ process .check_returncode ()
218+ except subprocess .CalledProcessError as exc :
219+ logger .error ("uv version failed: %s" , exc .stderr ) # noqa: TRY400
220+ if exc .returncode == ExitCode .MISSING .value :
221+ sys .exit (ExitCode .MISSING )
222+ if exc .returncode == ExitCode .PARSING .value :
223+ sys .exit (ExitCode .PARSING )
224+ sys .exit (ExitCode .UNKNOWN )
225+
226+ version = process .stdout .strip ().split ()[1 ]
227+ logger .info ("uv version: %s" , version )
228+
229+ if version < _UV_VERSION_MINIMA :
230+ logger .critical ("uv version %s is not supported" , version )
231+ sys .exit (ExitCode .VERSION )
232+
233+
210234def _main () -> None :
211235 from importlib .metadata import version
212236
237+ check_uv_version ()
238+
213239 parser = argparse .ArgumentParser ()
214240 parser .add_argument ("-a" , "--args" , action = "append" , default = [])
215241 parser .add_argument ("-p" , "--pyproject" , type = str , default = "pyproject.toml" )
0 commit comments