jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1354225?usp=email )
Change subject: scripts: add next_version.py script to update version directives
......................................................................
scripts: add next_version.py script to update version directives
This allows ``next`` in documentation version directives
to target the upcoming release of the current branch.
Bug: T440810
Change-Id: Ie9482072e5457c969c232649f4a87347d1176a26
---
M docs/scripts/maintenance.rst
M docs/scripts_ref/scripts.maintenance.rst
M scripts/README.rst
A scripts/maintenance/next_version.py
4 files changed, 102 insertions(+), 0 deletions(-)
Approvals:
Mahveotm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/scripts/maintenance.rst b/docs/scripts/maintenance.rst
index da7df5d..a97126b 100644
--- a/docs/scripts/maintenance.rst
+++ b/docs/scripts/maintenance.rst
@@ -30,6 +30,13 @@
:no-members:
:noindex:
+next\_version script
+====================
+
+.. automodule:: scripts.maintenance.next_version
+ :no-members:
+ :noindex:
+
unidata script
==============
diff --git a/docs/scripts_ref/scripts.maintenance.rst
b/docs/scripts_ref/scripts.maintenance.rst
index b24603d..83f89df 100644
--- a/docs/scripts_ref/scripts.maintenance.rst
+++ b/docs/scripts_ref/scripts.maintenance.rst
@@ -30,6 +30,11 @@
.. automodule:: scripts.maintenance.make_i18n_dict
+scripts.maintenance.next\_version
+---------------------------------
+
+.. automodule:: scripts.maintenance.next_version
+
scripts.maintenance.unidata
---------------------------
diff --git a/scripts/README.rst b/scripts/README.rst
index 46304c8..188993f 100644
--- a/scripts/README.rst
+++ b/scripts/README.rst
@@ -198,6 +198,8 @@
+------------------------+---------------------------------------------------------+
| make_i18n_dict.py | Generate an i18n file from a given script.
|
+------------------------+---------------------------------------------------------+
+| next_version.py | Replace ``next`` in Sphinx version directives
|
++------------------------+---------------------------------------------------------+
| unidata.py | Updates _first_upper_exception_dict in
tools.unidata |
+------------------------+---------------------------------------------------------+
diff --git a/scripts/maintenance/next_version.py
b/scripts/maintenance/next_version.py
new file mode 100755
index 0000000..ae0e3a4
--- /dev/null
+++ b/scripts/maintenance/next_version.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2026
+#
+# Distributed under the terms of the MIT license.
+#
+"""Replace ``next`` in version directives with the release version.
+
+This script allows ``next`` in documentation version directives to
+target the upcoming release of the current branch::
+
+ .. version-added:: next
+ .. version-changed:: next
+ .. version-deprecated:: next
+ .. version-removed:: next
+
+.. version-added:: 11.10
+"""
+
+from __future__ import annotations
+
+import re
+import sys
+from pathlib import Path
+
+import pywikibot
+
+
+DIRECTIVE_RE = re.compile(
+ r'(version-(?:added|changed|removed|deprecated):: )next\b'
+)
+
+ROOT = Path(__file__).resolve().parents[2]
+
+
+def get_version() -> str:
+ """Return the current release version."""
+ version = pywikibot.__version__
+ match = re.fullmatch(r'(\d+)\.(\d+)\.(\d+)(.*)', version)
+ if not match:
+ raise ValueError(f'Invalid version: {version!r}')
+
+ major, minor, patch, suffix = match.groups()
+ if int(patch):
+ return f'{major}.{minor}.{patch}'
+
+ return f'{major}.{minor}'
+
+
+def fix_file(path: Path, version: str) -> int:
+ """Replace ``next`` in version directives and return the change count."""
+ if path == Path(__file__).resolve(): # exclude this script
+ return 0
+
+ text = path.read_text(encoding='utf-8')
+ updated, count = DIRECTIVE_RE.subn(r'\g<1>' + version, text)
+
+ if count:
+ path.write_text(updated, encoding='utf-8')
+ pywikibot.info(
+ f'Updated {path.relative_to(ROOT)} ({count} replacements)')
+
+ return count
+
+
+def main(*args: str) -> None:
+ """Update version directives throughout the repository."""
+ if not args:
+ args = sys.argv[1:]
+ sys.argv = [sys.argv[0]]
+
+ for arg in args:
+ if arg in ('-h', '-help', '--help'):
+ pywikibot.show_help()
+ return
+
+ version = get_version()
+
+ paths = list(ROOT.glob('*.py'))
+ for directory in ('pywikibot', 'tests', 'scripts', 'docs'):
+ paths.extend((ROOT / directory).rglob('*.py'))
+
+ total = sum(fix_file(path, version) for path in paths)
+ pywikibot.info(f'Updated {total} version directives to {version}.')
+
+
+if __name__ == '__main__':
+ main()
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1354225?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: Ie9482072e5457c969c232649f4a87347d1176a26
Gerrit-Change-Number: 1354225
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Mahveotm <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]