Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually ensure the contents of pyproject.toml do not change after cleanup #207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def _get_and_apply_version(
elif pep621:
name = pyproject["project"]["name"]
original = pyproject["tool"]["poetry"]["version"]
dynamic_array = pyproject["project"]["dynamic"].copy()
dynamic_array = pyproject["project"]["dynamic"]
Copy link
Contributor Author

@edgarrmondragon edgarrmondragon Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out .copy() gets you the underlying list, not an tomlkit.item.Array.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't have guessed either 😅 Thanks for catching that.

else:
return None

Expand Down
4 changes: 3 additions & 1 deletion tests/project-pep621/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[project]
name = "project-pep621"
dynamic = ["version"]
dynamic = [
"version", # a comment that should be preserved
]

[tool.poetry]
# The plugin itself doesn't need this, but Poetry does:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,13 @@ def test_pep621_with_dynamic_version():
def test_pep621_with_dynamic_version_and_cleanup():
version = dunamai.Version.from_git().serialize()

contents_before = DUMMY_PEP621_PYPROJECT.read_bytes().decode("utf-8")

run("poetry build", where=DUMMY_PEP621)
pyproject = tomlkit.parse(DUMMY_PEP621_PYPROJECT.read_bytes().decode("utf-8"))
contents_after = DUMMY_PEP621_PYPROJECT.read_bytes().decode("utf-8")
assert contents_before == contents_after

pyproject = tomlkit.parse(contents_after)
assert "version" not in pyproject["project"]
assert "version" in pyproject["project"]["dynamic"]
assert '__version__ = "0.0.0"' in (DUMMY_PEP621 / "project_pep621" / "__init__.py").read_bytes().decode("utf-8")
Expand Down
Loading