jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] i18n: Deprecate non-mapping parameters
......................................................................
[IMPROV] i18n: Deprecate non-mapping parameters
Not using mapping parameters should be avoided when the text contains multiple
of them, as they might change order. And for consistency also translations
with only one parameter should use a mapping.
Change-Id: I60b32e4e415ed151458a484911a0cb222e2ab9c5
---
M pywikibot/i18n.py
1 file changed, 11 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index ee2bb92..212906d 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -33,7 +33,7 @@
import os
import pkgutil
-from collections import defaultdict
+from collections import defaultdict, Mapping
import pywikibot
@@ -41,6 +41,7 @@
from pywikibot import Error
from pywikibot import config
from pywikibot.plural import plural_rules
+from pywikibot.tools import issue_deprecation_warning
if sys.version_info[0] > 2:
basestring = (str, )
@@ -448,6 +449,9 @@
if parameters is None:
return trans
+ if not isinstance(parameters, Mapping):
+ issue_deprecation_warning('parameters not being a mapping', None, 2)
+
# else we check for PLURAL variants
trans = _extract_plural(code, trans, parameters)
if parameters:
@@ -470,7 +474,8 @@
@param code: The language code
@param twtitle: The TranslateWiki string title, in <package>-<key> format
- @param parameters: For passing parameters.
+ @param parameters: For passing parameters. It should be a mapping but for
+ backwards compatibility can also be a list, tuple or a single value.
@param fallback: Try an alternate language code
@type fallback: boolean
"""
@@ -512,6 +517,10 @@
# send the language code back via the given list
if code_needed:
code.append(alt)
+
+ if parameters is not None and not isinstance(parameters, Mapping):
+ issue_deprecation_warning('parameters not being a Mapping', None, 2)
+
if parameters:
return trans % parameters
else:
--
To view, visit https://gerrit.wikimedia.org/r/244430
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I60b32e4e415ed151458a484911a0cb222e2ab9c5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Changes are wrongly detected in the last langlink
......................................................................
Changes are wrongly detected in the last langlink
This was first detected in cosmetic_changes.py, where pages not needing any
cosmetic changes were still being updated, and the supposed changed was an
unchanged langlink (the last one). Then I realized this also happens in
interwiki.py, but only when changes are supposed to be made to the page.
After checking textlib.py, I noticed that removeLanguageLinks() returns a
stripped version of the text whereas replaceLanguageLinks() does not. So
the actual difference is related to blank space.
This explains why cosmetic_changes.py detects a change and updates the page,
but interwiki.py does not: interwiki.py does not rely in differences in the
final text to make an update, but when it does need to make an update, it
outputs that diff.
This patch strips the text in replaceLanguageLinks() before returning if the
original text is stripped itself.
Conflicts:
pywikibot/textlib.py
Change-Id: Icd7252be8dbccf3fb04a4b4a465f6b057e3a8e3a
(manually cherry picked from 097245e7e34)
---
M pywikibot/textlib.py
1 file changed, 8 insertions(+), 2 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index b40aba4..42a9e62 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -31,7 +31,10 @@
from pywikibot import config2 as config
from pywikibot.family import Family
-from pywikibot.tools import OrderedDict
+from pywikibot.tools import (
+ OrderedDict,
+ issue_deprecation_warning
+)
# cache for replaceExcept to avoid recompile or regexes each call
_regex_cache = {}
@@ -595,6 +598,9 @@
cseparator = site.family.category_text_separator
separatorstripped = separator.strip()
cseparatorstripped = cseparator.strip()
+ do_not_strip = oldtext.strip() != oldtext
+ if do_not_strip:
+ issue_deprecation_warning('Using unstripped text', 'stripped text', 2)
if addOnly:
s2 = oldtext
else:
@@ -662,7 +668,7 @@
newtext = s2.replace(marker, '').strip() + separator + s
else:
newtext = s2.replace(marker, '')
- return newtext
+ return newtext if do_not_strip else newtext.strip()
def interwikiFormat(links, insite=None):
--
To view, visit https://gerrit.wikimedia.org/r/243514
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icd7252be8dbccf3fb04a4b4a465f6b057e3a8e3a
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: 2.0
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Malafaya <malafaya(a)clix.pt>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix interwikiFormat support for Link
......................................................................
Fix interwikiFormat support for Link
interwikiFormat is supposed to support a dictionary of Page or Link
objects. There were several merges of core and compat 'textlib' to
keep the two in sync, such as core's 8978bfb6, and the support for
Link was broken somewhere along the way.
Add tests for Link in addition to existing tests for Page.
Also add a ValueError exception if it contains any other type.
Conflicts:
pywikibot/textlib.py
tests/textlib_tests.py
Change-Id: Ibb39ea8b3079083feec93249eb6abe4b997feb74
(manually cherry picked from 64ffa4279fb1)
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 17 insertions(+), 5 deletions(-)
Approvals:
XZise: Looks good to me, approved
Merlijn van Deen: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index b40aba4..e08560d 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -686,14 +686,15 @@
ar = interwikiSort(list(links.keys()), insite)
s = []
for site in ar:
- try:
+ if isinstance(links[site], pywikibot.Link):
+ links[site] = pywikibot.Page(links[site])
+ if isinstance(links[site], pywikibot.Page):
title = links[site].title(asLink=True, forceInterwiki=True,
insite=insite)
link = title.replace('[[:', '[[')
s.append(link)
- except AttributeError:
- s.append(pywikibot.Site(site, insite.family).linkto(
- links[site], othersite=insite))
+ else:
+ raise ValueError('links dict must contain Page or Link objects')
if insite.lang in insite.family.interwiki_on_one_line:
sep = u' '
else:
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 468d3f2..e6821e3 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -90,7 +90,8 @@
cached = True
- def test_interwiki_format(self):
+ def test_interwiki_format_Page(self):
+ """Test formatting interwiki links using Page instances."""
interwikis = {
'de': pywikibot.Page(pywikibot.Link('de:German', self.site)),
'fr': pywikibot.Page(pywikibot.Link('fr:French', self.site))
@@ -99,6 +100,16 @@
% {'LS': config.LS},
textlib.interwikiFormat(interwikis, self.site))
+ def test_interwiki_format_Link(self):
+ """Test formatting interwiki links using Page instances."""
+ interwikis = {
+ 'de': pywikibot.Link('de:German', self.site),
+ 'fr': pywikibot.Link('fr:French', self.site),
+ }
+ self.assertEqual('[[de:German]]%(LS)s[[fr:French]]%(LS)s'
+ % {'LS': config.LS},
+ textlib.interwikiFormat(interwikis, self.site))
+
class TestFormatCategory(DefaultDrySiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/243510
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibb39ea8b3079083feec93249eb6abe4b997feb74
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: 2.0
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Disable pep257 D211
......................................................................
Disable pep257 D211
D211 will be introduced in pep257 0.6.1, and requires removing
a blank line from the top of all classes.
As 0.6.0 would complain about the extra line, disable this rule
until 0.6.1 is widely accepted and installed by our team.
Change-Id: I4f7d3291eac7d1f5d1b431fb5eaaf9ecbe11b510
---
M tox.ini
1 file changed, 4 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tox.ini b/tox.ini
index a46ddf2..33d93fe 100644
--- a/tox.ini
+++ b/tox.ini
@@ -235,7 +235,7 @@
-rdocs/requirements-py3.txt
[flake8]
-ignore = E241,E402,E731,FI10,FI12,FI13,FI15,FI5,H101,H201,H202,H236,H237,H301,H306,H404,H405,H501,P102,P103
+ignore = E241,E402,E731,D211,FI10,FI12,FI13,FI15,FI5,H101,H201,H202,H236,H237,H301,H306,H404,H405,H501,P102,P103
exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/*
max_line_length = 130
accept-encodings = utf-8
@@ -245,3 +245,6 @@
ignore = E241,E402,E731
exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/*
max_line_length = 130
+
+[pep257]
+ignore = D211
--
To view, visit https://gerrit.wikimedia.org/r/243867
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4f7d3291eac7d1f5d1b431fb5eaaf9ecbe11b510
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>