Skip to content

Commit c1cbffc

Browse files
committed
update_bugs_by_version: Use pathlib
1 parent abe869a commit c1cbffc

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

scripts/update_bugs_by_version.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
# This makes it possible to use this script as part of CI to check
77
# that the list is up to date.
88

9-
import os
109
import json
1110
import re
1211
import sys
12+
from pathlib import Path
1313

1414
def comp(version_string):
1515
return [int(c) for c in version_string.split('.')]
1616

17-
path = os.path.dirname(os.path.realpath(__file__))
18-
with open(path + '/../docs/bugs.json', encoding='utf8') as bugsFile:
19-
bugs = json.load(bugsFile)
17+
root_path = Path(__file__).resolve().parent.parent
18+
19+
bugs = json.loads((root_path / 'docs/bugs.json').read_text(encoding='utf8'))
2020

2121
versions = {}
22-
with open(path + '/../Changelog.md', encoding='utf8') as changelog:
22+
with (root_path / 'Changelog.md').open(encoding='utf8') as changelog:
2323
for line in changelog:
2424
m = re.search(r'^### (\S+) \((\d+-\d+-\d+)\)$', line)
2525
if m:
@@ -36,8 +36,6 @@ def comp(version_string):
3636
value['bugs'] += [bug['name']]
3737

3838
new_contents = json.dumps(versions, sort_keys=True, indent=4, separators=(',', ': '))
39-
with open(path + '/../docs/bugs_by_version.json', 'r', encoding='utf8') as bugs_by_version:
40-
old_contents = bugs_by_version.read()
41-
with open(path + '/../docs/bugs_by_version.json', 'w', encoding='utf8') as bugs_by_version:
42-
bugs_by_version.write(new_contents)
39+
old_contents = (root_path / 'docs/bugs_by_version.json').read_text(encoding='utf8')
40+
(root_path / 'docs/bugs_by_version.json').write_text(new_contents, encoding='utf8')
4341
sys.exit(old_contents != new_contents)

0 commit comments

Comments
 (0)