def load_lockfile(project: Project, path: str | Path) -> Lockfile:
    """Load a lockfile from the given path."""

    default_lockfile = PyLock if project.config["lock.format"] == "pylock" else PDMLock

    try:
        with open(path, "rb") as f:
            data = tomllib.load(f)
    except OSError:
        return default_lockfile(path, ui=project.core.ui)
    else:
        if data.get("metadata", {}).get("lock_version"):
            return PDMLock(path, ui=project.core.ui)
        elif data.get("lock-version"):
            return PyLock(path, ui=project.core.ui)
        else:  # pragma: no cover
            return default_lockfile(path, ui=project.core.ui)
Load a lockfile from the given path.
src/pdm/project/lockfile/__init__.py