jenkins-bot has submitted this change and it was merged.
Change subject: Declare family.versionnumber and site.versionnumber as deprecated ......................................................................
Declare family.versionnumber and site.versionnumber as deprecated
There is a more precise method to compare versions by using LooseVersion from distutils.version whereas versionnumber() for "2.1wmf3" looks very strange with 1001. With LV we can also compare the build number.
remove versionnumber() from old site method list
Change-Id: I442523c5b14ccf1a240e74e782c6b3f6f3139a0d --- M pywikibot/family.py M pywikibot/site.py M pywikibot/textlib.py M scripts/cosmetic_changes.py M tests/site_tests.py 5 files changed, 19 insertions(+), 11 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py index c422460..ae20781 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -959,14 +959,18 @@
# Which version of MediaWiki is used? def version(self, code): - """Return MediaWiki version number as a string.""" - # Don't use this, use versionnumber() instead. This only exists - # to not break family files. + """ Return MediaWiki version number as a string. + Use LooseVersion from distutils.version to compare version strings. + + """ # Here we return the latest mw release for downloading return '1.20wmf2'
+ @pywikibot.deprecated("version()") def versionnumber(self, code): - """Return an int identifying MediaWiki version. + """ DEPRECATED, use version() instead and use + distutils.version.LooseVersion to compare version strings. + Return an int identifying MediaWiki version.
Currently this is implemented as returning the minor version number; i.e., 'X' in version '1.X.Y' @@ -1066,9 +1070,11 @@ ]
def version(self, code): - """Return Wikimedia projects version number as a string.""" - # Don't use this, use versionnumber() instead. This only exists - # to not break family files. + """Return Wikimedia projects version number as a string. + Use LooseVersion from distutils.version to compate versions. + + """ + # Here we return the latest mw release for downloading return '1.24wmf3'
def shared_image_repository(self, code): diff --git a/pywikibot/site.py b/pywikibot/site.py index 2db9e82..ce4328c 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -612,7 +612,6 @@ # postData: Post encoded form data to an http address at this site. # # version: Return MediaWiki version string from Family file. -# versionnumber: Return int identifying the MediaWiki version. # live_version: Return version number read from Special:Version. # checkCharset(charset): Warn if charset doesn't match family file. # diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index c96ecb6..410af7b 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -1020,7 +1020,8 @@ # if self.site().isInterwikiLink(name): # continue # # {{DEFAULTSORT:...}} -# defaultKeys = self.site().versionnumber() > 13 and \ +# from distutils.version import LooseVersion as LV +# defaultKeys = LV(self.site.version()) > LV("1.13") and \ # self.site().getmagicwords('defaultsort') # # It seems some wikis does not have this magic key # if defaultKeys: diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index 691460f..2b67cfc 100755 --- a/scripts/cosmetic_changes.py +++ b/scripts/cosmetic_changes.py @@ -74,6 +74,7 @@ #
import re +from distutils.version import LooseVersion as LV import pywikibot import isbn from pywikibot import pagegenerators @@ -338,7 +339,7 @@ thisNs = namespaces.pop(0) if nsNumber == 6 and family.name == 'wikipedia': if self.site.lang in ('en', 'fr') and \ - self.site.versionnumber() >= 14: + LV(self.site.version()) >= LV('1.14'): # do not change "Image" on en-wiki and fr-wiki assert u'Image' in namespaces namespaces.remove(u'Image') diff --git a/tests/site_tests.py b/tests/site_tests.py index 51a9c9e..83ff431 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -10,6 +10,7 @@ __version__ = '$Id$'
+from distutils.version import LooseVersion as LV import pywikibot from pywikibot.site import must_be from tests import patch_request, unpatch_request @@ -648,7 +649,7 @@ prefix = title[:title.index(":")] self.assertTrue(mysite.ns_index(prefix) in [6, 7]) self.assertTrue(change["ns"] in [6, 7]) - if mysite.versionnumber() <= 14: + if LV(mysite.version()) <= LV("1.14"): for change in mysite.recentchanges(pagelist=[mainpage, imagepage], total=5): self.assertType(change, dict)
pywikibot-commits@lists.wikimedia.org