diff --git a/news/3232.bugfix.md b/news/3232.bugfix.md new file mode 100644 index 0000000000..0ad57b1f61 --- /dev/null +++ b/news/3232.bugfix.md @@ -0,0 +1 @@ +Fix a bug that `strategy.inherit_metadata` config is not honored when using `--lockfile` option. diff --git a/src/pdm/project/core.py b/src/pdm/project/core.py index 114bd9b9d7..870d82e4e3 100644 --- a/src/pdm/project/core.py +++ b/src/pdm/project/core.py @@ -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) @cached_property def config(self) -> Mapping[str, Any]: