jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152033?usp=email )
Change subject: IMPR: use pathlib methods in version script
......................................................................
IMPR: use pathlib methods in version script
Bug: T395187
Change-Id: I4392b759d898b20a492ca0bf0e85b1f73db74b81
---
M pywikibot/scripts/version.py
1 file changed, 13 insertions(+), 10 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/scripts/version.py b/pywikibot/scripts/version.py
index 0905135..454f7f0 100755
--- a/pywikibot/scripts/version.py
+++ b/pywikibot/scripts/version.py
@@ -12,15 +12,15 @@
the *-nouser* option.
"""
#
-# (C) Pywikibot team, 2007-2024
+# (C) Pywikibot team, 2007-2025
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations
-import codecs
import os
import sys
+from pathlib import Path
import pywikibot
from pywikibot.version import getversion
@@ -75,17 +75,20 @@
or not hasattr(requests.certs, 'where')
or not callable(requests.certs.where)):
pywikibot.info(' cacerts: not defined')
- elif not os.path.isfile(requests.certs.where()):
- pywikibot.info(f' cacerts: {requests.certs.where()} (missing)')
else:
- pywikibot.info(' cacerts: ' + requests.certs.where())
-
- with codecs.open(requests.certs.where(), 'r', 'utf-8') as cert_file:
- text = cert_file.read()
+ cert = Path(requests.certs.where())
+ # is_symlink() required for Python 3.12 and below.
+ # Otherwise follow_symlinks=True could be used in is_file().
+ if not cert.is_file() or cert.is_symlink():
+ pywikibot.info(f' cacerts: {cert.name} (missing)')
+ else:
+ pywikibot.info(f' cacerts: {cert}')
+ text = cert.read_text(encoding='utf-8')
if WMF_CACERT in text:
has_wikimedia_cert = True
- pywikibot.info(' certificate test: {}'
- .format('ok' if has_wikimedia_cert else 'not ok'))
+ pywikibot.info(' certificate test: {}'
+ .format('ok' if has_wikimedia_cert else 'not ok'))
+
if not has_wikimedia_cert:
pywikibot.info(' Please reinstall requests!')
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152033?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: I4392b759d898b20a492ca0bf0e85b1f73db74b81
Gerrit-Change-Number: 1152033
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]