jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1335950?usp=email )
Change subject: setup: Compare release tags by version
......................................................................
setup: Compare release tags by version
Select the maximum PEP 440-compatible tag when validating an sdist.
Git's default tag order is lexicographic, which can leave an older 9.x tag
after 10.x and 11.x releases. Ignore non-version tags during comparison.
Change-Id: I1293d244dbcce4189924afff5970ad74ffaee8ca
---
M setup.py
M tests/setup_tests.py
2 files changed, 31 insertions(+), 9 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/setup.py b/setup.py
index 66ffcbe..c79f45d 100755
--- a/setup.py
+++ b/setup.py
@@ -148,13 +148,11 @@
print(e)
sys.exit('Creating source distribution canceled.')
- last_tag = None
- if tags:
- for tag in ('stable', 'python2'):
- with suppress(ValueError):
- tags.remove(tag)
-
- last_tag = tags[-1]
+ versions = []
+ for tag in tags:
+ with suppress(InvalidVersion):
+ versions.append(Version(tag))
+ last_version = max(versions, default=None)
warning = ''
try:
@@ -162,10 +160,10 @@
except InvalidVersion:
warning = f'{version} is not a valid version string following PEP 440.'
else:
- if last_tag and vrsn <= Version(last_tag):
+ if last_version and vrsn <= last_version:
warning = (
f'New version {version!r} is not higher than last version '
- f'{last_tag!r}.'
+ f'{str(last_version)!r}.'
)
if warning:
diff --git a/tests/setup_tests.py b/tests/setup_tests.py
index 21f8a31..7f62ef5 100755
--- a/tests/setup_tests.py
+++ b/tests/setup_tests.py
@@ -7,7 +7,11 @@
"""Test setup.py."""
from __future__ import annotations
+import sys
import unittest
+from unittest.mock import patch
+
+from packaging.version import Version
import pywikibot
import setup
@@ -30,6 +34,26 @@
self.assertEqual(setup.get_validated_version('pywikibot'),
pywikibot.__version__)
+ @patch('subprocess.run')
+ def test_get_validated_version_uses_latest_tag(self, mock_run) -> None:
+ """Test that version validation uses the latest repository tag."""
+ version = Version(pywikibot.__version__)
+ newer_version = f'{version.major + 1}.0.0'
+ older_version = f'{max(version.major - 1, 0)}.0.0'
+ mock_run.return_value.stdout = (
+ f'not-a-version\n{newer_version}\n{older_version}\n'
+ )
+
+ with patch.object(sys, 'argv', ['setup.py', 'sdist']):
+ with patch('builtins.print') as mock_print:
+ with self.assertRaises(SystemExit):
+ setup.get_validated_version('pywikibot')
+
+ mock_print.assert_any_call(
+ f'\n\nNew version {str(version)!r} is not higher than last '
+ f'version {newer_version!r}.'
+ )
+
def test_read_desc(self) -> None:
"""Test :func:`setup.read_desc` function."""
desc = setup.read_desc('README.rst')
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1335950?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: I1293d244dbcce4189924afff5970ad74ffaee8ca
Gerrit-Change-Number: 1335950
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]