jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/609568 )
Change subject: [doc] Update ROADMAP.rst
......................................................................
[doc] Update ROADMAP.rst
Also fix version strings
Change-Id: Ie5f0b9ccfce174fa9a2a6a0248ebef67b5feba5b
---
M ROADMAP.rst
1 file changed, 8 insertions(+), 5 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index f33490c..27af648 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,16 +1,19 @@
Current release
~~~~~~~~~~~~~~~
+* Use one central point for framework version (T106121, T171886, T197936, T253719)
+* rvtoken parameter of Site.loadrevisions() and Page.revisions() has been dropped (T74763)
+* getFilesFromAnHash and getImagesFromAnHash Site methods have been removed
+* Site and Page methods deprecated for 10 years or longer have been removed
* Support for Python 2 and 3.4 has been dropped (T213287, T239542)
Future releases
~~~~~~~~~~~~~~~
-* 3.0.30300703: Unsupported debug parameter of UploadRobot will be removed
-* 3.0.30300703: Unported compat decode parameter of Page.title() will be removed
-* 3.0.30300703: tools.count, tools.Counter, tools.OrderedDict and ContextManagerWrapper will be removed
-* 3.0.30300703: getFilesFromAnHash and getImagesFromAnHash Site methods will be removed
+* (current): Methods deprecated for 8 years or longer will be removed
+* 3.0.20200703: Unsupported debug parameter of UploadRobot will be removed
+* 3.0.20200703: Unported compat decode parameter of Page.title() will be removed
+* 3.0.20200703: tools.count, tools.Counter, tools.OrderedDict and ContextManagerWrapper will be removed
* 3.0.20200508: Page.getVersionHistory and Page.fullVersionHistory() methods will be removed (T136513, T151110)
-* 3.0.20200405: Site and Page methods deprecated for 10 years or longer will be removed
* 3.0.20200326: Functions dealing with stars list will be removed
* 3.0.20200306: Support of MediaWiki releases below 1.19 will be dropped (T245350)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/609568
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: Ie5f0b9ccfce174fa9a2a6a0248ebef67b5feba5b
Gerrit-Change-Number: 609568
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/409823 )
Change subject: [IMPR] Use one central point for framework version
......................................................................
[IMPR] Use one central point for framework version
Use one central point for framework version and other meta datas.
Enable PEP440 versioning and also follow PEP396 when deriving
version for setup.
Start with 4.0.0 as the current version which is Python 3.5+ only
- All meta data are placed within pywikibot/__metadata__.py.
This enables setup.py to fetch metadata without importing pywikibot itself.
- Start with 4.0.0 as the next release number. Increase the minor release
number if there are other changes than just bugfixes and L10N/i18n.
- Use __metadata__ in setup.py
- explain submitting a new release to pypi in setup.__doc__
Bug: T106121
Bug: T171886
Bug: T197936
Bug: T253719
Change-Id: I7ffe9096fece8c15e770b5fe25d3ac29410924af
---
M docs/conf.py
M pywikibot/CONTENT.rst
M pywikibot/__init__.py
A pywikibot/__metadata__.py
M setup.py
M tests/utils.py
6 files changed, 140 insertions(+), 37 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/conf.py b/docs/conf.py
index 4b42f93..3c4077b 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -64,8 +64,8 @@
master_doc = 'index'
# General information about the project.
-project = 'Pywikibot'
-copyright = '2003-2020, Pywikibot team'
+project = pywikibot.__name__.title()
+copyright = pywikibot.__copyright__
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
diff --git a/pywikibot/CONTENT.rst b/pywikibot/CONTENT.rst
index 883d6e3..3f606e8 100644
--- a/pywikibot/CONTENT.rst
+++ b/pywikibot/CONTENT.rst
@@ -7,6 +7,8 @@
| __init__.py | Initialization of the pywikibot framework, |
| | basic classes and methods |
+----------------------------+------------------------------------------------------+
+ | __metadata__.py | pywikibot framework metadata file |
+ +----------------------------+------------------------------------------------------+
| _wbtypes.py | Wikibase data type classes |
+----------------------------+------------------------------------------------------+
| bot.py | User-interface related functions for building bots |
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 8bd01df..cbd8352 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -7,9 +7,6 @@
#
from __future__ import absolute_import, division, unicode_literals
-__version__ = __release__ = '4.0.dev0'
-__url__ = 'https://www.mediawiki.org/wiki/Manual:Pywikibot'
-
import atexit
import datetime
from decimal import Decimal
@@ -21,6 +18,12 @@
from warnings import warn
+from pywikibot.__metadata__ import (
+ __copyright__, __description__, __download_url__, __license__,
+ __maintainer__, __maintainer_email__, __name__, __url__, __version__)
+
+__release__ = __version__ # backward compatibility
+
from pywikibot._wbtypes import WbRepresentation as _WbRepresentation
from pywikibot.bot import (
input, input_choice, input_yn, inputChoice, handle_args, showHelp, ui,
@@ -89,6 +92,9 @@
)
__all__ = (
+ '__copyright__', '__description__', '__download_url__', '__license__',
+ '__maintainer__', '__maintainer_email__', '__name__', '__release__',
+ '__url__', '__version__',
'BadTitle', 'Bot', 'calledModuleName', 'CaptchaError', 'CascadeLockedPage',
'Category', 'CircularRedirect', 'Claim', 'config',
'CoordinateGlobeUnknownException', 'critical', 'CurrentPageBot', 'debug',
diff --git a/pywikibot/__metadata__.py b/pywikibot/__metadata__.py
new file mode 100644
index 0000000..468a3fb
--- /dev/null
+++ b/pywikibot/__metadata__.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+"""Pywikibot metadata file."""
+#
+# (C) Pywikibot team, 2020
+#
+# Distributed under the terms of the MIT license.
+#
+from __future__ import unicode_literals
+
+__name__ = 'pywikibot'
+__version__ = '4.0.0.dev0'
+__description__ = 'Python MediaWiki Bot Framework'
+__maintainer__ = 'The Pywikibot team'
+__maintainer_email__ = 'pywikibot(a)lists.wikimedia.org'
+__license__ = 'MIT License'
+__url__ = 'https://www.mediawiki.org/wiki/Manual:Pywikibot'
+__download_url__ = 'https://tools.wmflabs.org/pywikibot/'
+__copyright__ = '(C) Pywikibot team, 2003-2020'
+__keywords__ = 'API bot client framework mediawiki pwb python pywiki ' \
+ 'pywikibase pywikibot pywikipedia pywikipediabot wiki ' \
+ 'wikibase wikidata wikimedia wikipedia'
diff --git a/setup.py b/setup.py
index ca96d76..fe41208 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,28 @@
# -*- coding: utf-8 -*-
-"""Installer script for Pywikibot framework."""
+"""Installer script for Pywikibot framework.
+
+To create a new distribution:
+-----------------------------
+
+- replace the developmental version string in ``pywikibot.__metadata.py``
+ by the corresponing final release
+- create the package with::
+
+ python setup.py sdist
+
+- push the change to gerrit and merge it to the repository
+- upload the package to pypy by::
+
+ twine upload dist/*
+
+- create a new tag with the version number of the final release
+- move the existing 'stable' tag to that new tag
+- delete 'stable' tag in gerrit to be overridden later
+- synchronize the local tags with the remote repositoy
+- prepare the next release by increasing the version number in
+ ``pywikibot.__metadata.py`` and adding developmental identifier
+- upload this patchset to gerrit and merge it.
+"""
#
# (C) Pywikibot team, 2009-2020
#
@@ -8,6 +31,7 @@
import os
import sys
+from pkg_resources import parse_version, safe_version
from setuptools import setup
PYTHON_VERSION = sys.version_info[:3]
@@ -117,32 +141,80 @@
test_deps += ['six']
-def get_version(name):
- """Get a valid pywikibot module version string.
+class _DottedDict(dict):
+ __getattr__ = dict.__getitem__
- Either create a timebased version number for the package
- or read the version number from the package.
+
+# import metadata
+metadata = _DottedDict()
+name = 'pywikibot'
+path = os.path.abspath(os.path.dirname(__file__))
+with open(os.path.join(path, name, '__metadata__.py')) as f:
+ exec(f.read(), metadata)
+assert metadata.__name__ == name
+
+
+def get_validated_version():
+ """Get a validated pywikibot module version string.
+
+ The version number from pywikibot.__metadata__.__version__ is used.
+ setup.py with 'sdist' option is used to create a new source distribution.
+ In that case the version number is validated: Read tags from git.
+ Verify that the new release is higher than the last repository tag
+ and is not a developmental release.
@return: pywikibot module version string
@rtype: str
"""
- version = '4.0'
+ version = metadata.__version__
+ if 'sdist' not in sys.argv:
+ return version
+
+ if PY2:
+ raise RuntimeError(
+ 'A new distribution cannot be created with Python {}'
+ .format(sys.version.split(None, 1)[0]))
+
+ # validate version for sdist
+ from contextlib import suppress
+ from subprocess import run, PIPE
try:
- import subprocess
- date = subprocess.check_output(
- ['git', 'log', '-1', '--format=%ci']).strip()
- date = date.decode().split(' ', 1)[0].replace('-', '')
- version += '.' + date
- if 'sdist' not in sys.argv:
- version += '.dev0'
+ tags = run(['git', 'tag'], check=True, stdout=PIPE,
+ universal_newlines=True).stdout.splitlines()
except Exception as e:
print(e)
- from pkg_resources import get_distribution, DistributionNotFound
- try:
- version = get_distribution(name).version
- except DistributionNotFound as e:
- print(e)
- version += '.dev0'
+ sys.exit('Creating source distribution canceled.')
+
+ for tag in ('stable', 'python2'):
+ with suppress(ValueError):
+ tags.remove(tag)
+
+ last_tag = tags[-1]
+
+ warnings = []
+ if 'dev' in version:
+ warnings.append('Distribution must not be a developmental release.')
+
+ if parse_version(version) < parse_version('0'):
+ # any version which is not a valid PEP 440 version will be considered
+ # less than any valid PEP 440 version
+ warnings.append(
+ version + ' is not a valid version string following PEP 440.')
+ elif safe_version(version) != version:
+ warnings.append(
+ '{} does not follow PEP 440. Use {} as version string instead.'
+ .format(version, safe_version(version)))
+
+ if parse_version(version) <= parse_version(last_tag):
+ warnings.append(
+ 'New version "{}" is not higher than last version "{}".'
+ .format(version, last_tag))
+
+ if warnings:
+ print(__doc__)
+ print('\n\n'.join(warnings))
+ sys.exit('\nBuild of distribution package canceled.')
+
return version
@@ -176,24 +248,22 @@
def main():
"""Setup entry point."""
- name = 'pywikibot'
+ version = get_validated_version()
setup(
- name=name,
- version=get_version(name),
- description='Python MediaWiki Bot Framework',
+ name=metadata.__name__,
+ version=version,
+ description=metadata.__description__,
long_description=read_desc('README.rst'),
- keywords=['API', 'bot', 'framework', 'mediawiki', 'pwb', 'python',
- 'pywikibot', 'pywikipedia', 'pywikipediabot', 'wiki',
- 'wikimedia', 'wikipedia'],
- maintainer='The Pywikibot team',
- maintainer_email='pywikibot(a)lists.wikimedia.org',
- license='MIT License',
+ keywords=metadata.__keywords__.split(),
+ maintainer=metadata.__maintainer__,
+ maintainer_email=metadata.__maintainer_email__,
+ license=metadata.__license__,
packages=get_packages(name),
python_requires='>=3.5.0',
install_requires=dependencies,
extras_require=extra_deps,
- url='https://www.mediawiki.org/wiki/Manual:Pywikibot',
- download_url='https://tools.wmflabs.org/pywikibot/',
+ url=metadata.__url__,
+ download_url=metadata.__download_url__,
test_suite='tests.collector',
tests_require=test_deps,
classifiers=[
@@ -217,6 +287,10 @@
use_2to3=False
)
+ # Finally show distribution version before uploading
+ if 'sdist' in sys.argv:
+ print('\nDistribution package created for version {}'.format(version))
+
if __name__ == '__main__':
main()
diff --git a/tests/utils.py b/tests/utils.py
index 8571d6c..8686e90 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -601,7 +601,7 @@
@type command: list of unicode
"""
if PY2 or PYTHON_VERSION < (3, 5, 0):
- command.insert(1, '-W ignore::FutureWarning:pywikibot:125')
+ command.insert(1, '-W ignore::FutureWarning:pywikibot:131')
if cryptography_version and cryptography_version < [1, 3, 4]:
command.insert(1, '-W ignore:Old version of cryptography:Warning')
# Any environment variables added on Windows must be of type
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/409823
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: I7ffe9096fece8c15e770b5fe25d3ac29410924af
Gerrit-Change-Number: 409823
Gerrit-PatchSet: 58
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: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: DannyS712 <DannyS712.enwiki(a)gmail.com>
Gerrit-CC: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606313 )
Change subject: [cleanup] Use FutureWarning for methods deprecated 2012
......................................................................
[cleanup] Use FutureWarning for methods deprecated 2012
- use FutureWarning for fileIsOnCommons in favour of file_is_shared
because this method was deprecated 8 years ago
- rename fileIsShared to file_is_shared
- deprecate the older fileIsShared due to naming convention
- replace all occurrences if fileIsShared
- use FutureWarning for the two randompages shortcuts
which where deprecated 7 years ago
Change-Id: I956b569b6976907049fe829aa6eb599450178d6b
---
M pywikibot/page/__init__.py
M pywikibot/site/__init__.py
M pywikibot/specialbots/_upload.py
M scripts/checkimages.py
M scripts/imagetransfer.py
M scripts/nowcommons.py
M scripts/unusedfiles.py
M tests/file_tests.py
8 files changed, 39 insertions(+), 27 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 9085f15..fe6bf42 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -2612,17 +2612,26 @@
url_param=url_param)
return self.latest_file_info.thumburl
- @deprecated('fileIsShared', since='20121101')
+ @deprecated('file_is_shared', since='20121101', future_warning=True)
def fileIsOnCommons(self):
"""
DEPRECATED. Check if the image is stored on Wikimedia Commons.
@rtype: bool
"""
- return self.fileIsShared()
+ return self.file_is_shared()
+ @deprecated('file_is_shared', since='20200618')
def fileIsShared(self):
"""
+ DEPRECATED. Check if the image is stored on Wikimedia Commons.
+
+ @rtype: bool
+ """
+ return self.file_is_shared()
+
+ def file_is_shared(self):
+ """
Check if the file is stored on any known shared repository.
@rtype: bool
@@ -2631,12 +2640,13 @@
# TODO: put the URLs to family file
if not self.site.has_image_repository:
return False
- elif 'wikitravel_shared' in self.site.shared_image_repository():
+
+ if 'wikitravel_shared' in self.site.shared_image_repository():
return self.latest_file_info.url.startswith(
'https://wikitravel.org/upload/shared/')
- else:
- return self.latest_file_info.url.startswith(
- 'https://upload.wikimedia.org/wikipedia/commons/')
+ # default to commons
+ return self.latest_file_info.url.startswith(
+ 'https://upload.wikimedia.org/wikipedia/commons/')
@deprecated('FilePage.latest_file_info.sha1', since='20141106')
def getFileMd5Sum(self):
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 5ee61be..d61c5b5 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -5193,7 +5193,8 @@
'ususers': usernames, 'usprop': usprop})
return usgen
- @deprecated('Site.randompages(total=1)', since='20130828')
+ @deprecated('Site.randompages(total=1)', since='20130828',
+ future_warning=True)
def randompage(self, redirect=False):
"""
DEPRECATED.
@@ -5203,7 +5204,8 @@
"""
return self.randompages(total=1, redirects=redirect)
- @deprecated('Site.randompages(total=1, redirects=True)', since='20130828')
+ @deprecated('Site.randompages(total=1, redirects=True)', since='20130828',
+ future_warning=True)
def randomredirectpage(self):
"""
DEPRECATED: Use Site.randompages() instead.
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index eec04ad..b1da796 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -322,7 +322,7 @@
continue
else:
try:
- if potential_file_page.fileIsShared():
+ if potential_file_page.file_is_shared():
pywikibot.output(
'File with name %s already exists in shared '
'repository and cannot be overwritten.' % filename)
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 668add6..f49b6ec 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -785,7 +785,7 @@
return True # continue with the check-part
pywikibot.output(self.imageName + ' is on commons!')
- if self.image.fileIsShared():
+ if self.image.file_is_shared():
pywikibot.output(
"But, the file doesn't exist on your project! Skip...")
# We have to skip the check part for that image because
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index ebbac0c..f421889 100755
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -274,7 +274,7 @@
break
todo = int(todo)
if 0 <= todo < len(imagelist):
- if (imagelist[todo].fileIsShared()
+ if (imagelist[todo].file_is_shared()
and imagelist[todo].site.image_repository()
== self.targetSite.image_repository()):
pywikibot.output(
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index d704ebf..48f4a4a 100755
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -268,7 +268,7 @@
self.current_page = page
try:
localImagePage = pywikibot.FilePage(self.site, page.title())
- if localImagePage.fileIsShared():
+ if localImagePage.file_is_shared():
pywikibot.output('File is already on Commons.')
continue
sha1 = localImagePage.latest_file_info.sha1
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 2273d0a..d563a80 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -12,7 +12,7 @@
If not used, all pages are used.
"""
#
-# (C) Pywikibot team, 2007-2019
+# (C) Pywikibot team, 2007-2020
#
# Distributed under the terms of the MIT license.
#
@@ -64,9 +64,9 @@
def treat(self, image):
"""Process one image page."""
- # Use fileUrl() and fileIsShared() to confirm it is local media
+ # Use fileUrl() and file_is_shared() to confirm it is local media
# rather than a local page with the same name as shared media.
- if (image.fileUrl() and not image.fileIsShared()
+ if (image.fileUrl() and not image.file_is_shared()
and 'http://' not in image.text):
if self.template_image in image.text:
pywikibot.output('{0} done already'
diff --git a/tests/file_tests.py b/tests/file_tests.py
index 1e7b50b..c96cae1 100644
--- a/tests/file_tests.py
+++ b/tests/file_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""FilePage tests."""
#
-# (C) Pywikibot team, 2014-2019
+# (C) Pywikibot team, 2014-2020
#
# Distributed under the terms of the MIT license.
#
@@ -21,7 +21,7 @@
class TestShareFiles(TestCase):
- """Test fileIsShared, exists and fileUrl/get_file_url with shared files."""
+ """Test file_is_shared, exists, fileUrl/get_file_url with shared files."""
sites = {
'enwiki': {
@@ -55,7 +55,7 @@
self.assertEqual(itwp_file.fileUrl(), itwp_file.get_file_url())
def testSharedOnly(self):
- """Test fileIsShared() on file page with shared file only."""
+ """Test file_is_shared() on file page with shared file only."""
title = 'File:Sepp Maier 1.JPG'
commons = self.get_site('commons')
@@ -69,8 +69,8 @@
self.assertFalse(itwp_file.exists())
self.assertTrue(commons_file.exists())
- self.assertTrue(itwp_file.fileIsShared())
- self.assertTrue(commons_file.fileIsShared())
+ self.assertTrue(itwp_file.file_is_shared())
+ self.assertTrue(commons_file.file_is_shared())
self.assertTrue(commons_file.get_file_url())
self.assertIn('/wikipedia/commons/', itwp_file.get_file_url())
@@ -80,7 +80,7 @@
itwp_file.get()
def testLocalOnly(self):
- """Test fileIsShared() on file page with local file only."""
+ """Test file_is_shared() on file page with local file only."""
title = 'File:Untitled (Three Forms), stainless steel sculpture by ' \
'--James Rosati--, 1975-1976, --Honolulu Academy of Arts--.JPG'
@@ -96,14 +96,14 @@
self.assertTrue(enwp_file.exists())
self.assertFalse(commons_file.exists())
- self.assertFalse(enwp_file.fileIsShared())
+ self.assertFalse(enwp_file.file_is_shared())
page_doesnt_exist_exc_regex = re.escape(
"Page [[commons:{}]] doesn't exist.".format(title))
with self.assertRaisesRegex(
pywikibot.NoPage,
page_doesnt_exist_exc_regex):
- commons_file.fileIsShared()
+ commons_file.file_is_shared()
with self.assertRaisesRegex(
pywikibot.NoPage,
@@ -116,7 +116,7 @@
commons_file.get()
def testOnBoth(self):
- """Test fileIsShared() on file page with local and shared file."""
+ """Test file_is_shared() on file page with local and shared file."""
title = 'File:Pulsante spam.png'
commons = self.get_site('commons')
@@ -131,8 +131,8 @@
self.assertTrue(itwp_file.exists())
self.assertTrue(commons_file.exists())
- self.assertFalse(itwp_file.fileIsShared())
- self.assertTrue(commons_file.fileIsShared())
+ self.assertFalse(itwp_file.file_is_shared())
+ self.assertTrue(commons_file.file_is_shared())
def testNonFileLocal(self):
"""Test file page, without local file, existing on the local wiki."""
@@ -144,7 +144,7 @@
self.assertTrue(testwp_file.latest_file_info.url)
self.assertTrue(testwp_file.exists())
- self.assertTrue(testwp_file.fileIsShared())
+ self.assertTrue(testwp_file.file_is_shared())
commons_file = pywikibot.FilePage(commons, title)
self.assertEqual(testwp_file.get_file_url(),
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606313
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: I956b569b6976907049fe829aa6eb599450178d6b
Gerrit-Change-Number: 606313
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606430 )
Change subject: [IMPR] Add missing return statements
......................................................................
[IMPR] Add missing return statements
- simplify toggleTalkPage
- remove return value from Page.delete method because
site.deletepage does not return anything other than None
- return empty list as last resort of getDeletedRevision.
This may be a breaking change but improves consisteny of
the result.
- remove return value in protect method because
site.protect does not return a value
- simplify registration to return None by default
- raise TypeError if Page._nskey is neither int nor str
Change-Id: I9dd2a6ea796f7528d7be81a240e298c220f9522f
---
M pywikibot/page/__init__.py
1 file changed, 22 insertions(+), 20 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 9085f15..9d20f7e 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -926,18 +926,12 @@
"""
ns = self.namespace()
if ns < 0: # Special page
- return
- if self.isTalkPage():
- if self.namespace() == 1:
- return Page(self.site, self.title(with_ns=False))
- else:
- return Page(self.site,
- '%s:%s' % (self.site.namespace(ns - 1),
- self.title(with_ns=False)))
- else:
- return Page(self.site,
- '%s:%s' % (self.site.namespace(ns + 1),
- self.title(with_ns=False)))
+ return None
+
+ title = self.title(with_ns=False)
+ new_ns = ns + (1, -1)[self.isTalkPage()]
+ return Page(self.site,
+ '{}:{}'.format(self.site.namespace(new_ns), title))
def is_categorypage(self):
"""Return True if the page is a Category, False otherwise."""
@@ -1957,7 +1951,9 @@
answer = 'y'
self.site._noDeletePrompt = True
if answer == 'y':
- return self.site.deletepage(self, reason)
+ self.site.deletepage(self, reason)
+ return
+
else: # Otherwise mark it for deletion
if mark or hasattr(self.site, '_noMarkDeletePrompt'):
answer = 'y'
@@ -2010,7 +2006,7 @@
@return: a list of [date, editor, comment, text, restoration
marker]. text will be None, unless content is True (or has
been retrieved earlier). If timestamp is not found, returns
- None.
+ empty list.
@rtype: list
"""
if hasattr(self, '_deletedRevs'):
@@ -2018,12 +2014,14 @@
not content
or 'content' in self._deletedRevs[timestamp]):
return self._deletedRevs[timestamp]
+
for item in self.site.deletedrevs(self, start=timestamp,
content=content, total=1):
# should only be one item with one revision
if item['title'] == self.title:
if 'revisions' in item:
return item['revisions'][0]
+ return []
def markDeletedRevision(self, timestamp, undelete=True):
"""
@@ -2150,7 +2148,7 @@
answer = 'y'
self.site._noProtectPrompt = True
if answer == 'y':
- return self.site.protect(self, protections, reason, **kwargs)
+ self.site.protect(self, protections, reason, **kwargs)
@deprecated_args(
comment='summary', oldCat='old_cat', newCat='new_cat',
@@ -3306,11 +3304,11 @@
@rtype: pywikibot.Timestamp or None
"""
- if self.isAnonymous():
- return None
- reg = self.getprops(force).get('registration')
- if reg:
- return pywikibot.Timestamp.fromISOformat(reg)
+ if not self.isAnonymous():
+ reg = self.getprops(force).get('registration')
+ if reg:
+ return pywikibot.Timestamp.fromISOformat(reg)
+ return None
def editCount(self, force=False):
"""
@@ -6103,6 +6101,10 @@
ns = self.site.namespaces[default_nskey]
return ns
+ raise TypeError(
+ 'Invalid type "{}" for Page._nskey. Must be int or str.'
+ .format(type(self._nskey)))
+
@property
def site(self):
"""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606430
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: I9dd2a6ea796f7528d7be81a240e298c220f9522f
Gerrit-Change-Number: 606430
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-MessageType: merged