jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/846940 )
Change subject: [bugfix] fix call of wrapper.py script in pwb.py caller
......................................................................
[bugfix] fix call of wrapper.py script in pwb.py caller
invoking any scripts from pwb.py caller fails because importing wrapper.py
also imports pywikibot and leads config.py to install user-config.py
even if PYWIKIBOT_NO_USER_CONFIG is set.
- use runpy.run_path to call the wrapper.py script from pwb.py caller
- fix the generate_user_files.py path in wrapper.py
- adjust exc_text in config.get_base_dir()
Bug: T321452
Change-Id: I33ac035ef8b2ea1f2600ff650dff4c3397926bd7
---
M pwb.py
M pywikibot/config.py
M pywikibot/scripts/wrapper.py
3 files changed, 13 insertions(+), 9 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 0e12919..e515776 100644
--- a/pwb.py
+++ b/pwb.py
@@ -7,7 +7,9 @@
#
# Distributed under the terms of the MIT license.
#
+import runpy
import sys
+from pathlib import Path
VERSIONS_REQUIRED_MESSAGE = """
Pywikibot is not available on:
@@ -28,8 +30,8 @@
def main():
"""Entry point for :func:`tests.utils.execute_pwb`."""
- from pywikibot.scripts import wrapper
- wrapper.main()
+ path = Path().resolve() / 'pywikibot' / 'scripts' / 'wrapper.py'
+ runpy.run_path(str(path), run_name='__main__')
if __name__ == '__main__':
diff --git a/pywikibot/config.py b/pywikibot/config.py
index 11d7b30..ae751f4 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -377,20 +377,22 @@
if not os.path.isabs(base_dir):
base_dir = os.path.normpath(os.path.join(os.getcwd(), base_dir))
+
# make sure this path is valid and that it contains user-config file
if not os.path.isdir(base_dir):
raise RuntimeError(f"Directory '{base_dir}' does not exist.")
+
# check if config_file is in base_dir
if not exists(base_dir):
- exc_text = 'No {} found in directory {!r}.\n'.format(
- config_file, base_dir)
+ exc_text = f'No {config_file} found in directory {base_dir!r}.\n'
if __no_user_config is None:
assert get_base_dir.__doc__ is not None
exc_text += (
- ' Please check that {0} is stored in the correct location.\n'
- ' Directory where {0} is searched is determined as follows:'
- '\n\n '.format(config_file)) + get_base_dir.__doc__
+ '\nPlease check that {0} is stored in the correct location.'
+ '\nDirectory where {0} is searched is determined as follows:'
+ '\n\n '.format(config_file)
+ ) + get_base_dir.__doc__
raise RuntimeError(exc_text)
if __no_user_config != '2':
diff --git a/pywikibot/scripts/wrapper.py b/pywikibot/scripts/wrapper.py
index db59e06..4446ae8 100755
--- a/pywikibot/scripts/wrapper.py
+++ b/pywikibot/scripts/wrapper.py
@@ -308,8 +308,8 @@
print('NOTE: user-config.py was not found!')
print('Please follow the prompts to create it:')
- run_python_file(str(wrapper_dir.joinpath(
- 'pywikibot', 'scripts', 'generate_user_files.py')), [])
+ run_python_file(
+ str(wrapper_dir.joinpath('generate_user_files.py')), [])
# because we have loaded pywikibot without user-config.py loaded,
# we need to re-start the entire process. Ask the user to do so.
print('Now, you have to re-execute the command to start your script.')
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/846940
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: I33ac035ef8b2ea1f2600ff650dff4c3397926bd7
Gerrit-Change-Number: 846940
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/+/845862 )
Change subject: [cleanup] cleanup Site.merge_history()
......................................................................
[cleanup] cleanup Site.merge_history()
merge_history was added 1.27:
https://www.mediawiki.org/wiki/API:Mergehistory
- remove need_version decorator
- update documentation
- also update documentation of BasePage.merge_history
Bug: T306637
Change-Id: I67d68210a58ab8fd4dcace9d2bdb13a187c8d453
---
M pywikibot/page/_page.py
M pywikibot/site/_apisite.py
2 files changed, 17 insertions(+), 11 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_page.py b/pywikibot/page/_page.py
index ded889b..bd2283a 100644
--- a/pywikibot/page/_page.py
+++ b/pywikibot/page/_page.py
@@ -1782,20 +1782,20 @@
if isinstance(user, pywikibot.User) else cnt[user]
for user in contributors)
- def merge_history(self, dest, timestamp=None, reason=None) -> None:
- """
- Merge revisions from this page into another page.
+ def merge_history(self,
+ dest: 'BasePage',
+ timestamp: Optional[pywikibot.Timestamp] = None,
+ reason: Optional[str] = None) -> None:
+ """Merge revisions from this page into another page.
- See :py:obj:`APISite.merge_history` for details.
+ .. seealso:: :meth:`APISite.merge_history()
+ <pywikibot.site._apisite.APISite.merge_history>` for details.
:param dest: Destination page to which revisions will be merged
- :type dest: pywikibot.Page
:param timestamp: Revisions from this page dating up to this timestamp
will be merged into the destination page (if not given or False,
all revisions will be merged)
- :type timestamp: pywikibot.Timestamp
:param reason: Optional reason for the history merge
- :type reason: str
"""
self.site.merge_history(self, dest, timestamp, reason)
@@ -1809,7 +1809,7 @@
Move this page to a new title.
.. versionchanged:: 7.2
- The `movesubpages` parameter was added
+ The *movesubpages* parameter was added
:param newtitle: The new page title.
:param reason: The edit summary for the move.
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index f45b6c0..98639da 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -55,7 +55,7 @@
)
from pywikibot.login import LoginStatus as _LoginStatus
from pywikibot.site._basesite import BaseSite
-from pywikibot.site._decorators import need_right, need_version
+from pywikibot.site._decorators import need_right
from pywikibot.site._extensions import (
EchoMixin,
FlowMixin,
@@ -2056,7 +2056,6 @@
}
@need_right('mergehistory')
- @need_version('1.27.0-wmf.13')
def merge_history(
self,
source: 'pywikibot.page.BasePage',
@@ -2066,7 +2065,10 @@
) -> None:
"""Merge revisions from one page into another.
- .. seealso:: :api:`Mergehistory`
+ .. seealso::
+
+ - :api:`Mergehistory`
+ - :meth:`page.BasePage.merge_history` (should be preferred)
Revisions dating up to the given timestamp in the source will be
moved into the destination page history. History merge fails if
@@ -2079,6 +2081,10 @@
will be merged into the destination page (if not given or False,
all revisions will be merged)
:param reason: Optional reason for the history merge
+ :raises APIError: unexpected APIError
+ :raises Error: expected APIError or unexpected response
+ :raises NoPageError: *source* or *dest* does not exist
+ :raises PageSaveRelatedError: *source* is equal to *dest*
"""
# Data for error messages
errdata = {
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/845862
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: I67d68210a58ab8fd4dcace9d2bdb13a187c8d453
Gerrit-Change-Number: 845862
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
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/+/845032 )
Change subject: [IMPR] Avoid to many return statements in QueryGenerator.generator property
......................................................................
[IMPR] Avoid to many return statements in QueryGenerator.generator property
Change-Id: I2a974eb70127fe2dda930451df0e20a09dd86215
---
M pywikibot/data/api/_generators.py
1 file changed, 14 insertions(+), 6 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api/_generators.py b/pywikibot/data/api/_generators.py
index 5e6daa2..8164754 100644
--- a/pywikibot/data/api/_generators.py
+++ b/pywikibot/data/api/_generators.py
@@ -605,13 +605,15 @@
while True:
prev_limit, new_limit = self._handle_query_limit(
prev_limit, new_limit, previous_result_had_data)
+
if not hasattr(self, 'data'):
self.data = self.request.submit()
+
if not self.data or not isinstance(self.data, dict):
pywikibot.debug(
'{}: stopped iteration because no dict retrieved from api.'
.format(type(self).__name__))
- return
+ break
if 'query' in self.data and self.resultkey in self.data['query']:
resultdata = self._get_resultdata()
@@ -621,10 +623,12 @@
for item in self.data['query']['normalized']}
else:
self.normalized = {}
+
try:
yield from self._extract_results(resultdata)
except RuntimeError:
- return
+ break
+
# self.resultkey in data in last request.submit()
previous_result_had_data = True
else:
@@ -632,23 +636,27 @@
pywikibot.log("%s: 'query' not found in api response." %
self.__class__.__name__)
pywikibot.log(str(self.data))
+
# if (query-)continue is present, self.resultkey might not have
# been fetched yet
if self.continue_name not in self.data:
- # No results.
- return
+ break # No results.
+
# self.resultkey not in data in last request.submit()
# only "(query-)continue" was retrieved.
previous_result_had_data = False
+
if self.modules[0] == 'random':
# "random" module does not return "(query-)continue"
# now we loop for a new random query
del self.data # a new request is needed
continue
+
if self.continue_name not in self.data:
- return
+ break
+
if self.continue_update():
- return
+ break
del self.data # a new request with (query-)continue is needed
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/845032
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: I2a974eb70127fe2dda930451df0e20a09dd86215
Gerrit-Change-Number: 845032
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
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/+/845863 )
Change subject: [cleanup] Cleanup MW version dependency in Site.notifications
......................................................................
[cleanup] Cleanup MW version dependency in Site.notifications
Also update documentation of EchoMixin
Bug: T306637
Change-Id: Ie009d508d1dd2ec923450e420c629cdd9bf65ab6
---
M pywikibot/site/_extensions.py
1 file changed, 7 insertions(+), 11 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/_extensions.py b/pywikibot/site/_extensions.py
index 6c5cf58..f252c5d 100644
--- a/pywikibot/site/_extensions.py
+++ b/pywikibot/site/_extensions.py
@@ -29,12 +29,11 @@
def notifications(self, **kwargs):
"""Yield Notification objects from the Echo extension.
- :keyword format: If specified, notifications will be returned formatted
- this way. Its value is either 'model', 'special' or None. Default
- is 'special'.
- :type format: str or None
+ :keyword Optional[str] format: If specified, notifications will
+ be returned formatted this way. Its value is either ``model``,
+ ``special`` or ``None``. Default is ``special``.
- Refer API reference for other keywords.
+ .. seealso:: :api:`Notifications` for other keywords.
"""
params = {
'action': 'query',
@@ -48,19 +47,16 @@
data = self.simple_request(**params).submit()
notifications = data['query']['notifications']['list']
- # Support API before 1.27.0-wmf.22
- if hasattr(notifications, 'values'):
- notifications = notifications.values()
-
return (Notification.fromJSON(self, notification)
for notification in notifications)
@need_extension('Echo')
- def notifications_mark_read(self, **kwargs):
+ def notifications_mark_read(self, **kwargs) -> bool:
"""Mark selected notifications as read.
+ .. seealso:: :api:`echomarkread`
+
:return: whether the action was successful
- :rtype: bool
"""
# TODO: ensure that the 'echomarkread' action
# is supported by the site
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/845863
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: Ie009d508d1dd2ec923450e420c629cdd9bf65ab6
Gerrit-Change-Number: 845863
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
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/+/843962 )
Change subject: [IMPR] Improvements for Category.aslink()
......................................................................
[IMPR] Improvements for Category.aslink()
Change-Id: Icaba23ada1d825e95b61c2b23d56082f4fbd093e
---
M pywikibot/page/_category.py
1 file changed, 17 insertions(+), 7 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_category.py b/pywikibot/page/_category.py
index 69bdf0d..37415b2 100644
--- a/pywikibot/page/_category.py
+++ b/pywikibot/page/_category.py
@@ -32,20 +32,30 @@
.format(self.title()))
def aslink(self, sort_key: Optional[str] = None) -> str:
- """
- Return a link to place a page in this Category.
+ """Return a link to place a page in this Category.
- Use this only to generate a "true" category link, not for interwikis
- or text links to category pages.
+ .. warning:: Use this only to generate a "true" category link,
+ not for interwikis or text links to category pages.
+
+ **Usage:**
+
+ >>> site = pywikibot.Site('wikipedia:test')
+ >>> cat = pywikibot.Category(site, 'Foo')
+ >>> cat.aslink()
+ '[[Category:Foo]]'
+ >>> cat = pywikibot.Category(site, 'Foo', sort_key='bar')
+ >>> cat.aslink()
+ '[[Category:Foo|bar]]'
+ >>> cat.aslink('baz')
+ '[[Category:Foo|baz]]'
:param sort_key: The sort key for the article to be placed in this
Category; if omitted, default sort key is used.
"""
key = sort_key or self.sortKey
+ title_with_sort_key = self.title(with_section=False)
if key is not None:
- title_with_sort_key = self.title(with_section=False) + '|' + key
- else:
- title_with_sort_key = self.title(with_section=False)
+ title_with_sort_key += '|' + key
return f'[[{title_with_sort_key}]]'
def subcategories(self,
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/843962
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: Icaba23ada1d825e95b61c2b23d56082f4fbd093e
Gerrit-Change-Number: 843962
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged