Skip to content

Commit 0f7f2e8

Browse files
jenkins-botGerrit Code Review
authored andcommitted
Merge "IMPR: use pathlib methods in version script"
2 parents 223abd5 + a1ed47a commit 0f7f2e8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

pywikibot/scripts/version.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
the *-nouser* option.
1313
"""
1414
#
15-
# (C) Pywikibot team, 2007-2024
15+
# (C) Pywikibot team, 2007-2025
1616
#
1717
# Distributed under the terms of the MIT license.
1818
#
1919
from __future__ import annotations
2020

21-
import codecs
2221
import os
2322
import sys
23+
from pathlib import Path
2424

2525
import pywikibot
2626
from pywikibot.version import getversion
@@ -75,17 +75,20 @@ def main(*args: str) -> None:
7575
or not hasattr(requests.certs, 'where')
7676
or not callable(requests.certs.where)):
7777
pywikibot.info(' cacerts: not defined')
78-
elif not os.path.isfile(requests.certs.where()):
79-
pywikibot.info(f' cacerts: {requests.certs.where()} (missing)')
8078
else:
81-
pywikibot.info(' cacerts: ' + requests.certs.where())
82-
83-
with codecs.open(requests.certs.where(), 'r', 'utf-8') as cert_file:
84-
text = cert_file.read()
79+
cert = Path(requests.certs.where())
80+
# is_symlink() required for Python 3.12 and below.
81+
# Otherwise follow_symlinks=True could be used in is_file().
82+
if not cert.is_file() or cert.is_symlink():
83+
pywikibot.info(f' cacerts: {cert.name} (missing)')
84+
else:
85+
pywikibot.info(f' cacerts: {cert}')
86+
text = cert.read_text(encoding='utf-8')
8587
if WMF_CACERT in text:
8688
has_wikimedia_cert = True
87-
pywikibot.info(' certificate test: {}'
88-
.format('ok' if has_wikimedia_cert else 'not ok'))
89+
pywikibot.info(' certificate test: {}'
90+
.format('ok' if has_wikimedia_cert else 'not ok'))
91+
8992
if not has_wikimedia_cert:
9093
pywikibot.info(' Please reinstall requests!')
9194

0 commit comments

Comments
 (0)