Skip to content

Commit

Permalink
Merge pull request #206 from edgarrmondragon/restore-full-dynamic-array
Browse files Browse the repository at this point in the history
Restore `dynamic` array for PEP 621
  • Loading branch information
mtkennerly authored Jan 9, 2025
2 parents 47d6f20 + b755853 commit 544408b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import jinja2
import tomlkit
import tomlkit.items
from dunamai import (
bump_version,
check_version,
Expand Down Expand Up @@ -131,14 +132,14 @@ def __init__(
original_version: Optional[str],
version: str,
mode: _Mode,
dynamic_index: Optional[int],
dynamic_array: Optional[tomlkit.items.Array],
substitutions: Optional[MutableMapping[Path, str]] = None,
) -> None:
self.path = path
self.original_version = original_version
self.version = version
self.mode = mode
self.dynamic_index = dynamic_index
self.dynamic_array = dynamic_array
self.substitutions = {} if substitutions is None else substitutions # type: MutableMapping[Path, str]


Expand Down Expand Up @@ -663,11 +664,11 @@ def _get_and_apply_version(
if classic:
name = pyproject["tool"]["poetry"]["name"]
original = pyproject["tool"]["poetry"]["version"]
dynamic_index = None
dynamic_array = None
elif pep621:
name = pyproject["project"]["name"]
original = pyproject["tool"]["poetry"]["version"]
dynamic_index = pyproject["project"]["dynamic"].index("version")
dynamic_array = pyproject["project"]["dynamic"].copy()
else:
return None

Expand All @@ -688,12 +689,12 @@ def _get_and_apply_version(

if classic and name is not None and original is not None:
mode = _Mode.Classic
_state.projects[name] = _ProjectState(pyproject_path, original, version, mode, dynamic_index)
_state.projects[name] = _ProjectState(pyproject_path, original, version, mode, dynamic_array)
if io:
_apply_version(name, version, instance, config, pyproject_path, mode, retain)
elif pep621 and name is not None:
mode = _Mode.Pep621
_state.projects[name] = _ProjectState(pyproject_path, original, version, mode, dynamic_index)
_state.projects[name] = _ProjectState(pyproject_path, original, version, mode, dynamic_array)
if io:
_apply_version(name, version, instance, config, pyproject_path, mode, retain)

Expand Down Expand Up @@ -725,9 +726,8 @@ def _revert_version(retain: bool = False) -> None:
if state.original_version is not None:
pyproject["tool"]["poetry"]["version"] = state.original_version # type: ignore
elif state.mode == _Mode.Pep621:
if state.dynamic_index is not None:
index = state.dynamic_index
pyproject["project"]["dynamic"].insert(index, "version") # type: ignore
if state.dynamic_array is not None:
pyproject["project"]["dynamic"] = state.dynamic_array
if "version" in pyproject["project"]: # type: ignore
pyproject["project"].pop("version") # type: ignore
if state.original_version is not None:
Expand Down

0 comments on commit 544408b

Please sign in to comment.