Skip to content

Commit

Permalink
Fix some unconditional references to tool.poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jun 17, 2024
1 parent 296669f commit 978a9a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 11 additions & 5 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,15 @@ def _apply_version(
instance: Version,
config: _Config,
pyproject_path: Path,
mode: _Mode,
retain: bool = False,
) -> None:
pyproject = tomlkit.parse(pyproject_path.read_bytes().decode("utf-8"))

pyproject["tool"]["poetry"]["version"] = version # type: ignore
if mode == _Mode.Classic:
pyproject["tool"]["poetry"]["version"] = version # type: ignore
elif mode == _Mode.Pep621:
pyproject["project"]["version"] = version # type: ignore

# Disable the plugin in case we're building a source distribution,
# which won't have access to the VCS info at install time.
Expand Down Expand Up @@ -694,13 +698,15 @@ def _get_and_apply_version(
os.chdir(str(initial_dir))

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

return name

Expand Down
5 changes: 4 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def test_invalid_config_for_vcs():
def test_keep_pyproject_modifications():
package = "cachy"
# Using --optional to avoid actually installing the package
run(f"poetry add --optional {package}", where=DUMMY)
if "USE_PEP621" in os.environ:
run(f"poetry add --optional main {package}", where=DUMMY)
else:
run(f"poetry add --optional {package}", where=DUMMY)
# Make sure pyproject.toml contains the new package dependency
data = DUMMY_PYPROJECT.read_bytes().decode("utf-8")
assert package in data
Expand Down

0 comments on commit 978a9a1

Please sign in to comment.