jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/667626 )
Change subject: [IMPR] Prepare scripts to be derived from specialbot/_disambig ......................................................................
[IMPR] Prepare scripts to be derived from specialbot/_disambig
Change-Id: Ifb8153e6d745a573343718375b314ba13eaecf58 --- M scripts/misspelling.py M scripts/solve_disambiguation.py M tox.ini 3 files changed, 23 insertions(+), 30 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/misspelling.py b/scripts/misspelling.py index 91d7ef1..cefb7f8 100755 --- a/scripts/misspelling.py +++ b/scripts/misspelling.py @@ -12,15 +12,16 @@ some choices for XY don't make sense and will result in a loop, e.g. "l" or "m".
+ -main only check pages in the main namespace, not in the talk, + wikipedia, user, etc. namespaces. + -start:XY goes through all misspellings in the category on your wiki that is defined (to the bot) as the category containing misspelling pages, starting at XY. If the -start argument is not given, it starts at the beginning. - - -main only check pages in the main namespace, not in the talk, - wikipedia, user, etc. namespaces. """ -# (C) Pywikibot team, 2007-2020 +# +# (C) Pywikibot team, 2007-2021 # # Distributed under the terms of the MIT license. # @@ -33,7 +34,7 @@ from pywikibot.bot import SingleSiteBot from pywikibot.tools.formatter import color_format
-from scripts.solve_disambiguation import DisambiguationRobot as DisambigBotBase +from scripts.solve_disambiguation import DisambiguationRobot as BaseDisambigBot
HELP_MSG = """\n misspelling.py does not support site {site}. @@ -45,7 +46,7 @@ these misspellings.\n"""
-class MisspellingRobot(DisambigBotBase): +class MisspellingRobot(BaseDisambigBot):
"""Spelling bot."""
@@ -112,15 +113,13 @@ pywikibot.output(HELP_MSG.format(site=self.site)) return
- generator = chain(*generators) - preloadingGen = pagegenerators.PreloadingGenerator(generator) - yield from preloadingGen + yield from pagegenerators.PreloadingGenerator(chain(*generators))
def findAlternatives(self, page) -> bool: """ Append link target to a list of alternative links.
- Overrides the DisambigBotBase method. + Overrides the BaseDisambigBot method.
@return: True if alternate link was appended """ @@ -157,11 +156,11 @@ """ Setup the summary message.
- Overrides the DisambiguationRobot method. + Overrides the BaseDisambigBot method. """ # TODO: setSummaryMessage() in solve_disambiguation now has parameters # new_targets and unlink. Make use of these here. - self.comment = i18n.twtranslate(self.site, 'misspelling-fixing', + self.summary = i18n.twtranslate(self.site, 'misspelling-fixing', {'page': page.title()})
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index 2c3c7b4..b8bc74d 100755 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -98,7 +98,6 @@ from pywikibot.tools import first_lower, first_upper from pywikibot.tools.formatter import SequenceOutputter
- # Disambiguation Needed template dn_template = { 'ar': '{{بحاجة لتوضيح}}', @@ -471,7 +470,7 @@ if line: self.ignorelist.add(line)
- def isIgnored(self, ref_page) -> bool: + def isIgnored(self, ref_page) -> bool: # noqa: N802 """Return if ref_page is to be ignored.
@type ref_page: pywikibot.Page @@ -576,7 +575,7 @@
class DisambiguationRobot(SingleSiteBot):
- """Disambiguation bot.""" + """Disambiguation Bot."""
ignore_contents = { 'de': ('{{[Ii]nuse}}', @@ -617,15 +616,13 @@ self.first_only = first_only self.minimum = minimum self.summary = None - self.dn_template_str = i18n.translate(self.site, dn_template)
- def checkContents(self, text) -> Optional[str]: + def checkContents(self, text: str) -> Optional[str]: # noqa: N802 """ Check if the text matches any of the ignore regexes.
@param text: wikitext of a page - @type text: str @return: None if none of the regular expressions given in the dictionary at the top of this class matches a substring of the text, otherwise the matched substring @@ -636,17 +633,14 @@ return match.group() return None
- def makeAlternativesUnique(self) -> None: + def makeAlternativesUnique(self) -> None: # noqa: N802 """Remove duplicate items from self.alternatives.
Preserve the order of alternatives. - @rtype: None - """ seen = set() - self.alternatives = [ - i for i in self.alternatives if i not in seen and not seen.add(i) - ] + self.alternatives = [i for i in self.alternatives + if i not in seen and not seen.add(i)]
def setup(self) -> None: """Compile regular expressions.""" @@ -1025,7 +1019,7 @@
return 'done'
- def findAlternatives(self, page) -> bool: + def findAlternatives(self, page) -> bool: # noqa: N802 """Extend self.alternatives using correctcap of disambPage.linkedPages.
@param page: the disambiguation page @@ -1266,9 +1260,9 @@ if page.exists(): alternatives.append(page.title()) elif pywikibot.input_yn( - 'Possibility {0} does not actually exist. Use it anyway?' - .format(page.title()), - default=False, automatic_quit=False): + 'Possibility {} does not actually exist. Use it anyway?' + .format(page.title()), default=False, + automatic_quit=False): alternatives.append(page.title()) elif arg == '-just': getAlternatives = False diff --git a/tox.ini b/tox.ini index 8fbb637..fb963f5 100644 --- a/tox.ini +++ b/tox.ini @@ -170,14 +170,14 @@ scripts/imagetransfer.py : N803, N806, N816 scripts/maintenance/* : T001 scripts/maintenance/download_dump.py : N815 - scripts/misspelling.py : N802, N803, N806, N815 + scripts/misspelling.py : N802, N806 scripts/movepages.py : N803, N806, N802 scripts/noreferences.py : N802, N803, N806, N816 scripts/pagefromfile.py : N815 scripts/redirect.py : N803, N806, N815 scripts/replace.py : N802, N803, N806, N816 scripts/revertbot.py: N815 - scripts/solve_disambiguation.py : N803, N806, N802 + scripts/solve_disambiguation.py : N802, N803, N806 scripts/templatecount.py: N802 scripts/weblinkchecker.py : N803, N806, N802 scripts/welcome.py: N802, N815
pywikibot-commits@lists.wikimedia.org