jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022557?usp=email )
Change subject: [IMPR] Permit strings as exceptions for fixes
......................................................................
[IMPR] Permit strings as exceptions for fixes
In other words, allow:
fixes['key'] = {
'exceptions': {
'text-contains': 'skip this text',
},
'replacements': [
...
],
}
Previously, a string was interpreted as a sequence (list)
of characters, each being a pattern to search for. Which
would cause silent skipping of pages.
Change-Id: I0f4d01fcf96f6b22d3ddc5970138ef4db8259f85
---
M scripts/replace.py
1 file changed, 5 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/replace.py b/scripts/replace.py
index 5a809f4..f31fd40 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -178,6 +178,8 @@
'title', 'require-title', 'text-contains', 'inside']:
if exceptionCategory in exceptions:
patterns = exceptions[exceptionCategory]
+ if isinstance(patterns, str):
+ patterns = [patterns]
if not use_regex:
patterns = [re.escape(pattern) for pattern in patterns]
patterns = [re.compile(pattern, flags) for pattern in patterns]
@@ -1030,9 +1032,9 @@
if not generators_given and 'generator' in fix:
gen_args = fix['generator']
if isinstance(gen_args, str):
- gen_args = [gen_args]
- for gen_arg in gen_args:
- genFactory.handle_arg(gen_arg)
+ genFactory.handle_arg(gen_args)
+ else:
+ genFactory.handle_args(gen_args)
replacement_set = ReplacementList(fix.get('regex'),
fix.get('exceptions'),
fix.get('nocase'),
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022557?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I0f4d01fcf96f6b22d3ddc5970138ef4db8259f85
Gerrit-Change-Number: 1022557
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022555?usp=email )
Change subject: Fix typos within docstrings
......................................................................
Fix typos within docstrings
Change-Id: I6b273f32a84efc7e63b646a969af9b06ee539cae
---
M pywikibot/_wbtypes.py
M pywikibot/page/_filepage.py
M pywikibot/page/_wikibase.py
M pywikibot/site/_generators.py
M scripts/replace.py
5 files changed, 13 insertions(+), 12 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/_wbtypes.py b/pywikibot/_wbtypes.py
index bbda021..868b7e6 100644
--- a/pywikibot/_wbtypes.py
+++ b/pywikibot/_wbtypes.py
@@ -698,7 +698,7 @@
*normalize* parameter was added.
.. versionchanged:: 8.2
*normalize* parameter was removed due to :phab:`T340495` and
- :phab:`57755`
+ :phab:`T57755`
:param force_iso: whether the output should be forced to ISO 8601
:return: Timestamp in a format resembling ISO 8601
@@ -739,7 +739,7 @@
*normalize* parameter was added.
.. versionchanged:: 8.2
*normalize* parameter was removed due to :phab:`T340495` and
- :phab:`57755`
+ :phab:`T57755`
:return: Wikibase JSON
"""
diff --git a/pywikibot/page/_filepage.py b/pywikibot/page/_filepage.py
index 94dc98f..eaed3dd 100644
--- a/pywikibot/page/_filepage.py
+++ b/pywikibot/page/_filepage.py
@@ -433,9 +433,9 @@
"""
Convenience function to get the associated Wikibase item of the file.
- If WikibaseMediaInfo extension is available (e.g. on Commons),
+ If WikibaseMediaInfo extension is available (e.g., on Commons),
the method returns the associated mediainfo entity. Otherwise,
- it falls back to behavior of BasePage.data_item.
+ it falls back to the behavior of :meth:`BasePage.data_item`.
.. versionadded:: 6.5
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index c242b2c..1f9ed9a 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -84,9 +84,10 @@
Each entity is identified by a data repository it belongs to
and an identifier.
- :cvar DATA_ATTRIBUTES: dictionary which maps data attributes (eg. 'labels',
- 'claims') to appropriate collection classes (eg. LanguageDict,
- ClaimsCollection)
+ :cvar DATA_ATTRIBUTES: dictionary which maps data attributes
+ (e.g., 'labels', 'claims') to appropriate collection classes
+ (e.g., :class:`LanguageDict<pywikibot.page._collections.LanguageDict>`,
+ :class:`ClaimCollection<pywikibot.page._collections.ClaimCollection>`)
:cvar entity_type: entity type identifier
:type entity_type: str
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index 4b48de3..c695523 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -1001,7 +1001,7 @@
:ref:`Http Settings` in your ``user-config.py`` file. Or
increase it patially within your code like:
- .. code:: pytkon
+ .. code:: python
from pywikibot import config
save_timeout = config.socket_timeout # save the timeout config
diff --git a/scripts/replace.py b/scripts/replace.py
index 5a809f4..4f0303f 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -989,9 +989,9 @@
replacement = Replacement(old, new)
if not single_summary:
single_summary = i18n.twtranslate(
- site, 'replace-replacing',
- {'description':
- f' (-{replacement.old} +{replacement.new})'}
+ site,
+ 'replace-replacing',
+ {'description': f' (-{replacement.old} +{replacement.new})'}
)
replacements.append(replacement)
@@ -1013,7 +1013,7 @@
pywikibot.error(
f'fixes[{fix_name!r}] is a {type(fix).__name__}, not a dict')
if type(fix) is tuple:
- pywikibot.info('Maybe a trailing comma in your user_fixes.py?')
+ pywikibot.info('Maybe a trailing comma in your user-fixes.py?')
pywikibot.debug(fix)
return
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022555?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I6b273f32a84efc7e63b646a969af9b06ee539cae
Gerrit-Change-Number: 1022555
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022465?usp=email )
Change subject: [bugfix] cleanup ReplaceRobot.treat(), move statements outside the loop
......................................................................
[bugfix] cleanup ReplaceRobot.treat(), move statements outside the loop
- test isTextExcepted() for the original_text instead for the modified
- replace text only once instead over and over again
- add the optionated category outside the loop
- leave treat method after opening the browser
Bug: T363047
Change-Id: I57417bfaf22627a76cc61db5ba58c4c35e3d77fd
---
M scripts/replace.py
1 file changed, 39 insertions(+), 40 deletions(-)
Approvals:
jenkins-bot: Verified
Matěj Suchánek: Looks good to me, approved
Xqt: Looks good to me, approved
diff --git a/scripts/replace.py b/scripts/replace.py
index 5a809f4..7c91495 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -686,36 +686,37 @@
except InvalidPageError as e:
pywikibot.error(e)
return
+
+ if self.isTextExcepted(original_text):
+ pywikibot.info(f'Skipping {page} because it contains text '
+ f'that is on the exceptions list.')
+ return
+
applied = set()
new_text = original_text
last_text = None
+ while new_text != last_text:
+ last_text = new_text
+ new_text = self.apply_replacements(last_text, applied, page)
+ if not self.opt.recursive:
+ break
+
+ if new_text == original_text:
+ if not self.opt.quiet:
+ pywikibot.info(f'No changes were necessary in {page}')
+ return
+
+ if self.opt.addcat:
+ # Fetch only categories in wikitext, otherwise the others
+ # will be explicitly added.
+ cats = textlib.getCategoryLinks(new_text, site=page.site)
+ if self.opt.addcat not in cats:
+ cats.append(self.opt.addcat)
+ new_text = textlib.replaceCategoryLinks(new_text, cats,
+ site=page.site)
+
context = 0
while True:
- if self.isTextExcepted(new_text):
- pywikibot.info(f'Skipping {page} because it contains text '
- f'that is on the exceptions list.')
- return
-
- while new_text != last_text:
- last_text = new_text
- new_text = self.apply_replacements(last_text, applied, page)
- if not self.opt.recursive:
- break
-
- if new_text == original_text:
- if not self.opt.quiet:
- pywikibot.info(f'No changes were necessary in {page}')
- return
-
- if self.opt.addcat:
- # Fetch only categories in wikitext, otherwise the others
- # will be explicitly added.
- cats = textlib.getCategoryLinks(new_text, site=page.site)
- if self.opt.addcat not in cats:
- cats.append(self.opt.addcat)
- new_text = textlib.replaceCategoryLinks(new_text,
- cats,
- site=page.site)
# Show the title of the page we're working on.
# Highlight the title in purple.
self.current_page = page
@@ -729,9 +730,11 @@
('edit Latest', 'l'), ('open in Browser', 'b'),
('More context', 'm'), ('All', 'a')],
default='N')
+
if choice == 'm':
context = context * 3 if context else 3
continue
+
if choice in ('e', 'l'):
text_editor = editor.TextEditor()
edit_text = original_text if choice == 'e' else new_text
@@ -739,32 +742,28 @@
# if user didn't press Cancel
if as_edited and as_edited != new_text:
new_text = as_edited
- if choice == 'l':
- # prevent changes from being applied again
- last_text = new_text
continue
+
if choice == 'b':
+ # open in browser and leave
pywikibot.bot.open_webbrowser(page)
try:
- original_text = page.get(get_redirect=True, force=True)
+ page.get(get_redirect=True, force=True)
except NoPageError:
pywikibot.info(f'Page {page.title()} has been deleted.')
- break
- new_text = original_text
- last_text = None
- continue
+ return
+
+ if choice == 'n':
+ return
+
if choice == 'a':
self.opt.always = True
- if choice == 'y':
- self.save(page, original_text, new_text, applied,
- show_diff=False, asynchronous=True)
- # choice must be 'N'
+ # break if choice is 'y' or 'a' to save
break
- if self.opt.always and new_text != original_text:
- self.save(page, original_text, new_text, applied,
- show_diff=False, asynchronous=False)
+ self.save(page, original_text, new_text, applied, show_diff=False,
+ asynchronous=not self.opt.always)
def save(self, page, oldtext, newtext, applied, **kwargs) -> None:
"""Save the given page."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022465?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I57417bfaf22627a76cc61db5ba58c4c35e3d77fd
Gerrit-Change-Number: 1022465
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <dalangi-ctr(a)wikimedia.org>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022503?usp=email )
Change subject: [IMPR] Respect 'text-contains' from fixes dictionaries
......................................................................
[IMPR] Respect 'text-contains' from fixes dictionaries
They were completely ignored, despite being documented.
Bug: T142324
Change-Id: I417e3c52c79346797ad62bfff1609f7be7d6b46b
---
M scripts/replace.py
1 file changed, 12 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/replace.py b/scripts/replace.py
index 0302473..5a809f4 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -575,11 +575,14 @@
return True
return False
- def isTextExcepted(self, original_text) -> bool:
+ def isTextExcepted(self, text, exceptions=None) -> bool:
"""Return True iff one of the exceptions applies for the given text."""
- if 'text-contains' in self.exceptions:
- return any(exc.search(original_text)
- for exc in self.exceptions['text-contains'])
+ if exceptions is None:
+ exceptions = self.exceptions
+
+ if 'text-contains' in exceptions:
+ return any(exc.search(text) for exc in exceptions['text-contains'])
+
return False
def apply_replacements(self, original_text, applied, page=None):
@@ -601,6 +604,7 @@
if (replacement.container
and replacement.container.name in skipped_containers):
continue
+
if page is not None and self.isTitleExcepted(
page.title(), replacement.exceptions):
if replacement.container:
@@ -616,6 +620,10 @@
'the title is on the exceptions list.'.format(
replacement.description, page.title(as_link=True)))
continue
+
+ if self.isTextExcepted(original_text, replacement.exceptions):
+ continue
+
old_text = new_text
new_text = textlib.replaceExcept(
new_text, replacement.old_regex, replacement.new,
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022503?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I417e3c52c79346797ad62bfff1609f7be7d6b46b
Gerrit-Change-Number: 1022503
Gerrit-PatchSet: 3
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022502?usp=email )
Change subject: [doc] Update ROADMAP.rst and CHANGELOG.rst
......................................................................
[doc] Update ROADMAP.rst and CHANGELOG.rst
Change-Id: Ia15768dbb3598ef09196d4789f6a0f7a8b4971df
---
M ROADMAP.rst
M scripts/CHANGELOG.rst
2 files changed, 4 insertions(+), 0 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/ROADMAP.rst b/ROADMAP.rst
index 1e7751a..854f7bc 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,6 +1,9 @@
Current release
---------------
+* ``-usernames`` option was added to :mod:`version<pywikibot.scripts.version>` script
+* Circumvent problems with *unique* and *prefix* parameters in :meth:`Site.alllinks()
+ <pywikibot.site._generators.GeneratorsMixin.alllinks>` (:phab:`T359427`)
* Detect nighly version file with :func:`version.getversion_nightly` (:phab:`T362492`)
* :mod:`version`.github_svn_rev2hash() was removed; it was no longer functional (:phab:`T362484`)
* SVN support has been dropped; ``.svnprops`` property settings was removed (:phab:`T362484`)
diff --git a/scripts/CHANGELOG.rst b/scripts/CHANGELOG.rst
index 98733d3..6ef1604 100644
--- a/scripts/CHANGELOG.rst
+++ b/scripts/CHANGELOG.rst
@@ -12,6 +12,7 @@
noreferences
^^^^^^^^^^^^
+* L10N updates
* Show an error message and leave if script is not localized (:phab:`T362103`)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022502?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia15768dbb3598ef09196d4789f6a0f7a8b4971df
Gerrit-Change-Number: 1022502
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <dalangi-ctr(a)wikimedia.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022548?usp=email )
Change subject: [fix] Increase read timeout for alllinks tests.
......................................................................
[fix] Increase read timeout for alllinks tests.
Using *namespace* option different from ``0`` needs a lot of time on
Wikidata site. Increase this value to 60s for tests and add an important
note to documentation.
Bug: T359427
Change-Id: I0b6c56883612fb165b9b792bcc00323d0a25b41a
---
M pywikibot/site/_generators.py
M tests/site_generators_tests.py
2 files changed, 29 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index eaed600..4b48de3 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -428,7 +428,9 @@
) -> Generator[pywikibot.Page, None, None]:
"""Yield internal wikilinks contained (or transcluded) on page.
- .. seealso:: :api:`Links`
+ .. seealso::
+ - :api:`Links`
+ - :meth:`page.BasePage.linkedPages`
:param namespaces: Only iterate pages in these namespaces
(default: all)
@@ -993,7 +995,27 @@
:func:`tools.itertools.filter_unique` in that case which
might be memory intensive. Use it with care.
- .. seealso:: :api:`Alllinks`
+ .. important:: Using *namespace* option different from ``0``
+ needs a lot of time on Wikidata site. You have to increase
+ the **read** timeout part of ``socket_timeout`` in
+ :ref:`Http Settings` in your ``user-config.py`` file. Or
+ increase it patially within your code like:
+
+ .. code:: pytkon
+
+ from pywikibot import config
+ save_timeout = config.socket_timeout # save the timeout config
+ config.socket_timeout = save_timeout[0], 60
+ ... # your code here
+ config.socket_timeout = save_timeout # restore timeout config
+
+ The minimum read timeout value should be 60 seconds in that
+ case.
+
+ .. seealso::
+ - :api:`Alllinks`
+ - :meth:`pagebacklinks`
+ - :meth:`pagelinks`
:param start: Start at this title (page need not exist).
:param prefix: Only yield pages starting with this string.
diff --git a/tests/site_generators_tests.py b/tests/site_generators_tests.py
index 3fae8e7..189943c 100755
--- a/tests/site_generators_tests.py
+++ b/tests/site_generators_tests.py
@@ -363,10 +363,15 @@
msg=f"{page.title()} does not start with 'Fix'"
)
+ # increase timeout due to T359427/T359425
+ # ~ 47s are required on wikidata
+ config_timeout = pywikibot.config.socket_timeout
+ pywikibot.config.socket_timeout = (config_timeout[0], 60)
with self.subTest(msg='Test namespace parameter'):
for page in mysite.alllinks(namespace=1, total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertEqual(page.namespace(), 1)
+ pywikibot.config.socket_timeout = config_timeout
with self.subTest(msg='Test with fromids parameter'):
for page in mysite.alllinks(start='From', namespace=4,
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1022548?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I0b6c56883612fb165b9b792bcc00323d0a25b41a
Gerrit-Change-Number: 1022548
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1019421?usp=email )
Change subject: [bugfix] Fix getversion_nightly() function and deprecate svn support
......................................................................
[bugfix] Fix getversion_nightly() function and deprecate svn support
Get nighly dump version for compat release. The version file was moved
from main to pywikibot folder in core branch. See:
https://github.com/pywikibot/Pywikibot-nightly-creator/blame/628c197c389bf2…
Deprecate svn support because github has desupported it and no svn
checkout be done for Pywikibot any longer. Older places on
wikimedia.org are given up for years and redirects to phabricator.
- remove .svnprops property file
- deprecate version.svn_rev_info() function and remove support for svn
older than 1.7
- remove version.github_svn_rev2hash() function which is no longer
functional because svn support was dropped at github
- deprecate version.getversion_svn() function and remove hsh check
- fix version.getversion_nightly() to use the right path for version
file
- update ROADMAP.rst
Bug: T362492
Bug: T362484
Change-Id: I8b859bab98d1ea95c4c1e9996ef827b42c1d3a61
---
D .svnprops
M ROADMAP.rst
M pywikibot/version.py
3 files changed, 42 insertions(+), 71 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.svnprops b/.svnprops
deleted file mode 100644
index 3fed37c..0000000
--- a/.svnprops
+++ /dev/null
Binary files differ
diff --git a/ROADMAP.rst b/ROADMAP.rst
index e0cecfc..1e7751a 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,6 +1,9 @@
Current release
---------------
+* Detect nighly version file with :func:`version.getversion_nightly` (:phab:`T362492`)
+* :mod:`version`.github_svn_rev2hash() was removed; it was no longer functional (:phab:`T362484`)
+* SVN support has been dropped; ``.svnprops`` property settings was removed (:phab:`T362484`)
* Skip process that requires login to logout (:phab:`T326614`)
* File title of :class:`specialbots.UploadRobot` must have a valid file extension (:phab:`T345786`)
* Add a :attr:`post_processor<specialbots.UploadRobot.post_processor>` attribute to :class:`specialbots.UploadRobot`
@@ -64,6 +67,8 @@
Will be removed in Pywikibot 10
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+* 9.1.0: :func:`version.svn_rev_info` and :func:`version.getversion_svn` will be removed. SVN is no longer supported.
+ (:phab:`T362484`)
* 7.7.0: :mod:`tools.threading` classes should no longer imported from :mod:`tools`
* 7.6.0: :mod:`tools.itertools` datatypes should no longer imported from :mod:`tools`
* 7.6.0: :mod:`tools.collections` datatypes should no longer imported from :mod:`tools`
diff --git a/pywikibot/version.py b/pywikibot/version.py
index ae872d9..542c480 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -1,6 +1,6 @@
"""Module to determine the pywikibot version (tag, revision and date)."""
#
-# (C) Pywikibot team, 2007-2022
+# (C) Pywikibot team, 2007-2024
#
# Distributed under the terms of the MIT license.
#
@@ -11,14 +11,14 @@
import os
import pathlib
import socket
+import sqlite3
import subprocess
import sys
import sysconfig
import time
-import xml.dom.minidom
from contextlib import closing, suppress
from importlib import import_module
-from io import BytesIO
+from pathlib import Path
from warnings import warn
import pywikibot
@@ -26,7 +26,8 @@
from pywikibot.backports import cache
from pywikibot.comms.http import fetch
from pywikibot.exceptions import VersionParseError
-from pywikibot.tools import deprecated
+from pywikibot.tools import deprecated, suppress_warnings
+from pywikibot.tools._deprecate import _NotImplementedWarning
def _get_program_dir() -> str:
@@ -67,7 +68,7 @@
data['cmp_ver'] = 'UNKNOWN'
else:
for branch, path in branches.items():
- with suppress(Exception):
+ with suppress(VersionParseError):
hsh[getversion_onlinerepo(path)] = branch
if hsh:
data['cmp_ver'] = hsh.get(local_hsh, 'OUTDATED')
@@ -94,9 +95,12 @@
getversion_nightly,
getversion_package):
try:
- (tag, rev, date, hsh) = vcs_func(_program_dir)
+ with suppress_warnings(
+ f'.*({vcs_func.__name__}|svn_rev_info) is deprecated since '
+ 'release 9.1.', _NotImplementedWarning):
+ tag, rev, date, hsh = vcs_func(_program_dir)
except Exception as e:
- exceptions[vcs_func] = e
+ exceptions[vcs_func] = vcs_func.__name__, e
else:
break
else:
@@ -105,8 +109,8 @@
# pywikibot was imported without using version control at all.
tag, rev, date, hsh = (
'', '-1 (unknown)', '0 (unknown)', '(unknown)')
- warn('Unable to detect version; exceptions raised:\n{!r}'
- .format(exceptions), UserWarning)
+ warn(f'Unable to detect version; exceptions raised:\n{exceptions!r}',
+ UserWarning)
exceptions = None
# Git and SVN can silently fail, as it may be a nightly.
@@ -124,9 +128,15 @@
return {'tag': tag, 'rev': rev, 'date': datestring, 'hsh': hsh}
-def svn_rev_info(path): # pragma: no cover
+@deprecated(since='9.1')
+def svn_rev_info(path):
"""Fetch information about the current revision of a Subversion checkout.
+ .. deprecated:: 9.1
+ update to git repository.
+ .. versionchanged:: 9.1
+ drop support for svn 1.6 and older.
+
:param path: directory of the Subversion checkout
:return:
- tag (name for the repository),
@@ -137,31 +147,8 @@
if not os.path.isdir(os.path.join(path, '.svn')):
path = os.path.join(path, '..')
- _program_dir = path
- filename = os.path.join(_program_dir, '.svn/entries')
- if os.path.isfile(filename):
- with open(filename) as entries:
- version = entries.readline().strip()
- if version != '12':
- for _ in range(3):
- entries.readline()
- tag = entries.readline().strip()
- t = tag.split('://', 1)
- t[1] = t[1].replace('svn.wikimedia.org/svnroot/pywikipedia/',
- '')
- tag = '[{}] {}'.format(*t)
- for _ in range(4):
- entries.readline()
- date = time.strptime(entries.readline()[:19],
- '%Y-%m-%dT%H:%M:%S')
- rev = entries.readline()[:-1]
- return tag, rev, date
-
- # We haven't found the information in entries file.
- # Use sqlite table for new entries format
- from sqlite3 import dbapi2 as sqlite
with closing(
- sqlite.connect(os.path.join(_program_dir, '.svn/wc.db'))) as con:
+ sqlite3.connect(os.path.join(path, '.svn/wc.db'))) as con:
cur = con.cursor()
cur.execute("""select
local_relpath, repos_path, revision, changed_date, checksum from nodes
@@ -175,52 +162,28 @@
return tag, rev, date
-def github_svn_rev2hash(tag: str, rev): # pragma: no cover
- """Convert a Subversion revision to a Git hash using GitHub.
-
- :param tag: name of the Subversion repo on GitHub
- :param rev: Subversion revision identifier
- :return: the git hash
- """
- uri = f'https://github.com/wikimedia/{tag}/!svn/vcc/default'
- request = fetch(uri, method='PROPFIND',
- data="<?xml version='1.0' encoding='utf-8'?>"
- '<propfind xmlns=\"DAV:\"><allprop/></propfind>',
- headers={'label': str(rev),
- 'user-agent': 'SVN/1.7.5 {pwb}'})
- dom = xml.dom.minidom.parse(BytesIO(request.content))
- hsh = dom.getElementsByTagName('C:git-commit')[0].firstChild.nodeValue
- date = dom.getElementsByTagName('S:date')[0].firstChild.nodeValue
- date = time.strptime(date[:19], '%Y-%m-%dT%H:%M:%S')
- return hsh, date
-
-
-def getversion_svn(path=None): # pragma: no cover
+@deprecated(since='9.1')
+def getversion_svn(path=None):
"""Get version info for a Subversion checkout.
+ .. deprecated:: 9.1
+ update to git repository.
+
:param path: directory of the Subversion checkout
:return:
- tag (name for the repository),
- rev (current Subversion revision identifier),
- date (date of current revision),
- - hash (git hash for the Subversion revision)
+ - hash '(unknown)'
:rtype: ``tuple`` of three ``str`` and a ``time.struct_time``
"""
_program_dir = path or _get_program_dir()
tag, rev, date = svn_rev_info(_program_dir)
- hsh, date2 = github_svn_rev2hash(tag, rev)
- if date.tm_isdst >= 0 and date2.tm_isdst >= 0:
- assert date == date2, 'Date of version is not consistent'
- # date.tm_isdst is -1 means unknown state
- # compare its contents except daylight saving time status
- else:
- for i in range(len(date) - 1):
- assert date[i] == date2[i], 'Date of version is not consistent'
-
rev = f's{rev}'
+
if (not date or not tag or not rev) and not path:
raise VersionParseError
- return (tag, rev, date, hsh)
+ return (tag, rev, date, '(unknown)')
def getversion_git(path=None):
@@ -278,9 +241,13 @@
return (tag, rev, date, hsh)
-def getversion_nightly(path=None): # pragma: no cover
+def getversion_nightly(path: str | Path | None = None): # pragma: no cover
"""Get version info for a nightly release.
+ .. hint::
+ the version informations of the nightly dump is stored in the
+ ``version`` file within the ``pywikibot`` folder.
+
:param path: directory of the uncompressed nightly.
:return:
- tag (name for the repository),
@@ -289,10 +256,9 @@
- hash (git hash for the current revision)
:rtype: ``tuple`` of three ``str`` and a ``time.struct_time``
"""
- if not path:
- path = _get_program_dir()
+ file = Path(path or _get_program_dir()) / 'pywikibot' / 'version'
- with open(os.path.join(path, 'version')) as data:
+ with file.open() as data:
(tag, rev, date, hsh) = data.readlines()
date = time.strptime(date[:19], '%Y-%m-%dT%H:%M:%S')
@@ -352,7 +318,7 @@
return None
program_dir = _get_program_dir()
- if filename[:len(program_dir)] == program_dir:
+ if filename.startswith(program_dir):
return filename
return None
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1019421?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I8b859bab98d1ea95c4c1e9996ef827b42c1d3a61
Gerrit-Change-Number: 1019421
Gerrit-PatchSet: 8
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged