jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1035856?usp=email )
Change subject: [doc] Update ROADMAP.rst
......................................................................
[doc] Update ROADMAP.rst
Change-Id: I15e336058996b0aeca8e7b978416592920afc702
---
M ROADMAP.rst
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index d1ef503..e42e037 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,13 +1,14 @@
Current release
---------------
+* Use :class:`data.api.CachedRequest` for userinfo requests (:phab:`T348925`)
* Raise :exc:`exceptions.SectionError` if a section does not exists on a page (:phab:`T107141`)
* Retry api request on ServerError (:phab:`T364275`, :phab:`T364393`)
Deprecations
------------
-* 9.2.0: *total* argument in ``-logevents`` pagegenrators option is deprecated;
+* 9.2.0: *total* argument in ``-logevents`` pagegenerators option is deprecated;
use ``-limit`` instead (:phab:`T128981`)
* 9.0.0: The *content* parameter of :meth:`proofreadpage.IndexPage.page_gen` is deprecated and will be ignored
(:phab:`T358635`)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1035856?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: I15e336058996b0aeca8e7b978416592920afc702
Gerrit-Change-Number: 1035856
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/+/1034059?usp=email )
Change subject: [IMPR] use CachedRequest for userinfo requests
......................................................................
[IMPR] use CachedRequest for userinfo requests
The expiry for userinfo is set to 1 day and can be changed within
user-config.py file. The second call for the same userinfo is upto
50 times faster.
Also create the site within its own worker thread. Now preload_sites.py
is up to 90 times faster than before and only half as fast than pwb 8.
Bug: T348925
Change-Id: I2bc6c375ee9b676e0a40a372362f37ee4a61ced8
---
M pywikibot/config.py
M pywikibot/scripts/preload_sites.py
M pywikibot/site/_apisite.py
3 files changed, 35 insertions(+), 12 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config.py b/pywikibot/config.py
index 7f12bcc..b2f20fb 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -175,6 +175,8 @@
site_interface = 'APISite'
# number of days to cache namespaces, api configuration, etc.
API_config_expiry = 30
+# userinfo expiry
+API_uinfo_expiry = 1
# The maximum number of bytes which uses a GET request, if not positive
# it'll always use POST requests
diff --git a/pywikibot/scripts/preload_sites.py b/pywikibot/scripts/preload_sites.py
index 8ff7d57..27a31f7 100755
--- a/pywikibot/scripts/preload_sites.py
+++ b/pywikibot/scripts/preload_sites.py
@@ -6,13 +6,18 @@
-worker:<num> The number of parallel tasks to be run. Default is the
number of processors on the machine
-Usage::
+**Usage:**
python pwb.py preload_sites [{<family>}] [-worker:{<num>}]
-To force preloading, change the global expiry value to 0::
+To force preloading, change the global expiry values to 0:
- python pwb.py -API_config_expiry:0 preload_sites [{<family>}]
+ python pwb.py -API_config_expiry:0 -API_uinfo_expiry:0 \
+ preload_sites [{<family>}]
+
+or run the :mod:`cache<scripts.maintenance.cache>` script previeously:
+
+ python pwb.py cache -delete
.. versionchanged:: 7.4
script was moved to the framework scripts folder.
@@ -57,7 +62,17 @@
def preload_family(family: str, executor: ThreadPoolExecutor) -> None:
- """Preload all sites of a single family file."""
+ """Preload all sites of a single family file.
+
+ .. versionchanged:: 9.2
+ use a separate worker thread for each site.
+ """
+
+ def create_page(code, family):
+ """Preload siteinfo and userinfo."""
+ site = pywikibot.Site(code, family)
+ pywikibot.Page(site, 'Main Page')
+
msg = 'Preloading sites of {} family{}'
pywikibot.info(msg.format(family, '...'))
@@ -65,14 +80,13 @@
for code in exceptions.get(family, []):
if code in codes:
codes.remove(code)
+
obsolete = Family.load(family).obsolete
futures = set()
for code in codes:
if code not in obsolete:
- site = pywikibot.Site(code, family)
- # page title does not care
- futures.add(executor.submit(pywikibot.Page, site, 'Main page'))
+ futures.add(executor.submit(create_page, code, family))
wait(futures)
pywikibot.info(msg.format(family, ' completed.'))
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 729a7ec..0fe76de 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -648,6 +648,10 @@
.. seealso:: :api:`Userinfo`
.. versionchanged:: 8.0
Use API formatversion 2.
+ .. versionchanged:: 9.2
+ API call is made through :class:`data.api.CachedRequest` with
+ expiry is set in ``API_uinfo_expiry`` within
+ :ref:`Account settings`.
:return: A dict with the following keys and values:
@@ -661,11 +665,14 @@
"""
if not hasattr(self, '_userinfo'):
- uirequest = self.simple_request(
- action='query',
- meta='userinfo',
- uiprop='blockinfo|hasmsg|groups|rights|ratelimits',
- formatversion=2,
+ uirequest = self._request(
+ expiry=pywikibot.config.API_uinfo_expiry,
+ parameters={
+ 'action': 'query',
+ 'meta': 'userinfo',
+ 'uiprop': 'blockinfo|hasmsg|groups|rights|ratelimits',
+ 'formatversion': 2,
+ }
)
uidata = uirequest.submit()
assert 'query' in uidata, \
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1034059?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: I2bc6c375ee9b676e0a40a372362f37ee4a61ced8
Gerrit-Change-Number: 1034059
Gerrit-PatchSet: 4
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/+/1033678?usp=email )
Change subject: [cleanup] remove arguments cleanup introduced with pwb 6.0.0
......................................................................
[cleanup] remove arguments cleanup introduced with pwb 6.0.0
Change-Id: I1ccc08b60e126397377707569cb31040bd9697cd
---
M scripts/solve_disambiguation.py
1 file changed, 4 insertions(+), 74 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index ac7f4ad..26c1dae 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -75,7 +75,7 @@
"""
#
-# (C) Pywikibot team, 2003-2023
+# (C) Pywikibot team, 2003-2024
#
# Distributed under the terms of the MIT license.
#
@@ -107,7 +107,7 @@
NoPageError,
PageSaveRelatedError,
)
-from pywikibot.tools import first_lower, first_upper, issue_deprecation_warning
+from pywikibot.tools import first_lower, first_upper
from pywikibot.tools.formatter import SequenceOutputter
@@ -610,7 +610,7 @@
}
# refer -help message for complete options documentation
- disambig_options = {
+ available_options = {
'always': None, # always perform the same action
'pos': [], # add possibilities as alternative disambig
'just': True, # just and only use the possibilities given with command
@@ -621,83 +621,13 @@
'min': 0, # minimum number of pages on a disambig
}
- # needed for argument cleanup
- available_options = disambig_options
-
def __init__(self, *args, **kwargs) -> None:
"""Initializer."""
- self._clean_args(args, kwargs)
- super().__init__(**kwargs)
+ super().__init__(*args, **kwargs)
self.ignores = set()
self.summary = None
self.dn_template_str = i18n.translate(self.site, dn_template)
- def _clean_args(self, args, kwargs) -> None:
- """Cleanup positional and keyword arguments.
-
- Replace positional arguments with keyword arguments.
- Replace old keywords with new keywords which are given by
- argument handling.
-
- This also fixes arguments which aren't currently used by
- BaseDisambigBot abstract class but was introduced for the old
- DisambiguationRobot to prevent multiple deprecation warnings.
- """
- # New keys of positional arguments
- keys = ('always', 'pos', 'just', 'dnskip', 'generator', 'primary',
- 'main', 'first', 'min')
-
- # Keys mapping from old argument name to new keywords.
- # The ordering of dics is not safe for Python < 3.7. Therefore
- # we need a dict in addition to key above.
- keymap = {
- 'alternatives': 'pos',
- 'getAlternatives': 'just',
- 'dnSkip': 'dnskip',
- 'main_only': 'main',
- 'first_only': 'first',
- 'minimum': 'min',
- }
-
- # Replace positional arguments with keyword arguments
- for i, arg in enumerate(args):
- key = keys[i]
- issue_deprecation_warning(
- f'Positional argument {i + 1} ({arg})',
- f'keyword argument "{key}={arg}"',
- since='6.0.0')
- if key in kwargs:
- pywikibot.warning('{!r} is given as keyword argument {!r} '
- 'already; ignoring {!r}'
- .format(key, arg, kwargs[key]))
- else:
- kwargs[key] = arg
-
- # replace old keywords to new
- for key in list(kwargs):
- if key in keymap:
- newkey = keymap[key]
- issue_deprecation_warning(
- f'{key!r} argument of {self.__class__.__name__}',
- repr(newkey), since='6.0.0')
- kwargs[newkey] = kwargs.pop(key)
-
- # Expand available_options
- # Currently scripts may have its own options set
- added_keys = []
- for key in keys:
- if key != 'generator' and key not in self.available_options:
- added_keys.append(key)
- self.available_options[key] = self.disambig_options[key]
- if added_keys:
- pywikibot.warning("""\
-The following keys were added to available_options:
-{options}.
-Either add them to available_options setting of {classname}
-bot class or use available_options.update() to use default settings from
-DisambiguationRobot""".format(options=added_keys,
- classname=self.__class__.__name__))
-
def checkContents(self, text: str) -> str | None: # noqa: N802
"""
Check if the text matches any of the ignore regexes.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1033678?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: I1ccc08b60e126397377707569cb31040bd9697cd
Gerrit-Change-Number: 1033678
Gerrit-PatchSet: 2
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/+/1033038?usp=email )
Change subject: [cleanup] drop bool values of deprecate_arg and deprecated_args
......................................................................
[cleanup] drop bool values of deprecate_arg and deprecated_args
bool values and None values were implemented to throw a
DeprecationWarning, PendingDeprecationWarning or FutureWarning but we
only used the later since years and never used the
PendingDeprecationWarning. Also update tests and backport types.NoneType.
Change-Id: I10ca6346525e71998d839e696b5e088242c76600
---
M pywikibot/backports.py
M pywikibot/tools/_deprecate.py
M tests/tools_deprecate_tests.py
3 files changed, 44 insertions(+), 32 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/backports.py b/pywikibot/backports.py
index 8b9d989..815f7d3 100644
--- a/pywikibot/backports.py
+++ b/pywikibot/backports.py
@@ -116,10 +116,12 @@
removesuffix = str.removesuffix # type: ignore[assignment]
-# bpo-38200
if PYTHON_VERSION < (3, 10) or SPHINX_RUNNING:
from itertools import tee
+ NoneType = type(None)
+
+ # bpo-38200
def pairwise(iterable):
"""Return successive overlapping pairs taken from the input iterable.
@@ -132,6 +134,7 @@
next(b, None)
return zip(a, b)
else:
+ from types import NoneType
from itertools import pairwise # type: ignore[no-redef]
diff --git a/pywikibot/tools/_deprecate.py b/pywikibot/tools/_deprecate.py
index 9bbc133..571aad1 100644
--- a/pywikibot/tools/_deprecate.py
+++ b/pywikibot/tools/_deprecate.py
@@ -19,7 +19,7 @@
deprecation decorators moved to _deprecate submodule
"""
#
-# (C) Pywikibot team, 2008-2023
+# (C) Pywikibot team, 2008-2024
#
# Distributed under the terms of the MIT license.
#
@@ -36,6 +36,7 @@
from typing import Any
from warnings import warn
+from pywikibot.backports import NoneType
from pywikibot.tools import SPHINX_RUNNING
@@ -309,10 +310,12 @@
deprecated = add_full_name(deprecated)
-def deprecate_arg(old_arg: str, new_arg: str | bool | None):
+def deprecate_arg(old_arg: str, new_arg: str | None = None):
"""Decorator to declare old_arg deprecated and replace it with new_arg.
- Usage:
+ **Usage:**
+
+ .. code-block:: python
@deprecate_arg('foo', 'bar')
def my_function(bar='baz'): pass
@@ -323,9 +326,12 @@
# ignores 'foo' keyword no longer used by my_function
:func:`deprecated_args` decorator should be used in favour of this
- ``deprecate_arg`` decorator but it is held to deprecate args which
- become a reserved word in future Python releases and to prevent
- syntax errors.
+ ``deprecate_arg`` decorator but it is held to deprecate args of
+ reserved words even for future Python releases and to prevent syntax
+ errors.
+
+ .. versionchanged:: 9.2
+ bool type of *new_arg* is no longer supported.
:param old_arg: old keyword
:param new_arg: new keyword
@@ -333,21 +339,29 @@
return deprecated_args(**{old_arg: new_arg})
-def deprecated_args(**arg_pairs):
+def deprecated_args(**arg_pairs: str | None):
"""Decorator to declare multiple args deprecated.
- Usage:
+ **Usage:**
+
+ .. code-block:: python
@deprecated_args(foo='bar', baz=None)
def my_function(bar='baz'): pass
# replaces 'foo' keyword by 'bar' and ignores 'baz' keyword
+ .. versionchanged:: 3.0.20200703
+ show a FutureWarning if the *arg_pairs* value is True; don't show
+ a warning if the value is an empty string.
+ .. versionchanged:: 6.4
+ show a FutureWarning for renamed arguments
+ .. versionchanged:: 9.2
+ bool type argument is no longer supported.
+
:param arg_pairs: Each entry points to the new argument name. If an
- argument is to be removed, the value may be one of the following:
- - None: shows a DeprecationWarning
- - False: shows a PendingDeprecationWarning
- - True: shows a FutureWarning (only once)
- - empty string: no warning is printed
+ argument is to be removed, the value may be either an empty str
+ or ``None``; the later also shows a `FutureWarning` once.
+ :raises TypeError: *arg_pairs* value is neither str nor None or
"""
def decorator(obj):
"""Outer wrapper.
@@ -376,15 +390,18 @@
if old_arg not in __kw:
continue
- if new_arg not in [True, False, None, '']:
+ if not isinstance(new_arg, (str, NoneType)):
+ raise TypeError(
+ f'deprecated_arg value for {old_arg} of {name} must '
+ f'be either str or None, not {type(new_arg).__name__}')
+
+ if new_arg:
if new_arg in __kw:
warn('{new_arg} argument of {name} '
'replaces {old_arg}; cannot use both.'
.format_map(output_args),
RuntimeWarning, depth)
else:
- # If the value is positionally given this will
- # cause a TypeError, which is intentional
warn('{old_arg} argument of {name} '
'is deprecated; use {new_arg} instead.'
.format_map(output_args),
@@ -393,15 +410,9 @@
elif new_arg == '':
pass
else:
- if new_arg is False:
- cls = PendingDeprecationWarning
- elif new_arg is True:
- cls = FutureWarning
- else: # new_arg is None
- cls = DeprecationWarning
warn('{old_arg} argument of {name} is deprecated.'
.format_map(output_args),
- cls, depth)
+ FutureWarning, depth)
del __kw[old_arg]
return obj(*__args, **__kw)
diff --git a/tests/tools_deprecate_tests.py b/tests/tools_deprecate_tests.py
index fd5cc21..c4a6895 100755
--- a/tests/tools_deprecate_tests.py
+++ b/tests/tools_deprecate_tests.py
@@ -135,7 +135,7 @@
return foo
-@deprecated_args(bah='foo', silent=False, loud=True, old=None)
+@deprecated_args(bah='foo', silent=None, loud=None, old='')
def deprecated_func_arg3(foo=None):
"""Test deprecated_args with three drops and one rename."""
return foo
@@ -459,6 +459,7 @@
def test_deprecate_and_remove_function_args(self):
"""Test @deprecated and removed function argument."""
+ deprecation_msg = f' argument of {__name__ }.deprecated_func_arg3'
rv = deprecated_func_arg3()
self.assertIsNone(rv)
self.assertNoDeprecation()
@@ -469,19 +470,16 @@
rv = deprecated_func_arg3(foo=1, silent=42)
self.assertEqual(rv, 1)
- self.assertDeprecationClass(PendingDeprecationWarning)
- self.assertOneDeprecationParts(
- 'silent argument of ' + __name__ + '.deprecated_func_arg3')
+ self.assertDeprecationClass(FutureWarning)
+ self.assertOneDeprecationParts('silent' + deprecation_msg)
rv = deprecated_func_arg3(3, loud='3')
self.assertEqual(rv, 3)
- self.assertOneDeprecationParts(
- 'loud argument of ' + __name__ + '.deprecated_func_arg3')
+ self.assertOneDeprecationParts('loud' + deprecation_msg)
rv = deprecated_func_arg3(4, old='4')
self.assertEqual(rv, 4)
- self.assertOneDeprecationParts(
- 'old argument of ' + __name__ + '.deprecated_func_arg3')
+ self.assertNoDeprecation()
def test_function_remove_last_args(self):
"""Test @remove_last_args on functions."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1033038?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: I10ca6346525e71998d839e696b5e088242c76600
Gerrit-Change-Number: 1033038
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged