jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1150036?usp=email )

Change subject: IMPR: replace codecs.open with Path.write_text in 
generate_family_file
......................................................................

IMPR: replace codecs.open with Path.write_text in generate_family_file

Bug: T395187
Change-Id: Ia9fe72392af5c9055646b7a80fcf5e864efe7b61
---
M pywikibot/scripts/generate_family_file.py
1 file changed, 8 insertions(+), 11 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/scripts/generate_family_file.py 
b/pywikibot/scripts/generate_family_file.py
index 8b03eff..3c97c3d 100755
--- a/pywikibot/scripts/generate_family_file.py
+++ b/pywikibot/scripts/generate_family_file.py
@@ -32,18 +32,17 @@
    If the url scheme is missing, ``https`` will be used.
 """
 #
-# (C) Pywikibot team, 2010-2024
+# (C) Pywikibot team, 2010-2025
 #
 # Distributed under the terms of the MIT license.
 #
 from __future__ import annotations

-import codecs
-import os
 import re
 import string
 import sys
 from contextlib import suppress
+from pathlib import Path
 from urllib.parse import urlparse, urlunparse


@@ -256,12 +255,11 @@

     def writefile(self, verify) -> None:
         """Write the family file."""
-        fn = os.path.join(self.base_dir, 'families',
-                          f'{self.name}_family.py')
-        print(f'Writing {fn}... ')
+        fp = Path(self.base_dir, 'families', f'{self.name}_family.py')
+        print(f'Writing {fp}... ')

-        if os.path.exists(fn) and input(
-                f'{fn} already exists. Overwrite? (y/n) ').lower() == 'n':
+        if fp.exists() and input(
+                f'{fp} already exists. Overwrite? (y/n) ').lower() == 'n':
             print('Terminating.')
             sys.exit(1)

@@ -289,9 +287,8 @@
     def verify_SSL_certificate(self, code: str) -> bool:
         return False
 """
-        os.makedirs(os.path.dirname(fn), exist_ok=True)
-        with codecs.open(fn, 'w', 'utf-8') as fh:
-            fh.write(content)
+        fp.parent.mkdir(parents=True, exist_ok=True)
+        fp.write_text(content, encoding='utf-8')


 family_template = """\

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1150036?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: Ia9fe72392af5c9055646b7a80fcf5e864efe7b61
Gerrit-Change-Number: 1150036
Gerrit-PatchSet: 1
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]

Reply via email to