diff --git a/make_release.py b/make_release.py index f6d16f0a7..7f05cb844 100644 --- a/make_release.py +++ b/make_release.py @@ -165,7 +165,7 @@ def get_changelog(changelog_path: str) -> str: Returns: Data of the CHANGELOG """ - with open(changelog_path) as fh: + with open(changelog_path, encoding="utf-8") as fh: changelog = fh.read() return changelog @@ -178,7 +178,7 @@ def write_changelog(new_changelog: str, changelog_path: str) -> None: new_changelog: Contents of the new CHANGELOG changelog_path: Path where the CHANGELOG file is """ - with open(changelog_path, "w") as fh: + with open(changelog_path, "w", encoding="utf-8") as fh: fh.write(new_changelog) @@ -253,7 +253,9 @@ def get_formatted_changes(git_tag: str) -> Tuple[str, str]: for prefix in grouped: for commit in grouped[prefix]: output += f"- {prefix}: {commit['msg']}\n" - output_with_user += f"- {prefix}: {commit['msg']} by @{commit['author']}\n" + output_with_user += ( + f"- {prefix}: {commit['msg']} by @{commit['author']}\n" + ) return output, output_with_user @@ -267,7 +269,7 @@ def get_most_recent_git_tag() -> str: """ git_tag = str( subprocess.check_output( - ["git", "describe", "--abbrev=0"], stderr=subprocess.STDOUT + ["git", "describe", "--tag", "--abbrev=0"], stderr=subprocess.STDOUT ) ).strip("'b\\n") return git_tag @@ -309,16 +311,20 @@ def get_git_commits_since_tag(git_tag: str) -> List[Change]: Returns: List of all changes since git_tag. """ - commits = subprocess.check_output( - [ - "git", - "--no-pager", - "log", - f"{git_tag}..HEAD", - '--pretty=format:"%H:::%s:::%aN"', - ], - stderr=subprocess.STDOUT, - ).decode("UTF-8").strip() + commits = ( + subprocess.check_output( + [ + "git", + "--no-pager", + "log", + f"{git_tag}..HEAD", + '--pretty=format:"%H:::%s:::%aN"', + ], + stderr=subprocess.STDOUT, + ) + .decode("UTF-8") + .strip() + ) lines = commits.splitlines() authors = get_author_mapping(len(lines)) return [parse_commit_line(line, authors) for line in lines if line != ""] @@ -337,7 +343,7 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change: Raises: ValueError: The commit line is not well-structured """ - parts = line.split(":::") + parts = line.strip().strip('"\\').split(":::") if len(parts) != 3: raise ValueError(f"Invalid commit line: '{line}'") commit_hash, rest, author = parts @@ -349,10 +355,8 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change: # Standardize message.strip() - commit_hash = commit_hash.strip('"') + commit_hash = commit_hash.strip() - if author.endswith('"'): - author = author[:-1] author_login = authors[commit_hash] prefix = prefix.strip() diff --git a/tests/scripts/test_make_release.py b/tests/scripts/test_make_release.py index 869e0aed0..b10424242 100644 --- a/tests/scripts/test_make_release.py +++ b/tests/scripts/test_make_release.py @@ -6,12 +6,12 @@ DATA_PATH = Path(__file__).parent.resolve() / "data" - +# line starting with \ and ending with " have been observed on windows GIT_LOG__VERSION_4_0_1 = """ b7bfd0d7eddfd0865a94cc9e7027df6596242cf7:::BUG: Use NumberObject for /Border elements of annotations (#2451):::rsinger417 8cacb0fc8fee9920b0515d1289e6ee8191eb3f21:::DOC: Document easier way to update metadata (#2454):::Stefan 3fb63f7e3839ce39ac98978c996f3086ba230a20:::TST: Avoid catching not emitted warnings (#2429):::Stefan -61b73d49778e8f0fb172d5323e67677c9974e420:::DOC: Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426):::CWKSC +\\61b73d49778e8f0fb172d5323e67677c9974e420:::DOC: Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426):::CWKSC" f851a532a5ec23b572d86bd7185b327a3fac6b58:::DEV: Bump codecov/codecov-action from 3 to 4 (#2430):::dependabot[bot]""".encode() # noqa: E501 COMMITS__VERSION_4_0_1 = DATA_PATH.joinpath("commits__version_4_0_1.json") @@ -116,28 +116,31 @@ def test_get_formatted_changes__other(): prefix="", message="Improve lossless compression example (#2488)", author="j-t-1", - author_login="j-t-1" + author_login="j-t-1", ), make_release.Change( commit_hash="afbee382f8fd2b39588db6470b9b2b2c82905318", prefix="ENH", message="Add reattach_fields function (#2480)", author="pubpub-zz", - author_login="pubpub-zz" + author_login="pubpub-zz", ), make_release.Change( commit_hash="cd705f959064d8125397ddf4f7bdd2ea296f889f", prefix="FIX", message="Broken test due to expired test file URL (#2468)", author="pubpub-zz", - author_login="pubpub-zz" + author_login="pubpub-zz", ), ] - with mock.patch.object(make_release, "get_git_commits_since_tag", return_value=changes): + with mock.patch.object( + make_release, "get_git_commits_since_tag", return_value=changes + ): output, output_with_user = make_release.get_formatted_changes("dummy") assert ( - output == """ + output + == """ ### New Features (ENH) - Add reattach_fields function (#2480) @@ -148,7 +151,8 @@ def test_get_formatted_changes__other(): ) assert ( - output_with_user == """ + output_with_user + == """ ### New Features (ENH) - Add reattach_fields function (#2480) by @pubpub-zz