Skip to content

Commit

Permalink
#150: Revert substitutions before specific pyproject.toml fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Oct 27, 2023
1 parent e206c5c commit 00b2723
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Unreleased

* Fixed:
* Custom substitutions in pyproject.toml weren't cleaned up correctly.
This was because the plugin would record the "original" content of the file
after the `version` and `enable` fields had already been changed.
Now, substitutions are reverted first before reverting `version` and `enable`.

## v1.1.0 (2023-10-01)

* Added:
Expand Down
16 changes: 10 additions & 6 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,6 @@ def _get_and_apply_version(
def _revert_version(retain: bool = False) -> None:
for project, state in _state.projects.items():
pyproject = tomlkit.parse(state.path.read_text(encoding="utf-8"))
pyproject["tool"]["poetry"]["version"] = state.original_version # type: ignore

if not retain and not _state.cli_mode:
pyproject["tool"]["poetry-dynamic-versioning"]["enable"] = True # type: ignore

state.path.write_bytes(tomlkit.dumps(pyproject).encode("utf-8"))

if state.substitutions:
config = _get_config(pyproject)
Expand All @@ -519,4 +513,14 @@ def _revert_version(retain: bool = False) -> None:

file.write_bytes(content.encode("utf-8"))

# Reread pyproject.toml in case the substitutions affected it.
pyproject = tomlkit.parse(state.path.read_text(encoding="utf-8"))

pyproject["tool"]["poetry"]["version"] = state.original_version # type: ignore

if not retain and not _state.cli_mode:
pyproject["tool"]["poetry-dynamic-versioning"]["enable"] = True # type: ignore

state.path.write_bytes(tomlkit.dumps(pyproject).encode("utf-8"))

_state.projects.clear()

0 comments on commit 00b2723

Please sign in to comment.