Skip to content

Commit

Permalink
fix: inherit_metadata would be written in lock file if the file is no…
Browse files Browse the repository at this point in the history
…t pdm.lock even strategy config is true

Fixes #3232

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Oct 31, 2024
1 parent 4401ff5 commit 4937eaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/3232.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that `strategy.inherit_metadata` config is not honored when using `--lockfile` option.
11 changes: 6 additions & 5 deletions src/pdm/project/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,16 @@ def pyproject(self) -> PyProject:
@property
def lockfile(self) -> Lockfile:
if self._lockfile is None:
self._lockfile = Lockfile(self.root / self.LOCKFILE_FILENAME, ui=self.core.ui)
if self.config.get("use_uv"):
self._lockfile.default_strategies.discard(FLAG_INHERIT_METADATA)
if not self.config["strategy.inherit_metadata"]:
self._lockfile.default_strategies.discard(FLAG_INHERIT_METADATA)
self.set_lockfile(self.root / self.LOCKFILE_FILENAME)
assert self._lockfile is not None
return self._lockfile

def set_lockfile(self, path: str | Path) -> None:
self._lockfile = Lockfile(path, ui=self.core.ui)
if self.config.get("use_uv"):
self._lockfile.default_strategies.discard(FLAG_INHERIT_METADATA)
if not self.config["strategy.inherit_metadata"]:
self._lockfile.default_strategies.discard(FLAG_INHERIT_METADATA)

Check warning on line 214 in src/pdm/project/core.py

View check run for this annotation

Codecov / codecov/patch

src/pdm/project/core.py#L214

Added line #L214 was not covered by tests

@cached_property
def config(self) -> Mapping[str, Any]:
Expand Down

0 comments on commit 4937eaf

Please sign in to comment.