Sync dependencies
Experiment with setting pyproject versions to latest lock file versions.
Supports both poetry.lock and uv.lock formats.
Functions⚓︎
replace_versions ⚓︎
replace_versions(path_lock)
Read packages from lock file and update the versions in pyproject.toml.
Supports both poetry.lock and uv.lock formats.
| PARAMETER | DESCRIPTION |
|---|---|
path_lock
|
Path to the lock file (poetry.lock or uv.lock)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
if the lock file format is not recognized |
Source code in corallium/sync_dependencies.py
def replace_versions(path_lock: Path) -> None:
"""Read packages from lock file and update the versions in pyproject.toml.
Supports both poetry.lock and uv.lock formats.
Args:
path_lock: Path to the lock file (poetry.lock or uv.lock)
Raises:
NotImplementedError: if the lock file format is not recognized
"""
if path_lock.name not in {'poetry.lock', 'uv.lock'}:
msg = f'Expected a path to a "poetry.lock" or "uv.lock" file. Instead, received: "{path_lock.name}"'
raise NotImplementedError(msg)
lock_versions = _parse_lock_file(path_lock)
path_pyproject = path_lock.parent / 'pyproject.toml'
pyproject_text = path_pyproject.read_text(encoding='utf-8')
pyproject_versions = _collect_pyproject_versions(pyproject_text)
path_pyproject.write_text(_replace_pyproject_versions(lock_versions, pyproject_versions, pyproject_text))