未验证 提交 1f0c51f5 编写于 作者: F Frost Ming

update lockfile schema

上级 98884349
Update the lock file schema, move the file hashes to `[metadata.files]` table.
......@@ -546,6 +546,10 @@ marker = "python_version < '4.0'"
summary = "Backport of pathlib-compatible object wrapper for zip files"
[metadata]
lock_version = "2"
content_hash = "md5:8e719a97515aca92ae14e3d509118834"
[metadata.files]
"apipkg 1.5" = [
{file = "apipkg-1.5-py2.py3-none-any.whl", hash = "sha256:58587dd4dc3daefad0487f6d9ae32b4542b185e1c36db6993290e7c41ca2b47c"},
{file = "apipkg-1.5.tar.gz", hash = "sha256:37228cda29411948b422fae072f57e31d3396d2ee1c9783775980ee9c9990af6"},
......@@ -958,7 +962,3 @@ summary = "Backport of pathlib-compatible object wrapper for zip files"
{file = "zipp-3.4.0.tar.gz", hash = "sha256:ed5eee1974372595f9e416cc7bbeeb12335201d8081ca8a0743c954d4446e5cb"},
]
[root]
meta_version = "0.0.1"
content_hash = "md5:8e719a97515aca92ae14e3d509118834"
......@@ -323,7 +323,7 @@ def format_lockfile(mapping, fetched_dependencies, summary_collection):
and a collection of package summaries.
"""
packages = tomlkit.aot()
metadata = tomlkit.table()
file_hashes = tomlkit.table()
for k, v in sorted(mapping.items()):
base = tomlkit.table()
base.update(v.as_lockfile_entry())
......@@ -349,10 +349,9 @@ def format_lockfile(mapping, fetched_dependencies, summary_collection):
inline.update({"file": filename, "hash": hash_value})
array.append(inline)
if array:
metadata.add(key, array)
doc = tomlkit.document()
doc.update({"package": packages, "metadata": metadata})
return doc
file_hashes.add(key, array)
data = {"package": packages, "files": file_hashes}
return data
def save_version_specifiers(
......
......@@ -43,7 +43,7 @@ class Project:
PYPROJECT_FILENAME = "pyproject.toml"
PDM_NAMESPACE = "tool.pdm"
DEPENDENCIES_RE = re.compile(r"(?:(.+?)-)?dependencies")
PYPROJECT_VERSION = "0.0.1"
PYPROJECT_VERSION = "2"
GLOBAL_PROJECT = Path.home() / ".pdm" / "global-project"
@classmethod
......@@ -281,18 +281,25 @@ class Project:
return SpinnerReporter(spinner, requirements)
def get_project_metadata(self) -> Dict[str, Any]:
content_hash = self.get_content_hash("md5")
content_hash = self.get_content_hash("sha256")
data = {
"meta_version": self.PYPROJECT_VERSION,
"content_hash": f"md5:{content_hash}",
"lock_version": self.PYPROJECT_VERSION,
"content_hash": f"sha256:{content_hash}",
}
return data
def write_lockfile(self, toml_data: Container, show_message: bool = True) -> None:
toml_data.update({"root": self.get_project_metadata()})
def write_lockfile(
self, toml_data: Dict[str, Container], show_message: bool = True
) -> None:
doc = tomlkit.document()
doc.add("package", toml_data["package"])
metadata = tomlkit.table()
metadata.update(self.get_project_metadata())
metadata.add("files", toml_data["files"])
doc.add("metadata", metadata)
with atomic_open_for_write(self.lockfile_file) as fp:
fp.write(tomlkit.dumps(toml_data))
fp.write(tomlkit.dumps(doc))
if show_message:
stream.echo(f"Changes are written to {stream.green('pdm.lock')}.")
self._lockfile = None
......@@ -323,7 +330,9 @@ class Project:
can.marker = req.marker
can.hashes = {
item["file"]: item["hash"]
for item in self.lockfile["metadata"].get(f"{req.key} {version}", [])
for item in self.lockfile["metadata"]
.get("files", {})
.get(f"{req.key} {version}", [])
} or None
result[req.identify()] = can
if section in ("default", "__all__") and self.meta.name and self.meta.version:
......@@ -347,7 +356,11 @@ class Project:
def is_lockfile_hash_match(self) -> bool:
if not self.lockfile_file.exists():
return False
hash_in_lockfile = str(self.lockfile["root"]["content_hash"])
hash_in_lockfile = str(
self.lockfile.get("metadata", {}).get("content_hash", "")
)
if not hash_in_lockfile:
return False
algo, hash_value = hash_in_lockfile.split(":")
content_hash = self.get_content_hash(algo)
return content_hash == hash_value
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册