Skip to content

Instantly share code, notes, and snippets.

@yyolk
Created August 15, 2024 18:00
Show Gist options
  • Save yyolk/c7b133171634987063c3ac345033ecec to your computer and use it in GitHub Desktop.
Save yyolk/c7b133171634987063c3ac345033ecec to your computer and use it in GitHub Desktop.
"""PDM Lock merge strategy driver.
To automatically relock after merging like ``git -X theirs ...``.
Used with an entry in ``pyproject.toml``::
[tool.pdm.scripts]
merge_lockfile = "tasks/merge_lockfile.py"
lockall = "pdm lock -G:all"
and an entry in ``.git/config``::
[merge "pdm-lock-theirs-relock"]
name = A merge driver used to resolve pdm.lock updates from main
driver = pdm run merge_lockfile %O %A %B && pdm run lockall
"""
import sys
from pathlib import Path
ancestors_version, current_version, other_branch_version = sys.argv[1:]
print(f"{ancestors_version=}", f"{current_version=}", f"{other_branch_version=}")
# Write to current version and exit 0 to signal successful merge
with Path.open(other_branch_version) as fp, Path.open(current_version, "w") as wfp:
wfp.write(fp.read())
# We'll exit 0 by default if the above succeeded.
# sys.exit(0)
# Optionally, we could re-lock here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment