jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/523949 )
Change subject: fix(APISite.fromDBName): work for all known dbnames
......................................................................
fix(APISite.fromDBName): work for all known dbnames
APISite.fromDBName used to use `APISite(sitecode, sitecode)` for
instantiating special sites. But some of those sites, like test2wiki,
cannot be instantiated this way because pywikibot does not have any
family with that code (test2).
APISite.fromDBName:
* Use pywikibot.Site(url=...)
Family.from_url:
* Include test codes when searching for a domain.
wikidata_family.py and test_family.py:
* Remove test_codes attribute. Otherwise Family.from_url will end up
with duplicate codes in Family.from_url and raises
RuntimeError('Found multiple matches for URL ...').
I found two issues with this patch:
>> Site('test', 'wikipedia') ==
Site('test', 'test') # should be True
False
>> Site().fromDBName('testwiki') #
should not warn
WARNING: Found multiple matches for URL \
"https://test.wikipedia.org/w/index.php": \
('test', Family("test")), ('test',
Family("wikipedia")) (use first)
APISite("test", "test")
Note that the first issue is not introduced by this patch (
it already exists on master).
The cause of the mentioned issues is that we have two separate family
files that contain the same site. IOW,
test.wikipeida.org is defined
both in test_family.py and in wikipedia_family.py. It should be removed
from one of them, but that sounds like a big breaking change and requires
a deprecation period. This patch is not going to get into that matter.
Bug: T225590
Bug: T225723
Bug: T226960
Change-Id: I42c7f34abd42c3eced06f1332177f3f7b91b0c40
---
M pywikibot/families/test_family.py
M pywikibot/families/wikidata_family.py
M pywikibot/family.py
M pywikibot/site.py
4 files changed, 4 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/families/test_family.py b/pywikibot/families/test_family.py
index c2cc2f4..0e89716 100644
--- a/pywikibot/families/test_family.py
+++ b/pywikibot/families/test_family.py
@@ -17,7 +17,4 @@
name = 'test'
domain = 'test.wikipedia.org'
-
- test_codes = ('test', )
-
interwiki_forward = 'wikipedia'
diff --git a/pywikibot/families/wikidata_family.py
b/pywikibot/families/wikidata_family.py
index fe11d15..e8012c4 100644
--- a/pywikibot/families/wikidata_family.py
+++ b/pywikibot/families/wikidata_family.py
@@ -17,7 +17,6 @@
"""Family class for Wikidata."""
name = 'wikidata'
- test_codes = ('test', 'beta')
langs = {
'wikidata': 'www.wikidata.org',
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 77904e2..b0be37b 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -9,6 +9,7 @@
import collections
from importlib import import_module
+from itertools import chain
import logging
from os.path import basename, dirname, splitext
import re
@@ -1315,7 +1316,7 @@
else:
domain = False
if domain is not False:
- for code in self.codes:
+ for code in chain(self.codes, getattr(self, 'test_codes', ())):
if code in ignored:
continue
if self._hostname(code)[1] == parsed.netloc:
diff --git a/pywikibot/site.py b/pywikibot/site.py
index ee2c84c..bef3935 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1886,10 +1886,10 @@
if site['code'] == 'wiki':
site['code'] = 'wikipedia'
return cls(lang, site['code'])
- else:
+ else: # key == 'specials'
for site in val:
if site['dbname'] == dbname:
- return cls(site['code'], site['code'])
+ return pywikibot.Site(url=site['url'] +
'/w/index.php')
raise ValueError('Cannot parse a site out of %s.' % dbname)
@deprecated(since='20141225')
--
To view, visit
https://gerrit.wikimedia.org/r/523949
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I42c7f34abd42c3eced06f1332177f3f7b91b0c40
Gerrit-Change-Number: 523949
Gerrit-PatchSet: 3
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)