jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1354028?usp=email )
Change subject: tools: Parse separated MediaWiki prerelease versions
......................................................................
tools: Parse separated MediaWiki prerelease versions
Accept optional leading hyphens and period or hyphen separators in beta
and rc suffixes, including the documented 1.35-rc-1 spelling.
Raise ValueError for malformed prerelease suffixes so optimized Python
cannot silently classify them as stable releases. Interpolate the unused
suffix in the debug message and extend the existing parser tests.
Change-Id: Ic6391f80f562454b82360b2fe11a63d5b0050e92
---
M pywikibot/tools/__init__.py
M tests/mediawikiversion_tests.py
2 files changed, 15 insertions(+), 6 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index b898b8d..1cb30d6 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -459,7 +459,8 @@
The version mainly consists of digits separated by periods. After
that is a suffix which may only be 'wmf<number>', 'alpha',
- 'beta<number>' or '-rc.<number>' (the - and . are optional). They
+ 'beta<number>' or 'rc<number>'. Beta and rc suffixes may have a
+ leading hyphen and a period or hyphen before the number. They
are considered from old to new in that order with a version number
without suffix is considered the newest. This secondary difference
is stored in an internal _dev_version attribute.
@@ -478,10 +479,15 @@
.. version-changed:: 6.1
Dependency of distutils was dropped because the package will be
removed with Python 3.12.
+ .. version-changed:: 11.9
+ Beta and rc suffixes accept period and hyphen separators.
+ Malformed prerelease suffixes raise ValueError instead of
+ AssertionError, including when Python optimizations are enabled.
"""
MEDIAWIKI_VERSION = re.compile(
- r'(\d+(?:\.\d+)+)(-?wmf\.?(\d+)|alpha|beta(\d+)|-?rc\.?(\d+)|.*)?')
+ r'(\d+(?:\.\d+)+)(-?wmf\.?(\d+)|alpha|'
+ r'-?beta[.-]?(\d+)|-?rc[.-]?(\d+)|.*)?')
def __init__(self, version_str: str) -> None:
"""Initializer.
@@ -514,11 +520,12 @@
else:
for handled in ('wmf', 'alpha', 'beta', 'rc'):
# if any of those pops up here our parser has failed
- assert handled not in version_match[2], \
- f'Found "{handled}" in "{version_match[2]}"'
+ if handled in version_match[2]:
+ raise ValueError(
+ f'Found "{handled}" in "{version_match[2]}"')
if version_match[2]:
pywikibot.logging.debug(
- 'Additional unused version part {version_match[2]!r}')
+ f'Additional unused version part {version_match[2]!r}')
self._dev_version = (4, )
self.suffix = version_match[2] or ''
diff --git a/tests/mediawikiversion_tests.py b/tests/mediawikiversion_tests.py
index 80c21e9..6bd36f7 100755
--- a/tests/mediawikiversion_tests.py
+++ b/tests/mediawikiversion_tests.py
@@ -76,9 +76,11 @@
self._version_check('1.33alpha', (1, 33), (1, ), 'alpha')
self._version_check('1.27.0-alpha', (1, 27, 0), (1, ), '-alpha')
self._version_check('1.33beta1', (1, 33), (2, 1), 'beta1')
+ self._version_check('1.35-beta.1', (1, 35), (2, 1), '-beta.1')
self._version_check('1.33rc1', (1, 33), (3, 1), 'rc1')
self._version_check('1.33-rc1', (1, 33), (3, 1), '-rc1')
self._version_check('1.33-rc.1', (1, 33), (3, 1), '-rc.1')
+ self._version_check('1.35-rc-1', (1, 35), (3, 1), '-rc-1')
self._version_check('1.33text', (1, 33), (4, ), 'text')
def test_invalid_versions(self) -> None:
@@ -96,7 +98,7 @@
self.INVALID_VERSION_RE):
MediaWikiVersion('1.missing')
with self.assertRaisesRegex(
- AssertionError,
+ ValueError,
'Found "wmf" in "wmf-1"'):
MediaWikiVersion('1.33wmf-1')
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1354028?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: Ic6391f80f562454b82360b2fe11a63d5b0050e92
Gerrit-Change-Number: 1354028
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[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]