Skip to content

Commit c9dda9a

Browse files
authored
DEV: Make make_release.py compatible with Windows environment (#2894)
1 parent c8bfa5f commit c9dda9a

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

make_release.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def get_changelog(changelog_path: str) -> str:
165165
Returns:
166166
Data of the CHANGELOG
167167
"""
168-
with open(changelog_path) as fh:
168+
with open(changelog_path, encoding="utf-8") as fh:
169169
changelog = fh.read()
170170
return changelog
171171

@@ -178,7 +178,7 @@ def write_changelog(new_changelog: str, changelog_path: str) -> None:
178178
new_changelog: Contents of the new CHANGELOG
179179
changelog_path: Path where the CHANGELOG file is
180180
"""
181-
with open(changelog_path, "w") as fh:
181+
with open(changelog_path, "w", encoding="utf-8") as fh:
182182
fh.write(new_changelog)
183183

184184

@@ -253,7 +253,9 @@ def get_formatted_changes(git_tag: str) -> Tuple[str, str]:
253253
for prefix in grouped:
254254
for commit in grouped[prefix]:
255255
output += f"- {prefix}: {commit['msg']}\n"
256-
output_with_user += f"- {prefix}: {commit['msg']} by @{commit['author']}\n"
256+
output_with_user += (
257+
f"- {prefix}: {commit['msg']} by @{commit['author']}\n"
258+
)
257259

258260
return output, output_with_user
259261

@@ -267,7 +269,7 @@ def get_most_recent_git_tag() -> str:
267269
"""
268270
git_tag = str(
269271
subprocess.check_output(
270-
["git", "describe", "--abbrev=0"], stderr=subprocess.STDOUT
272+
["git", "describe", "--tag", "--abbrev=0"], stderr=subprocess.STDOUT
271273
)
272274
).strip("'b\\n")
273275
return git_tag
@@ -309,16 +311,20 @@ def get_git_commits_since_tag(git_tag: str) -> List[Change]:
309311
Returns:
310312
List of all changes since git_tag.
311313
"""
312-
commits = subprocess.check_output(
313-
[
314-
"git",
315-
"--no-pager",
316-
"log",
317-
f"{git_tag}..HEAD",
318-
'--pretty=format:"%H:::%s:::%aN"',
319-
],
320-
stderr=subprocess.STDOUT,
321-
).decode("UTF-8").strip()
314+
commits = (
315+
subprocess.check_output(
316+
[
317+
"git",
318+
"--no-pager",
319+
"log",
320+
f"{git_tag}..HEAD",
321+
'--pretty=format:"%H:::%s:::%aN"',
322+
],
323+
stderr=subprocess.STDOUT,
324+
)
325+
.decode("UTF-8")
326+
.strip()
327+
)
322328
lines = commits.splitlines()
323329
authors = get_author_mapping(len(lines))
324330
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:
337343
Raises:
338344
ValueError: The commit line is not well-structured
339345
"""
340-
parts = line.split(":::")
346+
parts = line.strip().strip('"\\').split(":::")
341347
if len(parts) != 3:
342348
raise ValueError(f"Invalid commit line: '{line}'")
343349
commit_hash, rest, author = parts
@@ -349,10 +355,8 @@ def parse_commit_line(line: str, authors: Dict[str, str]) -> Change:
349355

350356
# Standardize
351357
message.strip()
352-
commit_hash = commit_hash.strip('"')
358+
commit_hash = commit_hash.strip()
353359

354-
if author.endswith('"'):
355-
author = author[:-1]
356360
author_login = authors[commit_hash]
357361

358362
prefix = prefix.strip()

tests/scripts/test_make_release.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
DATA_PATH = Path(__file__).parent.resolve() / "data"
88

9-
9+
# line starting with \ and ending with " have been observed on windows
1010
GIT_LOG__VERSION_4_0_1 = """
1111
b7bfd0d7eddfd0865a94cc9e7027df6596242cf7:::BUG: Use NumberObject for /Border elements of annotations (#2451):::rsinger417
1212
8cacb0fc8fee9920b0515d1289e6ee8191eb3f21:::DOC: Document easier way to update metadata (#2454):::Stefan
1313
3fb63f7e3839ce39ac98978c996f3086ba230a20:::TST: Avoid catching not emitted warnings (#2429):::Stefan
14-
61b73d49778e8f0fb172d5323e67677c9974e420:::DOC: Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426):::CWKSC
14+
\\61b73d49778e8f0fb172d5323e67677c9974e420:::DOC: Typo `Polyline` → `PolyLine` in adding-pdf-annotations.md (#2426):::CWKSC"
1515
f851a532a5ec23b572d86bd7185b327a3fac6b58:::DEV: Bump codecov/codecov-action from 3 to 4 (#2430):::dependabot[bot]""".encode() # noqa: E501
1616

1717
COMMITS__VERSION_4_0_1 = DATA_PATH.joinpath("commits__version_4_0_1.json")
@@ -116,28 +116,31 @@ def test_get_formatted_changes__other():
116116
prefix="",
117117
message="Improve lossless compression example (#2488)",
118118
author="j-t-1",
119-
author_login="j-t-1"
119+
author_login="j-t-1",
120120
),
121121
make_release.Change(
122122
commit_hash="afbee382f8fd2b39588db6470b9b2b2c82905318",
123123
prefix="ENH",
124124
message="Add reattach_fields function (#2480)",
125125
author="pubpub-zz",
126-
author_login="pubpub-zz"
126+
author_login="pubpub-zz",
127127
),
128128
make_release.Change(
129129
commit_hash="cd705f959064d8125397ddf4f7bdd2ea296f889f",
130130
prefix="FIX",
131131
message="Broken test due to expired test file URL (#2468)",
132132
author="pubpub-zz",
133-
author_login="pubpub-zz"
133+
author_login="pubpub-zz",
134134
),
135135
]
136-
with mock.patch.object(make_release, "get_git_commits_since_tag", return_value=changes):
136+
with mock.patch.object(
137+
make_release, "get_git_commits_since_tag", return_value=changes
138+
):
137139
output, output_with_user = make_release.get_formatted_changes("dummy")
138140

139141
assert (
140-
output == """
142+
output
143+
== """
141144
### New Features (ENH)
142145
- Add reattach_fields function (#2480)
143146
@@ -148,7 +151,8 @@ def test_get_formatted_changes__other():
148151
)
149152

150153
assert (
151-
output_with_user == """
154+
output_with_user
155+
== """
152156
### New Features (ENH)
153157
- Add reattach_fields function (#2480) by @pubpub-zz
154158

0 commit comments

Comments
 (0)