diff --git a/CHANGELOG.md b/CHANGELOG.md index f6374e4..62843c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## Unreleased + +* Fixed: + * The formatting of `project.dynamic` and `tool.poetry.version` + could be changed when triggering the plugin via `poetry dynamic-versioning` or `pip install` + (but not via `poetry build` or `poetry-dynamic-versioning`). + ## v1.5.1 (2025-01-09) * Fixed: diff --git a/README.md b/README.md index cd84801..29d56b8 100644 --- a/README.md +++ b/README.md @@ -441,3 +441,8 @@ In addition to those: * specify `project.name` * specify `project.dynamic` to contain `"version"` * not specify `project.version` + + Note that, in PEP 621 mode, + the plugin must temporarily remove and then re-add the `tool.poetry.version` key. + This can result in the key shifting to the bottom of its table. + Please put the key at the bottom preemptively to avoid any conflicts. diff --git a/poetry_dynamic_versioning/__init__.py b/poetry_dynamic_versioning/__init__.py index ce7e656..c2d20e4 100644 --- a/poetry_dynamic_versioning/__init__.py +++ b/poetry_dynamic_versioning/__init__.py @@ -635,7 +635,6 @@ def _apply_version( def _get_and_apply_version( - pyproject: Optional[Mapping] = None, pyproject_path: Optional[Path] = None, retain: bool = False, force: bool = False, @@ -646,8 +645,9 @@ def _get_and_apply_version( if pyproject_path is None: raise RuntimeError("Unable to find pyproject.toml") - if pyproject is None: - pyproject = tomlkit.parse(pyproject_path.read_bytes().decode("utf-8")) + # The actual type is `tomlkit.TOMLDocument`, which is important to preserve formatting, + # but it also causes a lot of type-checking noise. + pyproject = tomlkit.parse(pyproject_path.read_bytes().decode("utf-8")) # type: Mapping classic = "tool" in pyproject and "poetry" in pyproject["tool"] and "name" in pyproject["tool"]["poetry"] pep621 = ( diff --git a/poetry_dynamic_versioning/patch.py b/poetry_dynamic_versioning/patch.py index 9ad6c90..bc0876e 100644 --- a/poetry_dynamic_versioning/patch.py +++ b/poetry_dynamic_versioning/patch.py @@ -24,7 +24,6 @@ def alt_poetry_create(cls, *args, **kwargs): if not _state.cli_mode: name = _get_and_apply_version( - pyproject=instance.pyproject.data, pyproject_path=_get_pyproject_path_from_poetry(instance.pyproject), ) if name: diff --git a/poetry_dynamic_versioning/plugin.py b/poetry_dynamic_versioning/plugin.py index 273521b..3001593 100644 --- a/poetry_dynamic_versioning/plugin.py +++ b/poetry_dynamic_versioning/plugin.py @@ -82,7 +82,6 @@ def _apply_version_via_plugin( # fmt: on ) -> None: name = _get_and_apply_version( - pyproject=poetry.pyproject.data, pyproject_path=_get_pyproject_path_from_poetry(poetry.pyproject), retain=retain, force=force,