Skip to content

Commit

Permalink
store package files on the package in lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Sep 5, 2022
1 parent aa591ec commit 3a62a13
Show file tree
Hide file tree
Showing 36 changed files with 446 additions and 158 deletions.
22 changes: 16 additions & 6 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ def locked_repository(self) -> Repository:
if source_type in ["directory", "file"]:
url = self._lock.path.parent.joinpath(url).resolve().as_posix()

name = info["name"]
package = Package(
info["name"],
name,
info["version"],
info["version"],
source_type=source_type,
Expand All @@ -123,9 +124,19 @@ def locked_repository(self) -> Repository:
package.category = info.get("category", "main")
package.optional = info["optional"]
metadata = cast("dict[str, Any]", lock_data["metadata"])
name = info["name"]
if "hashes" in metadata:
# Old lock so we create dummy files from the hashes

# Storing of package files and hashes has been through a few generations in
# the lockfile, we can read them all:
#
# - latest and preferred is that this is read per package, from
# package.files
# - oldest is that hashes were stored in metadata.hashes without filenames
# - in between those two, hashes were stored alongside filenames in
# metadata.files
package_files = info.get("files")
if package_files is not None:
package.files = package_files
elif "hashes" in metadata:
hashes = cast("dict[str, Any]", metadata["hashes"])
package.files = [{"name": h, "hash": h} for h in hashes[name]]
elif source_type in {"git", "directory", "url"}:
Expand Down Expand Up @@ -226,8 +237,6 @@ def set_lock_data(self, root: Package, packages: list[Package]) -> bool:
assert isinstance(package_files, Array)
files[package["name"]] = package_files.multiline(True)

del package["files"]

lock = document()
lock["package"] = package_specs

Expand All @@ -241,6 +250,7 @@ def set_lock_data(self, root: Package, packages: list[Package]) -> bool:
"lock-version": self._VERSION,
"python-versions": root.python_versions,
"content-hash": self._content_hash,
# TODO stop writing files here, this is deprecated.
"files": files,
}

Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/old_lock/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

152 changes: 0 additions & 152 deletions tests/fixtures/old_lock/updated.lock

This file was deleted.

112 changes: 112 additions & 0 deletions tests/fixtures/outdated_lock/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3a62a13

Please sign in to comment.