Skip to content

Commit

Permalink
DEV: Make make_release.py easier to configure (#2348)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma authored Dec 17, 2023
1 parent 40bc577 commit 50a1cf6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions make_release.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Internal tool to update the changelog."""
"""Internal tool to update the CHANGELOG."""

import json
import subprocess
Expand All @@ -9,6 +9,11 @@

from rich.prompt import Prompt

GH_ORG = "py-pdf"
GH_PROJECT = "pypdf"
VERSION_FILE_PATH = "pypdf/_version.py"
CHANGELOG_FILE_PATH = "CHANGELOG.md"


@dataclass(frozen=True)
class Change:
Expand Down Expand Up @@ -41,7 +46,7 @@ def main(changelog_path: str) -> None:

today = datetime.now(tz=timezone.utc)
header = f"## Version {new_version}, {today:%Y-%m-%d}\n"
url = f"https://github.com/py-pdf/pypdf/compare/{git_tag}...{new_version}"
url = f"https://github.com/{GH_ORG}/{GH_PROJECT}/compare/{git_tag}...{new_version}"
trailer = f"\n[Full Changelog]({url})\n\n"
new_entry = header + changes + trailer
print(new_entry)
Expand All @@ -61,8 +66,8 @@ def main(changelog_path: str) -> None:
def print_instructions(new_version: str) -> None:
"""Print release instructions."""
print("=" * 80)
print(f"☑ _version.py was adjusted to '{new_version}'")
print("☑ CHANGELOG.md was adjusted")
print(f"☑ {VERSION_FILE_PATH} was adjusted to '{new_version}'")
print(f"☑ {CHANGELOG_FILE_PATH} was adjusted")
print("")
print("Now run:")
print(" git commit -eF RELEASE_COMMIT_MSG.md")
Expand All @@ -73,7 +78,7 @@ def print_instructions(new_version: str) -> None:

def adjust_version_py(version: str) -> None:
"""Adjust the __version__ string."""
with open("pypdf/_version.py", "w") as fp:
with open(VERSION_FILE_PATH, "w") as fp:
fp.write(f'__version__ = "{version}"\n')


Expand All @@ -93,8 +98,7 @@ def get_version_interactive(new_version: str, changes: str) -> str:

def is_semantic_version(version: str) -> bool:
"""Check if the given version is a semantic version."""
# It's not so important to cover the edge-cases like pre-releases
# This is meant for pypdf only and we don't make pre-releases
# This doesn't cover the edge-cases like pre-releases
if version.count(".") != 2:
return False
try:
Expand Down Expand Up @@ -284,7 +288,7 @@ def get_author_mapping(line_count: int) -> Dict[str, str]:
mapping: Dict[str, str] = {}
for _ in range(0, line_count, per_page):
with urllib.request.urlopen( # noqa: S310
f"https://api.github.com/repos/py-pdf/pypdf/commits?per_page={per_page}&page={page}"
f"https://api.github.com/repos/{GH_ORG}/{GH_PROJECT}/commits?per_page={per_page}&page={page}"
) as response:
commits = json.loads(response.read())
page += 1
Expand Down Expand Up @@ -366,4 +370,4 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change:


if __name__ == "__main__":
main("CHANGELOG.md")
main(CHANGELOG_FILE_PATH)

0 comments on commit 50a1cf6

Please sign in to comment.