Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.

Commit 4225fa8

Browse files
committed
fix: check uv version
1 parent df23da2 commit 4225fa8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/sync_uv_pre_commit/cli.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
__all__ = []
2727

2828
_RE_VERSION = "{name}==(?P<version>.+)"
29+
_UV_VERSION_MINIMA = "0.4.7" # uv export --output-file
2930
logger = logging.getLogger("sync_uv_pre_commit")
3031
logger.setLevel(logging.INFO)
3132
handler = logging.StreamHandler()
@@ -51,6 +52,7 @@ class ExitCode(IntEnum):
5152
MISSING = 127
5253
PARSING = 1
5354
MISMATCH = 2
55+
VERSION = 3
5456

5557

5658
def 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+
210234
def _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

Comments
 (0)