Skip to content

Commit 1013b3c

Browse files
committed
update python hooks to include uv sync
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent 6f547fe commit 1013b3c

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

.hooks/sync_version.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
INIT_FILE = pathlib.Path("socketsecurity/__init__.py")
1010
PYPROJECT_FILE = pathlib.Path("pyproject.toml")
11+
UV_LOCK_FILE = pathlib.Path("uv.lock")
1112

1213
VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]")
1314
PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*".*"$', re.MULTILINE)
@@ -72,6 +73,21 @@ def inject_version(version: str):
7273
new_pyproject = re.sub(r"(\[project\])", rf"\1\nversion = \"{version}\"", pyproject)
7374
PYPROJECT_FILE.write_text(new_pyproject)
7475

76+
77+
def run_uv_lock() -> bool:
78+
before = UV_LOCK_FILE.read_bytes() if UV_LOCK_FILE.exists() else b""
79+
try:
80+
subprocess.run(["uv", "lock"], check=True, text=True)
81+
except FileNotFoundError:
82+
print("❌ `uv` is required but was not found in PATH.")
83+
sys.exit(1)
84+
except subprocess.CalledProcessError:
85+
print("❌ `uv lock` failed. Please run it manually and fix any errors.")
86+
sys.exit(1)
87+
88+
after = UV_LOCK_FILE.read_bytes() if UV_LOCK_FILE.exists() else b""
89+
return before != after
90+
7591
def main():
7692
dev_mode = "--dev" in sys.argv
7793
current_version = read_version_from_init(INIT_FILE)
@@ -84,15 +100,24 @@ def main():
84100
base_version = current_version.split(".dev")[0] if ".dev" in current_version else current_version
85101
new_version = find_next_available_dev_version(base_version)
86102
inject_version(new_version)
87-
print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.")
103+
uv_lock_changed = run_uv_lock()
104+
lock_hint = " and uv.lock" if uv_lock_changed else ""
105+
print(f"⚠️ Version was unchanged — auto-bumped. Please git add{lock_hint} + commit again.")
88106
sys.exit(0)
89107
else:
90108
new_version = bump_patch_version(current_version)
91109
inject_version(new_version)
92-
print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.")
110+
uv_lock_changed = run_uv_lock()
111+
lock_hint = " and uv.lock" if uv_lock_changed else ""
112+
print(f"⚠️ Version was unchanged — auto-bumped. Please git add{lock_hint} + commit again.")
93113
sys.exit(1)
94114
else:
95-
print("✅ Version already bumped — proceeding.")
115+
uv_lock_changed = run_uv_lock()
116+
if uv_lock_changed:
117+
print("⚠️ Version already bumped, but uv.lock was out of date and has been updated. Please git add uv.lock + commit again.")
118+
sys.exit(1)
119+
120+
print("✅ Version already bumped and uv.lock is up to date — proceeding.")
96121
sys.exit(0)
97122

98123
if __name__ == "__main__":

0 commit comments

Comments
 (0)