Skip to content

Commit

Permalink
#203: Prevent formatting change in some commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jan 10, 2025
1 parent bbeebe9 commit 4d26f8b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 3 additions & 3 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = (
Expand Down
1 change: 0 additions & 1 deletion poetry_dynamic_versioning/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion poetry_dynamic_versioning/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4d26f8b

Please sign in to comment.