Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: calculate project file hash using the tool.pdm.resolution table #2956

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading