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

change lockfile generation

上级 1f0c51f5
......@@ -150,7 +150,6 @@ def do_add(
save_version_specifiers(requirements, resolved, save)
project.add_dependencies(requirements)
lockfile = project.lockfile
lockfile["root"]["content_hash"] = "md5:" + project.get_content_hash("md5")
project.write_lockfile(lockfile, False)
if sync:
......@@ -237,7 +236,6 @@ def do_update(
save_version_specifiers(updated_deps, resolved, save)
project.add_dependencies(updated_deps)
lockfile = project.lockfile
lockfile["root"]["content_hash"] = "md5:" + project.get_content_hash("md5")
project.write_lockfile(lockfile, False)
......
......@@ -350,8 +350,12 @@ def format_lockfile(mapping, fetched_dependencies, summary_collection):
array.append(inline)
if array:
file_hashes.add(key, array)
data = {"package": packages, "files": file_hashes}
return data
doc = tomlkit.document()
doc.add("package", packages)
metadata = tomlkit.table()
metadata.add("files", file_hashes)
doc.add("metadata", metadata)
return doc
def save_version_specifiers(
......
......@@ -281,25 +281,16 @@ class Project:
return SpinnerReporter(spinner, requirements)
def get_project_metadata(self) -> Dict[str, Any]:
content_hash = self.get_content_hash("sha256")
data = {
"lock_version": self.PYPROJECT_VERSION,
"content_hash": f"sha256:{content_hash}",
}
content_hash = tomlkit.string("sha256:" + self.get_content_hash("sha256"))
content_hash.trivia.trail = "\n\n"
data = {"lock_version": self.PYPROJECT_VERSION, "content_hash": content_hash}
return data
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)
def write_lockfile(self, toml_data: Container, show_message: bool = True) -> None:
toml_data["metadata"].update(self.get_project_metadata())
with atomic_open_for_write(self.lockfile_file) as fp:
fp.write(tomlkit.dumps(doc))
fp.write(tomlkit.dumps(toml_data))
if show_message:
stream.echo(f"Changes are written to {stream.green('pdm.lock')}.")
self._lockfile = None
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册