From fa9757679403577cc0523c063975d144bcbd1e2a Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 20 Jun 2024 09:55:19 +0800 Subject: [PATCH] feat: calculate project file hash using the `tool.pdm.resolution` table Signed-off-by: Frost Ming --- news/2956.feature.md | 2 ++ src/pdm/project/lockfile.py | 2 +- src/pdm/project/project_file.py | 10 +--------- 3 files changed, 4 insertions(+), 10 deletions(-) create mode 100644 news/2956.feature.md diff --git a/news/2956.feature.md b/news/2956.feature.md new file mode 100644 index 0000000000..cef2f0fc2a --- /dev/null +++ b/news/2956.feature.md @@ -0,0 +1,2 @@ +Use `tool.pdm.resolution` table when calculating the content hash of project file, previously only `overrides` table was used. +This will change the hash already stored in the lockfile, so bump the lockfile version to `4.4.2`. diff --git a/src/pdm/project/lockfile.py b/src/pdm/project/lockfile.py index 79be8e5562..74fde4535a 100644 --- a/src/pdm/project/lockfile.py +++ b/src/pdm/project/lockfile.py @@ -32,7 +32,7 @@ class Compatibility(enum.IntEnum): class Lockfile(TOMLBase): - spec_version = parse_version("4.4.1") + spec_version = parse_version("4.4.2") @cached_property def default_strategies(self) -> set[str]: diff --git a/src/pdm/project/project_file.py b/src/pdm/project/project_file.py index a308675bf9..3b10cd2f6b 100644 --- a/src/pdm/project/project_file.py +++ b/src/pdm/project/project_file.py @@ -2,7 +2,6 @@ import hashlib import json -import warnings from typing import Any, Mapping from tomlkit import TOMLDocument, items @@ -70,13 +69,6 @@ def resolution(self) -> Mapping[str, Any]: @property def allow_prereleases(self) -> bool | None: - if "allow_prereleases" in self.settings: # pragma: no cover - warnings.warn( - "'tool.pdm.allow_prereleases' is deprecated, use 'tool.pdm.resolution.allow-prereleases' instead.", - FutureWarning, - stacklevel=3, - ) - return self.settings["allow_prereleases"] return self.resolution.get("allow-prereleases") def content_hash(self, algo: str = "sha256") -> str: @@ -89,7 +81,7 @@ def content_hash(self, algo: str = "sha256") -> str: "dev-dependencies": self.settings.get("dev-dependencies", {}), "optional-dependencies": self.metadata.get("optional-dependencies", {}), "requires-python": self.metadata.get("requires-python", ""), - "overrides": self.resolution.get("overrides", {}), + "resolution": self.resolution, } pyproject_content = json.dumps(dump_data, sort_keys=True) hasher = hashlib.new(algo)