jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/347308 )
Change subject: Fix spelling mistake
......................................................................
Fix spelling mistake
Also keep next line beneath 80 chars.
Change-Id: I8894eb8a5129f7b99e8ad610252d189a4aea5fbd
---
M pywikibot/proofreadpage.py
1 file changed, 3 insertions(+), 2 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index 4034cb5..47bf1ab 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -473,8 +473,9 @@
and relative page numbers and labels by means of several helper
functions.
- It also providesa generator to pages contained in Index page, with
- possibility to define range, filter by quality levels and page existance.
+ It also provides a generator to pages contained in Index page, with
+ possibility to define range, filter by quality levels and page
+ existence.
@raise UnknownExtension: source Site has no ProofreadPage Extension.
@raise ImportError: bs4 is not installed.
--
To view, visit https://gerrit.wikimedia.org/r/347308
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8894eb8a5129f7b99e8ad610252d189a4aea5fbd
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/347336 )
Change subject: Only require that all encuntered data types are known
......................................................................
Only require that all encuntered data types are known
This changes the requirements of the test to require that all
encountered data types are known but not that all known data types
are encountered.
Note that test_datatypes is still expected to fail until T161726
is resolved, BUT it should no longer fail afterwards.
Bug: T160339
Change-Id: I6e1e4cf0194dc786c845c50a5d7b3fe651c6dce8
---
M tests/paraminfo_tests.py
1 file changed, 10 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/paraminfo_tests.py b/tests/paraminfo_tests.py
index 2899314..f1162f7 100644
--- a/tests/paraminfo_tests.py
+++ b/tests/paraminfo_tests.py
@@ -41,14 +41,19 @@
return param['type']
def _check_param_values(self, site, module, parameter, expected):
- """Perform check that a parameter matches the expected list."""
+ """Check that a parameter matches the expected list exactly."""
values = self._get_param_values(site, module, parameter)
self.assertCountEqual(expected, values)
def _check_param_subset(self, site, module, parameter, expected):
- """Perform check that a parameter matches the expected list."""
+ """Check that a parameter contains all entries in expected list."""
values = self._get_param_values(site, module, parameter)
self.assertLessEqual(set(expected), set(values))
+
+ def _check_param_superset(self, site, module, parameter, expected):
+ """Check that a parameter only contains entries in expected list."""
+ values = self._get_param_values(site, module, parameter)
+ self.assertGreaterEqual(set(expected), set(values))
class MediaWikiKnownTypesTestCase(KnownTypesTestBase,
@@ -226,10 +231,11 @@
self._check_param_values(self.repo, 'wbsearchentities', 'type', known)
def test_datatypes(self):
- """Test known datatypes."""
+ """Test that all encountered datatypes are known."""
unsupported = set(['wikibase-property'])
known = set(Property.types) | unsupported
- self._check_param_values(self.repo, 'wbformatvalue', 'datatype', known)
+ self._check_param_superset(
+ self.repo, 'wbformatvalue', 'datatype', known)
def test_snaktype(self):
"""Test known snak types."""
--
To view, visit https://gerrit.wikimedia.org/r/347336
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6e1e4cf0194dc786c845c50a5d7b3fe651c6dce8
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/258684 )
Change subject: Add async parameter to ItemPage.editEntity
......................................................................
Add async parameter to ItemPage.editEntity
'asynchronous' parameter enables ItemPage.editEntity to edit an entity
asynchronously, which can be used in Wikidata bots.
TODO:
- needs better exception handling? (T86083)
- new callback argument, just like in BasePage.save()
Bug: T86074
Change-Id: I1ffa92b8710e91b7095b24808c151ff9d0a592cf
---
M pywikibot/bot.py
M pywikibot/page.py
2 files changed, 8 insertions(+), 2 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 80905bf..9a24644 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1866,7 +1866,6 @@
if 'summary' in kwargs:
pywikibot.output(u'Change summary: %s' % kwargs['summary'])
- # TODO async in editEntity should actually have some effect (bug T86074)
# TODO PageSaveRelatedErrors should be actually raised in editEntity
# (bug T86083)
self._save_page(item, item.editEntity, data, **kwargs)
diff --git a/pywikibot/page.py b/pywikibot/page.py
index dc34774..a1540f4 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3541,7 +3541,7 @@
return site.dbName()
return site
- def editEntity(self, data=None, **kwargs):
+ def editEntity(self, data=None, asynchronous=False, **kwargs):
"""
Edit an entity using Wikibase wbeditentity API.
@@ -3553,7 +3553,14 @@
@param data: Data to be saved
@type data: dict, or None to save the current content of the entity.
+ @param asynchronous: if True, launch a separate thread to edit
+ asynchronously
+ @type asynchronous: bool
"""
+ if asynchronous:
+ pywikibot.async_request(self.editEntity, data, **kwargs)
+ return
+
if hasattr(self, '_revid'):
baserevid = self.latest_revision_id
else:
--
To view, visit https://gerrit.wikimedia.org/r/258684
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1ffa92b8710e91b7095b24808c151ff9d0a592cf
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Vadiraja.k <vadi.fedx(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <Ladsgroup(a)gmail.com>
Gerrit-Reviewer: M4tx <m4tx(a)m4tx.pl>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: MarcoAurelio <strigiwm(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/332333 )
Change subject: [IMPR] Polish WikidataBot.user_edit_entity
......................................................................
[IMPR] Polish WikidataBot.user_edit_entity
- Fix accessing WikibasePage.
- Make the method return bool, just like BaseBot._save_page does.
- Do not automatically set current_item, this shows ugly "-1" for new
items.
Bug: T87493
Change-Id: I91bf76085ce19bf191dcdbab73b2fb7c1b5bfac4
---
M pywikibot/bot.py
1 file changed, 5 insertions(+), 5 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 82f24ef..f35a785 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1313,7 +1313,7 @@
@rtype: bool
"""
if not self.user_confirm('Do you want to accept these changes?'):
- return
+ return False
if 'async' not in kwargs and self.getOption('always'):
kwargs['async'] = True
@@ -1871,16 +1871,16 @@
@kwarg ignore_save_related_errors: if True, errors related to
page save will be reported and ignored (default: False)
@type ignore_save_related_errors: bool
+ @return: whether the item was saved successfully
+ @rtype: bool
"""
- self.current_page = item
-
show_diff = kwargs.pop('show_diff', True)
if show_diff:
if data is None:
diff = item.toJSON(diffto=(
item._content if hasattr(item, '_content') else None))
else:
- diff = pywikibot.WikibasePage._normalizeData(data)
+ diff = pywikibot.page.WikibasePage._normalizeData(data)
pywikibot.output(json.dumps(diff, indent=4, sort_keys=True))
if 'summary' in kwargs:
@@ -1889,7 +1889,7 @@
# TODO async in editEntity should actually have some effect (bug T86074)
# TODO PageSaveRelatedErrors should be actually raised in editEntity
# (bug T86083)
- self._save_page(item, item.editEntity, data, **kwargs)
+ return self._save_page(item, item.editEntity, data, **kwargs)
def getSource(self, site):
"""
--
To view, visit https://gerrit.wikimedia.org/r/332333
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I91bf76085ce19bf191dcdbab73b2fb7c1b5bfac4
Gerrit-PatchSet: 9
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/319857 )
Change subject: Make sparql use Site to access sparql endpoint and entity_url
......................................................................
Make sparql use Site to access sparql endpoint and entity_url
Introduces a repo parameter which takes any DataSite and gets
its sparql endpoint and entity_url. Still supports explicit
endpoint and entity_url for full flexibility.
As before this defaults to Wikidata but now relies on its Site
object rather than hard-coded endpoint and entity_url.
The same change is implemented in pagegenerators.
Note that this change is breaking for anyone who had overridden
endpoint but not entity_url (i.e. running their own endpoint but
loaded with wikidata data). This was an undocumented feature and
these users will now recieve an Error.
Bug: T159956
Change-Id: I057335a56398a7d5f6c8c811233a002228b73093
---
M pywikibot/data/sparql.py
M pywikibot/pagegenerators.py
M pywikibot/site.py
M tests/sparql_tests.py
4 files changed, 64 insertions(+), 15 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/data/sparql.py b/pywikibot/data/sparql.py
index e95c916..b577bb0 100644
--- a/pywikibot/data/sparql.py
+++ b/pywikibot/data/sparql.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""SPARQL Query interface."""
#
+# (C) Pywikibot team, 2016-2017
+#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals
@@ -12,10 +14,10 @@
else:
from urllib2 import quote
+from pywikibot import Site, Error
from pywikibot.comms import http
from pywikibot.tools import UnicodeMixin, py2_encode_utf_8
-WIKIDATA = 'http://query.wikidata.org/sparql'
DEFAULT_HEADERS = {'cache-control': 'no-cache',
'Accept': 'application/sparql-results+json'}
@@ -27,15 +29,44 @@
This class allows to run SPARQL queries against any SPARQL endpoint.
"""
- def __init__(self, endpoint=WIKIDATA, entity_url='http://www.wikidata.org/entity/'):
+ def __init__(self, endpoint=None, entity_url=None, repo=None):
"""
Create endpoint.
- @param endpoint: SPARQL endpoint URL, by default Wikidata query endpoint
+ @param endpoint: SPARQL endpoint URL
+ @type endpoint: string
+ @param entity_url: URL prefix for any entities returned in a query.
+ @type entity_url: string
+ @param repo: The Wikibase site which we want to run queries on. If
+ provided this overrides any value in endpoint and entity_url.
+ Defaults to Wikidata.
+ @type repo: pywikibot.site.DataSite
"""
- self.endpoint = endpoint
+ # default to Wikidata
+ if not repo and not endpoint:
+ repo = Site('wikidata', 'wikidata')
+
+ if repo:
+ try:
+ self.endpoint = repo.sparql_endpoint
+ self.entity_url = repo.concept_base_uri
+ except NotImplementedError:
+ raise NotImplementedError(
+ 'Wiki version must be 1.28-wmf.23 or newer to '
+ 'automatically extract the sparql endpoint. '
+ 'Please provide the endpoint and entity_url '
+ 'parameters instead of a repo.')
+ if not self.endpoint:
+ raise Error('The site {0} does not provide a sparql endpoint.'
+ .format(repo))
+ else:
+ if not entity_url:
+ raise Error('If initialised with an endpoint the entity_url '
+ 'must be provided.')
+ self.endpoint = endpoint
+ self.entity_url = entity_url
+
self.last_response = None
- self.entity_url = entity_url
def get_last_response(self):
"""
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 61dacdb..1152def 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -40,13 +40,13 @@
from pywikibot.tools import (
deprecated,
deprecated_args,
- redirect_func,
- issue_deprecation_warning,
- itergroup,
DequeGenerator,
- intersect_generators,
- IteratorNextMixin,
filter_unique,
+ intersect_generators,
+ issue_deprecation_warning,
+ IteratorNextMixin,
+ itergroup,
+ redirect_func,
)
from pywikibot import date, config, i18n, xmlreader
@@ -2727,7 +2727,16 @@
site = pywikibot.Site()
repo = site.data_repository()
if endpoint is None:
- endpoint = sparql.WIKIDATA
+ try:
+ endpoint = repo.sparql_endpoint
+ except NotImplementedError:
+ raise NotImplementedError(
+ 'Wiki version must be 1.28-wmf.23 or newer to automatically '
+ 'extract the sparql endpoint. Please provide the endpoint '
+ 'parameter as well.')
+ if not endpoint:
+ pywikibot.error('The site {0} does not provide a sparql endpoint.'
+ .format(repo))
query_object = sparql.SparqlQuery(endpoint=endpoint)
data = query_object.get_items(query,
diff --git a/pywikibot/site.py b/pywikibot/site.py
index f2724d9..5da6345 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -7057,6 +7057,17 @@
% self)
@property
+ @need_version("1.28-wmf.3")
+ def sparql_endpoint(self):
+ """
+ Return the sparql endpoint url, if any has been set.
+
+ @return: sparql endpoint url
+ @rtype: str|None
+ """
+ return self.siteinfo['general'].get('wikibase-sparql')
+
+ @property
@need_version("1.28-wmf.23")
def concept_base_uri(self):
"""
diff --git a/tests/sparql_tests.py b/tests/sparql_tests.py
index 02c76d6..c392d57 100644
--- a/tests/sparql_tests.py
+++ b/tests/sparql_tests.py
@@ -12,7 +12,7 @@
import pywikibot.data.sparql as sparql
from pywikibot.tools import UnicodeType
-from tests.aspects import unittest, TestCase
+from tests.aspects import unittest, TestCase, WikidataTestCase
if sys.version_info[0] > 2:
from unittest.mock import patch
@@ -95,10 +95,8 @@
self.content = value
-class TestSparql(TestCase):
+class TestSparql(WikidataTestCase):
"""Test SPARQL queries."""
-
- net = False
@patch.object(sparql.http, 'fetch')
def testQuerySelect(self, mock_method):
--
To view, visit https://gerrit.wikimedia.org/r/319857
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I057335a56398a7d5f6c8c811233a002228b73093
Gerrit-PatchSet: 11
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <Ladsgroup(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Smalyshev <smalyshev(a)wikimedia.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/338631 )
Change subject: [Bug] Create attributes when item is being preloaded
......................................................................
[Bug] Create attributes when item is being preloaded
Attributes like labels or claims are only created inside ItemPage.get().
Change-Id: Iec24389546725dd8142374ee755fedea7284fee3
---
M pywikibot/site.py
1 file changed, 2 insertions(+), 0 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/site.py b/pywikibot/site.py
index bdf1fb4..7c453fa 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -7231,6 +7231,8 @@
for qid in data['entities']:
item = pywikibot.ItemPage(self, qid)
item._content = data['entities'][qid]
+ # No api call is made because item._content is given
+ item.get(get_redirect=True)
yield item
def getPropertyType(self, prop):
--
To view, visit https://gerrit.wikimedia.org/r/338631
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iec24389546725dd8142374ee755fedea7284fee3
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>