jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/800891 )
Change subject: [IMPR] Make BaseBot._generator_completed a public attribute
......................................................................
[IMPR] Make BaseBot._generator_completed a public attribute
generator_completed can be used inside scripts e.g. in teardown method.
- rename _generator_completed to generator_completed
- update category.py
- add documtentation and an example for this attribute
Change-Id: I48eac33feab0d24cadfa30de6250631ba3dd74cb
---
M pywikibot/bot.py
M scripts/category.py
2 files changed, 16 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 70e845d..ebe226b 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1279,7 +1279,7 @@
else:
#: instance variable to hold the generator processed by
#: :meth:`run` method
- self.generator = kwargs.pop('generator')
+ self.generator = kwargs.pop('generator') # type: Iterable
self.available_options.update(self.update_options)
super().__init__(**kwargs)
@@ -1295,7 +1295,19 @@
Your additional counters are also printed during :meth:`exit`
"""
- self._generator_completed = False
+ self.generator_completed = False # type: bool
+ """Instance attribute which is True if the generator is completed.
+
+ To check for an empty generator you may use::
+
+ if self.generator_completed and not self.counter['read']:
+ print('generator was emtpty')
+
+ .. note:: An empty generator remains False.
+ .. versionadded:: 3.0
+ .. versionchanged:: 7.4
+ renamed to `generator_completed` to become a public attribute.
+ """
#: instance variable to hold the default page type
self.treat_page_type = pywikibot.page.BasePage # type: Any
@@ -1643,7 +1655,7 @@
self.counter['read'] += 1
self.treat(page)
- self._generator_completed = True
+ self.generator_completed = True
except QuitKeyboardInterrupt:
pywikibot.output('\nUser quit {} bot run...'
.format(self.__class__.__name__))
diff --git a/scripts/category.py b/scripts/category.py
index 8db8a1d..360c779 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -1240,7 +1240,7 @@
def teardown(self) -> None:
"""Cleanups after run operation."""
- if self._generator_completed and not self.counter['read']:
+ if self.generator_completed and not self.counter['read']:
pywikibot.output('There are no pages or files in category {}.'
.format(self.cat_title))
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/800891
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: I48eac33feab0d24cadfa30de6250631ba3dd74cb
Gerrit-Change-Number: 800891
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dalba <dalba.wiki(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/+/800932 )
Change subject: [IMPR] solve W505 doc line too long (85 > 80 characters)
......................................................................
[IMPR] solve W505 doc line too long (85 > 80 characters)
Change-Id: Iaba5d99ccf0c6b8cef397bc2c50faf957edd1db0
---
M scripts/dataextend.py
1 file changed, 2 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/dataextend.py b/scripts/dataextend.py
index 5792aee..313a6b6 100644
--- a/scripts/dataextend.py
+++ b/scripts/dataextend.py
@@ -10350,7 +10350,8 @@
if self.isperson:
self.urlbase = 'https://enciclopedia.itaucultural.org.br/{id}'
else:
- # Analyzer only created for persons, for works and possible other it can be extended later
+ # Analyzer only created for persons,
+ # for works and possible other it can be extended later
self.urlbase = None
self.hrtre = r'<h1[^<>]*>\s*Outras informações.*?<div class="section_content">(.*?)</section>'
self.language = 'pt'
@@ -13428,9 +13429,6 @@
return [self.findbyre(r'<b>(.*?)<', html)] + \
self.findallbyre(r'<FONT[^<>]*>(.*?)<', html)
- # def findlanguagesspoken(self, html):
- # return self.findallbyre(r'<span class=LI>([^<>]*) - ', html, 'language')
-
def findmixedrefs(self, html):
return self.finddefaultmixedrefs(html, includesocial=False)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/800932
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: Iaba5d99ccf0c6b8cef397bc2c50faf957edd1db0
Gerrit-Change-Number: 800932
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/800881 )
Change subject: [doc] Update ROADMAP.rst
......................................................................
[doc] Update ROADMAP.rst
Change-Id: Ie7d7aa4f4b728058f578b043259a01dc4abd8f28
---
M ROADMAP.rst
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/ROADMAP.rst b/ROADMAP.rst
index 8aba0c0..a2eeb86 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,7 +1,7 @@
Current release 7.4.0
^^^^^^^^^^^^^^^^^^^^^
-* *(no changes yet)*
+* Return gracefully from pwb.find_alternates if folder in user_script_paths does not exist (:phab:`T308910`)
Deprecations
^^^^^^^^^^^^
@@ -36,7 +36,7 @@
* 7.3.0: Python 3.5 support will be dropped (:phab:`T301908`)
* 7.1.0: win32_unicode.py will be removed
* 7.0.0: The i18n identifier 'cosmetic_changes-append' will be removed in favour of 'pywikibot-cosmetic-changes'
-* 7.0.0: Require mysql >= 0.7.11 (:phab:`T216741`)
+* 7.0.0: pymysql < 0.7.11 will be dropped; require pymysql >= 0.7.11 (:phab:`T216741`)
* 5.5.0: APISite.redirectRegex() will be removed in favour of APISite.redirect_regex()
* 4.0.0: Revision.parent_id will be removed in favour of Revision.parentid
* 4.0.0: Revision.content_model will be removed in favour of Revision.contentmodel
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/800881
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: Ie7d7aa4f4b728058f578b043259a01dc4abd8f28
Gerrit-Change-Number: 800881
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/795282 )
Change subject: [doc] remove epydoc stuff
......................................................................
[doc] remove epydoc stuff
- remove pywikibot_epytext_to_sphinx function
- replace epytext tokens with sphinx counterparts
- update deprecation tests
- update deprecation notice with @deprecated decorator
Bug: T308985
Change-Id: I41fc77f7b7bb942bb06cb8a7a3050ecd43c8d71c
---
M docs/conf.py
M pywikibot/bot_choice.py
M pywikibot/data/api.py
M pywikibot/page/_pages.py
M pywikibot/site/_datasite.py
M pywikibot/tools/_deprecate.py
M scripts/archivebot.py
M scripts/dataextend.py
M scripts/redirect.py
M scripts/replace.py
M tests/deprecation_tests.py
11 files changed, 34 insertions(+), 86 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/conf.py b/docs/conf.py
index 1b2a310..ec0e077 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -377,59 +377,6 @@
}
-TOKENS_WITH_PARAM = [
- # sphinx
- 'param', 'parameter', 'arg', 'argument', 'key', 'keyword',
- 'type',
- 'raises', 'raise', 'except', 'exception',
- 'var', 'ivar', 'cvar',
- 'vartype',
- 'meta',
- # epytext
- 'todo',
-]
-
-TOKENS = [
- # sphinx
- 'return', 'returns', 'rtype',
- # epytext
- 'attention', 'author', 'bug',
- 'change', 'changed',
- 'contact',
- 'copyright', '(c)',
- 'deprecated',
- 'invariant', 'license', 'note',
- 'organization', 'org',
- 'permission',
- 'postcondition', 'postcond',
- 'precondition', 'precond',
- 'requires', 'require', 'requirement',
- 'see', 'seealso',
- 'since', 'status', 'summary', 'todo',
- 'version',
- 'warn', 'warning',
-]
-
-
-def pywikibot_epytext_to_sphinx(app, what, name, obj, options, lines):
- """Convert epytext tokens to sphinx."""
- result = []
- for line in lines:
- line = re.sub(r'(\A *)@({}) '.format('|'.join(TOKENS_WITH_PARAM)),
- r'\1:\2 ', line) # tokens with parameter
- line = re.sub(r'(\A *)@({}):'.format('|'.join(TOKENS)),
- r'\1:\2:', line) # short token
- line = re.sub(r'(\A *)@(?:kwarg|kwparam) ',
- r'\1:keyword ', line) # keyword
- line = re.sub(r'(\A| )L\{([^}]*)\}', r'\1:py:obj:`\2`', line) # Link
- line = re.sub(r'(\A| )B\{([^}]*)\}', r'\1**\2**', line) # Bold
- line = re.sub(r'(\A| )I\{([^}]*)\}', r'\1*\2*', line) # Italic
- line = re.sub(r'(\A| )C\{([^}]*)\}', r'\1``\2``', line) # Code
- line = re.sub(r'(\A| )U\{([^}]*)\}', r'\1\2', line) # Url
- result.append(line)
- lines[:] = result[:] # assignment required in this way
-
-
def pywikibot_fix_phab_tasks(app, what, name, obj, options, lines):
"""Convert Phabricator tasks id to a link using sphinx.ext.extlinks."""
result = []
@@ -541,7 +488,6 @@
def setup(app):
"""Implicit Sphinx extension hook."""
- app.connect('autodoc-process-docstring', pywikibot_epytext_to_sphinx)
app.connect('autodoc-process-docstring', pywikibot_fix_phab_tasks)
app.connect('autodoc-process-docstring', pywikibot_docstring_fixups)
app.connect('autodoc-process-docstring', pywikibot_script_docstring_fixups)
diff --git a/pywikibot/bot_choice.py b/pywikibot/bot_choice.py
index 8e4e7b3..040f06f 100644
--- a/pywikibot/bot_choice.py
+++ b/pywikibot/bot_choice.py
@@ -125,7 +125,9 @@
def out(self) -> str:
"""String to be used when selected before or after the question.
- :Note: This method is used by ui.input_choice instead of output().
+ .. note:: This method is used by :meth:`ui.input_choice
+ <pywikibot.userinterfaces._interface_base.ABUIC.input_choice>`
+ instead of deprecated :meth:`output`.
.. versionadded:: 6.2
"""
@@ -136,7 +138,7 @@
"""Output string.
.. deprecated:: 6.5
- This method was replaced by :py:obj:`out` property and is no
+ This method was replaced by :attr:`out` property and is no
no longer used by the
:py:mod:`userinterfaces <pywikibot.userinterfaces>` system.
"""
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 8e821da..ab01827 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2456,13 +2456,12 @@
namespace identifiers. An empty iterator clears any
namespace restriction.
:raises KeyError: a namespace identifier was not resolved
-
+ """
# TODO: T196619
- # @raises TypeError: module does not support a namespace parameter
+ # :raises TypeError: module does not support a namespace parameter
# or a namespace identifier has an inappropriate
# type such as NoneType or bool, or more than one namespace
# if the API module does not support multiple namespaces
- """
assert self.limited_module # some modules do not have a prefix
param = self.site._paraminfo.parameter('query+' + self.limited_module,
'namespace')
diff --git a/pywikibot/page/_pages.py b/pywikibot/page/_pages.py
index 848b7c0..aa5d930 100644
--- a/pywikibot/page/_pages.py
+++ b/pywikibot/page/_pages.py
@@ -1077,8 +1077,8 @@
def _check_bot_may_edit(self, module: Optional[str] = None) -> bool:
"""A botMayEdit helper method.
- @param module: The module name to be restricted. Defaults to
- pywikibot.calledModuleName().
+ :param module: The module name to be restricted. Defaults to
+ :func:`pywikibot.calledModuleName`.
"""
if not hasattr(self, 'templatesWithParams'):
return True
diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index 440134e..097928a 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -713,7 +713,8 @@
return gen
@need_right('edit')
- def _wbset_action(self, itemdef, action, action_data, **kwargs):
+ def _wbset_action(self, itemdef, action: str, action_data,
+ **kwargs) -> dict:
"""
Execute wbset{action} on a Wikibase entity.
@@ -724,9 +725,8 @@
:type itemdef: str, WikibaseEntity or Page connected to such item
:param action: wbset{action} to perform:
'wbsetaliases', 'wbsetdescription', 'wbsetlabel', 'wbsetsitelink'
- :type action: str
- :param data: data to be used in API request, see API help
- :type data: SiteLink or dict
+ :param action_data: data to be used in API request, see API help
+ :type action_data: SiteLink or dict
wbsetaliases:
dict shall have the following structure:
{'language': value (str),
@@ -740,12 +740,11 @@
wbsetsitelink:
dict shall have keys 'linksite', 'linktitle' and
optionally 'badges'
- @kwargs bot: Whether to mark the edit as a bot edit, default is True
+ :keyword bot: Whether to mark the edit as a bot edit, default is True
:type bot: bool
- @kwargs tags: Change tags to apply with the edit
+ :keyword tags: Change tags to apply with the edit
:type tags: list of str
:return: query result
- :rtype: dict
:raises AssertionError, TypeError
"""
def format_sitelink(sitelink):
diff --git a/pywikibot/tools/_deprecate.py b/pywikibot/tools/_deprecate.py
index bff6759..22da253 100644
--- a/pywikibot/tools/_deprecate.py
+++ b/pywikibot/tools/_deprecate.py
@@ -270,9 +270,9 @@
if not deprecated_notice.search(wrapper.__doc__):
add_docstring(wrapper)
else:
- # Get docstring up to @params so deprecation notices for
+ # Get docstring up to :params so deprecation notices for
# parameters don't disrupt it
- trim_params = re.compile(r'^.*?((?=@param)|$)', re.DOTALL)
+ trim_params = re.compile(r'^.*?((?=:param)|$)', re.DOTALL)
trimmed_doc = trim_params.match(wrapper.__doc__).group(0)
if not deprecated_notice.search(trimmed_doc): # No notice
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 6d53efc..41609eb 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -268,7 +268,7 @@
150K - 150 kilobytes
2M - 2 megabytes
- @Returns: a tuple ``(size, unit)``, where ``size`` is an integer and
+ :Returns: a tuple ``(size, unit)``, where ``size`` is an integer and
unit is ``'B'`` (bytes) or ``'T'`` (threads).
"""
match = re.fullmatch(r'(\d{1,3}(?: \d{3})+|\d+) *([BkKMT]?)', string)
diff --git a/scripts/dataextend.py b/scripts/dataextend.py
index 1411475..5792aee 100644
--- a/scripts/dataextend.py
+++ b/scripts/dataextend.py
@@ -15413,7 +15413,7 @@
If args is an empty list, sys.argv is used.
- @param args: command line arguments
+ :param args: command line arguments
"""
item = None
options = {}
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 4488167..9029760 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -457,13 +457,12 @@
self.is_repo = self.repo if self.repo == page.site else None
return page
- def delete_redirect(self, page, summary_key) -> None:
+ def delete_redirect(self, page, summary_key: str) -> None:
"""Delete the redirect page.
- @param page: The page to delete
- @type page: pywikibot.page.BasePage
- @param summary_key: The message key for the deletion summary
- @type summary_key: str
+ :param page: The page to delete
+ :type page: pywikibot.page.BasePage
+ :param summary_key: The message key for the deletion summary
"""
assert page.site == self.current_page.site, (
'target page is on different site {}'.format(page.site))
@@ -666,8 +665,8 @@
def treat(self, page) -> None:
"""Treat a page.
- @param page: Page to be treated.
- @type page: pywikibot.page.BasePage
+ :param page: Page to be treated.
+ :type page: pywikibot.page.BasePage
"""
if self.counter['read'] >= self.opt.limit:
pywikibot.output('\nNumber of pages reached the limit. '
diff --git a/scripts/replace.py b/scripts/replace.py
index 3e932e8..b8c0ae0 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -510,7 +510,6 @@
:type allowoverlap: bool
:keyword recursive: Recurse replacement as long as possible.
:type recursive: bool
- :warning: Be careful, this might lead to an infinite loop.
:keyword addcat: category to be added to every page touched
:type addcat: pywikibot.Category or str or None
:keyword sleep: slow down between processing multiple regexes
@@ -520,9 +519,12 @@
:keyword always: the user won't be prompted before changes are made
:type keyword: bool
:keyword site: Site the bot is working on.
- :warning: site parameter should be passed to constructor.
- Otherwise the bot takes the current site and warns the operator
- about the missing site
+ .. warning::
+ - Be careful with `recursive` parameter, this might lead to an
+ infinite loop.
+ - `site` parameter should be passed to constructor.
+ Otherwise the bot takes the current site and warns the operator
+ about the missing site
"""
def __init__(self, generator,
diff --git a/tests/deprecation_tests.py b/tests/deprecation_tests.py
index 649fb42..a0efea2 100755
--- a/tests/deprecation_tests.py
+++ b/tests/deprecation_tests.py
@@ -122,7 +122,7 @@
@deprecated
def deprecated_func_docstring_arg(foo=None):
- """@param foo: Foo. DEPRECATED."""
+ """:param foo: Foo. DEPRECATED."""
return foo
@@ -308,12 +308,13 @@
(deprecated_func_instead_docstring, "DEPRECATED, don't use "
'this. Deprecated function.'),
(deprecated_func_docstring_arg, 'Deprecated.\n\n'
- '@param foo: Foo. DEPRECATED.'),
+ ':param foo: Foo. DEPRECATED.'),
(deprecated_func_docstring_arg2, '\n DEPRECATED.\n\n'
' :param foo: Foo. DEPRECATED.\n '),
]
for rv, doc in testcases:
- self.assertEqual(rv.__doc__, doc)
+ with self.subTest(function=rv.__name__):
+ self.assertEqual(rv.__doc__, doc)
def test_deprecated_function_bad_args(self):
"""Test @deprecated function with bad arguments."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/795282
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: I41fc77f7b7bb942bb06cb8a7a3050ecd43c8d71c
Gerrit-Change-Number: 795282
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.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/+/794469 )
Change subject: [bugfix] Return gracefully from pwb.find_alternates if a folder does not exits
......................................................................
[bugfix] Return gracefully from pwb.find_alternates if a folder does not exits
Bug: T308910
Change-Id: I452ecfd74145e2fc7beed56a5886555994995db2
---
M pwb.py
1 file changed, 6 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 3c46597..e7a35af 100755
--- a/pwb.py
+++ b/pwb.py
@@ -291,7 +291,7 @@
def find_alternates(filename, script_paths):
"""Search for similar filenames in the given script paths."""
- from pywikibot import config, input_choice, info
+ from pywikibot import config, input_choice, error, info, warning
from pywikibot.bot import QuitKeyboardInterrupt, ShowingListOption
assert config.pwb_close_matches > 0, \
@@ -299,14 +299,17 @@
assert 0.0 < config.pwb_cut_off < 1.0, \
'config.pwb_cut_off must be a float in range [0, 1]'
- print('ERROR: {} not found! Misspelling?'.format(filename),
- file=sys.stderr)
+ error('{} not found! Misspelling?'.format(filename))
scripts = {}
script_paths = [['.']] + script_paths # add current directory
for path in script_paths:
folder = Path(_pwb_dir).joinpath(*path)
+ if not folder.exists():
+ warning('{} does not exists; remove it from user_script_paths'
+ .format(folder))
+ continue
for script_name in folder.iterdir():
name, suffix = script_name.stem, script_name.suffix
if suffix == '.py' and not name.startswith('__'):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/794469
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: I452ecfd74145e2fc7beed56a5886555994995db2
Gerrit-Change-Number: 794469
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged