Xqt has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/399755 )
Change subject: [IMPR] Introduce a timestamp in deprecated decorator
......................................................................
[IMPR] Introduce a timestamp in deprecated decorator
- also add timestamps in scripts files
Bug: T106121
Change-Id: I376c6ee1a2be5118ea331e51d3b8332cb5250b4b
---
M pywikibot/tools/__init__.py
M scripts/category.py
M scripts/data_ingestion.py
M scripts/replace.py
M scripts/replicate_wiki.py
M scripts/template.py
M scripts/weblinkchecker.py
7 files changed, 39 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/55/399755/1
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index b9c99e0..6a2e891 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -22,6 +22,7 @@
import time
import types
+from datetime import datetime
from distutils.version import Version
from functools import wraps
from warnings import catch_warnings, showwarning, warn
@@ -1356,17 +1357,41 @@
return outer_wrapper
-def issue_deprecation_warning(name, instead, depth, warning_class=None):
+def issue_deprecation_warning(name, instead, depth, warning_class=None,
+ since=None):
"""Issue a deprecation warning."""
+ if since:
+ days = (datetime.utcnow() - datetime.strptime(since, '%Y%m%d')).days
+ years = days // 365
+ days = days % 365
+ months = days / 30
+ days = days % 30
+ if years == 1:
+ years = 0
+ months += 12
+ years = '{0} years'.format(years) if years else ''
+ months = '{0} month{1}'.format(
+ months, 's' if months != 1 else '') if months else ''
+ if years and months:
+ years += ' and '
+ days = '{0} day{1}'.format(
+ days, 's' if days != 1 else '') if not years else ''
+ if months and days:
+ months += ' and '
+ since = ' since {0}{1}{2}'.format(years, months, days)
+ else:
+ since = ''
if instead:
if warning_class is None:
warning_class = DeprecationWarning
- warn(u'{0} is deprecated; use {1} instead.'.format(name, instead),
+ warn('{0} is deprecated{1}; use {2} instead.'
+ .format(name, since, instead),
warning_class, depth + 1)
else:
if warning_class is None:
warning_class = _NotImplementedWarning
- warn('{0} is deprecated.'.format(name), warning_class, depth + 1)
+ warn('{0} is deprecated{1}.'
+ .format(name, since), warning_class, depth + 1)
@add_full_name
@@ -1396,7 +1421,7 @@
"""
name = obj.__full_name__
depth = get_wrapper_depth(wrapper) + 1
- issue_deprecation_warning(name, instead, depth)
+ issue_deprecation_warning(name, instead, depth, since=since)
return obj(*args, **kwargs)
def add_docstring(wrapper):
@@ -1436,6 +1461,7 @@
return wrapper
+ since = kwargs.pop('since', None)
without_parameters = len(args) == 1 and len(kwargs) == 0 and
callable(args[0])
if 'instead' in kwargs:
instead = kwargs['instead']
diff --git a/scripts/category.py b/scripts/category.py
index 6d09ada..a0dcadb 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -769,7 +769,7 @@
CategoryMoveRobot without newcat param instead.
"""
- @deprecated('CategoryMoveRobot.__init__()')
+ @deprecated('CategoryMoveRobot.__init__()', since='20140416')
def __init__(self, catTitle, batchMode=False, editSummary='',
useSummaryForDeletion=CategoryMoveRobot.DELETION_COMMENT_AUTOMATIC,
titleRegex=None, inPlace=False, pagesonly=False):
diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py
index a6628c1..05cd3ed 100755
--- a/scripts/data_ingestion.py
+++ b/scripts/data_ingestion.py
@@ -178,13 +178,13 @@
self.pagefmt = pagefmt
@property
- @deprecated('generator')
+ @deprecated('generator', since='20150508')
def reader(self):
"""Get generator. Deprecated."""
return self.generator
@reader.setter
- @deprecated('generator')
+ @deprecated('generator', since='20150508')
def reader(self, value):
"""Set generator. Deprecated."""
self.generator = value
@@ -211,7 +211,7 @@
return title
- @deprecated("treat()")
+ @deprecated('treat()', since='20150118')
def doSingle(self):
"""Process one page."""
return self.treat(next(self.reader))
diff --git a/scripts/replace.py b/scripts/replace.py
index ddaea1b..db68545 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -651,7 +651,7 @@
return new_text
- @deprecated('apply_replacements')
+ @deprecated('apply_replacements', since='20160816')
def doReplacements(self, original_text, page=None):
"""Apply replacements to the given text and page."""
if page is None:
diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py
index 7009737..f14d1a8 100755
--- a/scripts/replicate_wiki.py
+++ b/scripts/replicate_wiki.py
@@ -58,7 +58,7 @@
from pywikibot.tools import deprecated
-@deprecated('BaseSite.namespaces')
+@deprecated('BaseSite.namespaces', since='20150515')
def namespaces(site):
"""Return a dictionary from namespace number to prefix."""
return dict((n.id, n.custom_name) for n in site.namespaces)
diff --git a/scripts/template.py b/scripts/template.py
index ca51b7d..aeb96ca 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -127,7 +127,7 @@
from scripts.replace import ReplaceRobot as ReplaceBot
-@deprecated('XMLDumpPageGenerator')
+@deprecated('XMLDumpPageGenerator', since='20151109')
class XmlDumpTemplatePageGenerator(XMLDumpPageGenerator):
"""
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index 54ac583..dd159c0 100755
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -289,7 +289,7 @@
"""The link is not an URL."""
-@deprecated('requests')
+@deprecated('requests', since='20160120')
class LinkChecker(object):
"""
@@ -940,7 +940,7 @@
return i
-@deprecated('requests')
+@deprecated('requests', since='20160120')
def check(url):
"""DEPRECATED: Use requests instead. Perform a check on URL."""
c = LinkChecker(url)
--
To view, visit https://gerrit.wikimedia.org/r/399755
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I376c6ee1a2be5118ea331e51d3b8332cb5250b4b
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits