jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1005124?usp=email )
Change subject: [bugfix] Ignore InvalidTitleError/InvalidPageError
......................................................................
[bugfix] Ignore InvalidTitleError/InvalidPageError
Bug: T357953
Change-Id: I199d46f59d7b0489b02650c0740e1879fa54ae2a
---
M scripts/interwiki.py
1 file changed, 36 insertions(+), 8 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index d0a4d4e..ead72d0 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -328,7 +328,7 @@
"""
#
-# (C) Pywikibot team, 2003-2023
+# (C) Pywikibot team, 2003-2024
#
# Distributed under the terms of the MIT license.
#
@@ -357,6 +357,7 @@
from pywikibot.exceptions import (
EditConflictError,
Error,
+ InvalidPageError,
InvalidTitleError,
LockedPageError,
NoCreateError,
@@ -1107,9 +1108,16 @@
def check_page(self, page, counter) -> None:
"""Check whether any iw links should be added to the todo list."""
- if not page.exists():
+ try:
+ ok = page.exists()
+ except InvalidPageError as e: # T357953
+ msg = str(e)
+ ok = False
+ else:
+ msg = f'{page} does not exist.'
+ if not ok:
self.conf.remove.append(str(page))
- self.conf.note(f'{page} does not exist. Skipping.')
+ self.conf.note(f'{msg} Skipping.')
if page == self.origin:
# The page we are working on is the page that does not
# exist. No use in doing any work on it in that case.
@@ -1311,7 +1319,12 @@
# Each value will be a list of pages.
new = defaultdict(list)
for page in self.done:
- if page.exists() and not page.isRedirectPage() \
+ try:
+ ok = page.exists()
+ except InvalidPageError: # T357953
+ continue
+
+ if ok and not page.isRedirectPage() \
and not page.isCategoryRedirect():
site = page.site
if site.family.interwiki_forward:
@@ -1985,10 +1998,15 @@
# Get the content of the assembled list in one blow
gen = site.preloadpages(pageGroup, templates=True, langlinks=True,
pageprops=True, quiet=False)
- for _ in gen:
- # we don't want to do anything with them now. The
- # page contents will be read via the Subject class.
- pass
+ while True:
+ # we don't want to do anything with them now.
+ # The page contents will be read via the Subject class.
+ try:
+ next(gen)
+ except StopIteration:
+ break
+ except InvalidTitleError: # T357953
+ pass
# Tell all of the subjects that the promised work is done
for subject in subjectGroup:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1005124?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: I199d46f59d7b0489b02650c0740e1879fa54ae2a
Gerrit-Change-Number: 1005124
Gerrit-PatchSet: 3
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/+/996075?usp=email )
Change subject: [IMPR] raise TypeError in Site.randompages if redirects parameter is invalid
......................................................................
[IMPR] raise TypeError in Site.randompages if redirects parameter is invalid
Also add typing hints for GeneratorsMixin
Change-Id: I58ebcceda48a78013006dc6f202e3338736cc426
---
M pywikibot/site/_generators.py
1 file changed, 48 insertions(+), 8 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index 763b0d9..aae2e82 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -13,7 +13,7 @@
from typing import TYPE_CHECKING, Any
import pywikibot
-from pywikibot.backports import Generator, Iterable, batched
+from pywikibot.backports import Callable, Generator, Iterable, batched
from pywikibot.data import api
from pywikibot.exceptions import (
APIError,
@@ -34,13 +34,33 @@
if TYPE_CHECKING:
- from pywikibot.site._namespace import SingleNamespaceType
+ from data.api import ParamInfo, Request
+ from pywikibot.site._apisite import _RequestWrapperT
+ from pywikibot.site._namespace import NamespacesDict, SingleNamespaceType
+ from pywikibot.site._tokenwallet import TokenWallet
+ from pywikibot.tools import MediaWikiVersion
class GeneratorsMixin:
"""API generators mixin to MediaWiki site."""
+ if TYPE_CHECKING:
+ _generator: Callable[..., _RequestWrapperT]
+ _paraminfo: ParamInfo
+ _request: Callable[..., Request]
+ assert_valid_iter_params: Callable[..., None]
+ encoding: Callable[[], str]
+ get_property_names: Callable[..., list[str]]
+ has_right: Callable[[str], bool]
+ maxlimit: int
+ mw_version: MediaWikiVersion
+ namespaces: NamespacesDict
+ protection_types: Callable[[], set[str]]
+ sametitle: Callable[[str, str], bool]
+ tokens: TokenWallet
+ user: Callable[[], str | None]
+
def load_pages_from_pageids(
self,
pageids: str | Iterable[int | str],
@@ -1787,11 +1807,14 @@
) -> Iterable[pywikibot.Page]:
"""Iterate a number of random pages.
- .. seealso: :api:`Random`
-
Pages are listed in a fixed sequence, only the starting point is
random.
+ .. seealso: :api:`Random`
+ .. versionchanged:: 9.0
+ Raises ``TypeError`` instead of ``AssertionError`` if
+ *redirects* is invalid.
+
:param total: the maximum number of pages to iterate
:param namespaces: only iterate pages in these namespaces.
:param redirects: if True, include only redirect pages in
@@ -1802,10 +1825,12 @@
:raises KeyError: a namespace identifier was not resolved
:raises TypeError: a namespace identifier has an inappropriate
type such as NoneType or bool
- :raises AssertError: unsupported redirects parameter
+ :raises TypeError: unsupported redirects parameter
"""
mapping = {False: None, True: 'redirects', None: 'all'}
- assert redirects in mapping
+ if redirects not in mapping:
+ raise TypeError(f"Invalid type for 'redirects' parameter: "
+ f'{type(redirects).__name__}({redirects})')
redirects_ = mapping[redirects]
params = {}
if redirects_ is not None:
@@ -1970,9 +1995,13 @@
) -> Iterable[pywikibot.Page]:
"""Iterate Page objects retrieved from Special:{special_page}.
- .. seealso:: :api:`Querypage`
+ Generic function for all special pages supported by the site MW
+ API.
- Generic function for all special pages supported by the site MW API.
+ .. seealso:: :api:`Querypage`
+ .. versionchanged:: 9.0
+ Raises ``ValueError`` instead of ``AssertionError`` if
+ *special_page* is invalid.
:param special_page: Special page to query
:param total: number of pages to return
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/996075?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: I58ebcceda48a78013006dc6f202e3338736cc426
Gerrit-Change-Number: 996075
Gerrit-PatchSet: 6
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/+/1004727?usp=email )
Change subject: [doc] Update environment variables in tests documentation
......................................................................
[doc] Update environment variables in tests documentation
Add description for PYWIKIBOT_TEST_NO_RC and PYWIKIBOT_TEST_QUIET
Change-Id: I49e61b30d4c83473a35e5344afd9cdc1e28b7792
---
M tests/README.rst
1 file changed, 25 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/README.rst b/tests/README.rst
index bff07ea..e6880d0 100644
--- a/tests/README.rst
+++ b/tests/README.rst
@@ -116,15 +116,28 @@
.. note:: test names must be given without subsequent ``_tests``.
+**PYWIKIBOT_TEST_NO_RC**
+ This environment variable disables recent changes tests and can be used to
+ speed up tests. GitHub actions enables this setting for that purpose::
+
+ PYWIKIBOT_TEST_NO_RC=1
+
**PYWIKIBOT_TEST_OAUTH**
This environment variable holds the Oauth token. It is set by
``oauth_tests-ci.yml`` CI config file and is solely used by
:mod:`tests.oauth_tests`. You can use it for your private tests. The
- environment variabke must contain consumer key and secret and access
+ environment variable must contain consumer key and secret and access
key and secret delimited by ``:`` as::
PYWIKIBOT_TEST_OAUTH=consumer_key:consumer_secret:access_key:access:secret
+**PYWIKIBOT_TEST_QUIET**
+ This environment variable can be set for quit mode. It prevents output by
+ test package, i.e. 'max_retries reduced from x to y'. It is used be the
+ :func:`tests.utils.execute` test runner. To enable it for other tests use::
+
+ PYWIKIBOT_TEST_QUIET=1
+
**PYWIKIBOT_TEST_RUNNING**
This environment variable skips tests instead of raising
:exc:`exceptions.MaxlagTimeoutError` when maximum retries attempted due to
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1004727?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: I49e61b30d4c83473a35e5344afd9cdc1e28b7792
Gerrit-Change-Number: 1004727
Gerrit-PatchSet: 2
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/+/1004659?usp=email )
Change subject: [tests] Show site if skipping tests due to missing rights
......................................................................
[tests] Show site if skipping tests due to missing rights
Change-Id: I2541bdc05e98c2fe8fb563d9486e4797ebcdef79
---
M tests/aspects.py
1 file changed, 12 insertions(+), 3 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/aspects.py b/tests/aspects.py
index 4c3d1fb..4ae285e 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -675,9 +675,9 @@
for right in cls.rights.split(','):
if not site.has_right(right):
- raise unittest.SkipTest('User "{}" does not have required '
- 'user right "{}"'
- .format(site.user(), right))
+ raise unittest.SkipTest(
+ f'User "{site.user()}" does not have required user '
+ f'right "{right}" on site "{site}"')
class MetaTestCaseClass(type):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1004659?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: I2541bdc05e98c2fe8fb563d9486e4797ebcdef79
Gerrit-Change-Number: 1004659
Gerrit-PatchSet: 2
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/+/1000779?usp=email )
Change subject: [IMPR] Only delegate site methods to public Family methods
......................................................................
[IMPR] Only delegate site methods to public Family methods
BaseSite.__getattr__() rewritten.
Undefined methods calls are delegated to the Family object.
No longer delegate private methods like _get_cr_templates or
_hostname. Also do not delegate static methods or other methods
which does not have 'code' as first parameter.
Change-Id: Ibca93fbbd14b3a901d816afca9db8cbc9ff4dba6
---
M pywikibot/site/_basesite.py
1 file changed, 39 insertions(+), 14 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/site/_basesite.py b/pywikibot/site/_basesite.py
index 813cf91..2eaa581 100644
--- a/pywikibot/site/_basesite.py
+++ b/pywikibot/site/_basesite.py
@@ -1,12 +1,13 @@
"""Objects with site methods independent of the communication interface."""
#
-# (C) Pywikibot team, 2008-2023
+# (C) Pywikibot team, 2008-2024
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations
import functools
+import inspect
import re
import threading
from warnings import warn
@@ -194,19 +195,27 @@
"""Return the username used for the site."""
return self._username
- def __getattr__(self, attr):
- """Delegate undefined methods calls to the Family object."""
- try:
- method = getattr(self.family, attr)
- if not callable(method):
- raise AttributeError
- f = functools.partial(method, self.code)
- if hasattr(method, '__doc__'):
- f.__doc__ = method.__doc__
- return f
- except AttributeError:
- raise AttributeError(f'{type(self).__name__} instance has no '
- f'attribute {attr!r}') from None
+ def __getattr__(self, name: str):
+ """Delegate undefined methods calls to the Family object.
+
+ .. versionchanged:: 9.0
+ Only delegate to public Family methods which have ``code`` as
+ first parameter.
+ """
+ if not name.startswith('_'):
+ obj = getattr(self.family, name, None)
+ if inspect.ismethod(obj):
+ params = inspect.signature(obj).parameters
+ if params:
+ parameter = next(iter(params))
+ if parameter == 'code':
+ method = functools.partial(obj, self.code)
+ if hasattr(obj, '__doc__'):
+ method.__doc__ = obj.__doc__
+ return method
+
+ raise AttributeError(f'{type(self).__name__} instance has no '
+ f'attribute {name!r}') from None
def __str__(self) -> str:
"""Return string representing this Site's name and code."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1000779?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: Ibca93fbbd14b3a901d816afca9db8cbc9ff4dba6
Gerrit-Change-Number: 1000779
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged