mongo/buildscripts/poetry_lock_check.py
Andrew Bradshaw f4644578e0 SERVER-120217 Update to using rules python (#48943)
GitOrigin-RevId: 4684e8f134d1fff534747129566fed89a4f96528
2026-03-06 01:52:51 +00:00

36 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""
Check to make sure poetry.lock is synced with pyproject.toml.
Returns nonzero if poetry.lock and pyproject.toml are not synced
"""
import os
import runpy
import sys
POETRY_LOCK_V200 = (
"""# This file is automatically @generated by Poetry 2.0.0 and should not be changed by hand."""
)
REPO_ROOT = os.environ.get("BUILD_WORKSPACE_DIRECTORY", ".")
old_argv = sys.argv
old_cwd = os.getcwd()
try:
sys.argv = ["poetry", "check", "--lock"]
os.chdir(REPO_ROOT)
runpy.run_module("poetry", run_name="__main__")
except SystemExit as e:
if e.code not in (None, 0):
raise
finally:
sys.argv = old_argv
os.chdir(old_cwd)
# Check if the poetry lock file was generated with poetry 2.0.0
with open(f"{REPO_ROOT}/poetry.lock", "r") as poetry_lock:
if POETRY_LOCK_V200 not in poetry_lock.read(len(POETRY_LOCK_V200)):
raise Exception("""Poetry lockfile was not generated by poetry 2.0.0.
Make sure to have poetry 2.0.0 installed when running poetry lock.
If you are seeing this message please follow the poetry install steps in docs/building.md.""")