Skip to content

Commit

Permalink
feat: calculate project file hash using the tool.pdm.resolution tab…
Browse files Browse the repository at this point in the history
…le (#2956)

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Jun 20, 2024
1 parent 38ccc68 commit af4267b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 2 additions & 0 deletions news/2956.feature.md
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 1 addition & 1 deletion src/pdm/project/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
10 changes: 1 addition & 9 deletions src/pdm/project/project_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import hashlib
import json
import warnings
from typing import Any, Mapping

from tomlkit import TOMLDocument, items
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit af4267b

Please sign in to comment.