jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152435?usp=email )
Change subject: IMPR: replace codecs.open() with pathlib methods in
make_i18n_dict.py
......................................................................
IMPR: replace codecs.open() with pathlib methods in make_i18n_dict.py
Bug: T395187
Change-Id: I2c583e915faf87f4f6e2d58adc95012a055916f0
---
M scripts/maintenance/make_i18n_dict.py
1 file changed, 17 insertions(+), 19 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/maintenance/make_i18n_dict.py
b/scripts/maintenance/make_i18n_dict.py
index d55c3cf..8cc41ad 100755
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -30,16 +30,15 @@
>>> bot.to_json()
"""
#
-# (C) Pywikibot team, 2013-2024
+# (C) Pywikibot team, 2013-2025
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations
-import codecs
import json
-import os
from importlib import import_module
+from pathlib import Path
from pywikibot import config
@@ -132,24 +131,23 @@
if not self.dict:
self.run(quiet)
- json_dir = os.path.join(
- config.base_dir, 'scripts/i18n', self.scriptname)
- if not os.path.exists(json_dir):
- os.makedirs(json_dir)
+ json_dir = Path(config.base_dir, 'scripts/i18n', self.scriptname)
+ json_dir.mkdir(exist_ok=True)
+
for lang in self.dict:
- file_name = os.path.join(json_dir, f'{lang}.json')
- if os.path.isfile(file_name):
- with codecs.open(file_name, 'r', 'utf-8') as json_file:
- new_dict = json.load(json_file)
- else:
- new_dict = {}
+ new_dict = {}
+
+ file_path = json_dir / f'{lang}.json'
+ if file_path.is_file():
+ new_dict = json.load(file_path.read_text(encoding='utf-8'))
+
new_dict['@metadata'] = new_dict.get('@metadata', {'authors': []})
- with codecs.open(file_name, 'w', 'utf-8') as json_file:
- new_dict.update(self.dict[lang])
- s = json.dumps(new_dict, ensure_ascii=False, sort_keys=True,
- indent=indent, separators=(',', ': '))
- s = s.replace(' ' * indent, '\t')
- json_file.write(s)
+ new_dict.update(self.dict[lang])
+ s = json.dumps(new_dict, ensure_ascii=False, sort_keys=True,
+ indent=indent, separators=(',', ': '))
+ s = s.replace(' ' * indent, '\t')
+
+ file_path.write_text(s, encoding='utf-8')
if __name__ == '__main__':
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152435?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2c583e915faf87f4f6e2d58adc95012a055916f0
Gerrit-Change-Number: 1152435
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]