Skip to content
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
10 changes: 7 additions & 3 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,13 @@ def tweak_patchlevel(
"rc": "PY_RELEASE_LEVEL_GAMMA",
"f": "PY_RELEASE_LEVEL_FINAL",
}[tag.level]
new_constants = template.format(
tag=tag, level_def=level_def, plus=done and "+" or ""
)
if done:
# 3.15+ uses "+dev" for PEP 440 local-version compliance;
# 3.14 and earlier keep the bare "+" suffix.
plus = "+dev" if tag.as_tuple() >= (3, 15) else "+"
else:
plus = ""
new_constants = template.format(tag=tag, level_def=level_def, plus=plus)
if tag.as_tuple() >= (3, 7, 0, "a", 3):
new_constants = new_constants.expandtabs()
constant_replace(filename, new_constants)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,34 @@ def test_tweak_patchlevel(tmp_path: Path) -> None:
assert expected in new_contents


@pytest.mark.parametrize(
["test_tag", "expected_py_version"],
[
# 3.14 and earlier keep the bare "+" suffix.
("3.14.0b2", '#define PY_VERSION "3.14.0b2+"'),
# 3.15+ uses "+dev" for PEP 440 local-version compliance.
("3.15.0b1", '#define PY_VERSION "3.15.0b1+dev"'),
("3.16.0a1", '#define PY_VERSION "3.16.0a1+dev"'),
],
)
def test_tweak_patchlevel_done(
tmp_path: Path, test_tag: str, expected_py_version: str
) -> None:
# Arrange
tag = release.Tag(test_tag)

original_patchlevel_file = Path(__file__).parent / "patchlevel.h"
patchlevel_file = tmp_path / "patchlevel.h"
patchlevel_file.write_text(original_patchlevel_file.read_text())

# Act
release.tweak_patchlevel(tag, filename=str(patchlevel_file), done=True)

# Assert
new_contents = patchlevel_file.read_text()
assert expected_py_version in new_contents


@pytest.mark.parametrize(
[
"test_tag",
Expand Down
Loading