jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] tools: Add itertools.count function for 2.6
......................................................................
[FEAT] tools: Add itertools.count function for 2.6
The count function in itertools from Python 2.6 does only support positional
parameters and does not support a step. This uses the count implementation from
the future package just maps it to itertools' implementation in newer versions.
In case an older version of the future package is used (before 0.15.0) it uses
a backported version but informs the user to update.
Change-Id: I779580054642386c90ef2a10a33cfe64cfa1fd23
---
M pywikibot/tools/__init__.py
M requirements.txt
M setup.py
3 files changed, 25 insertions(+), 7 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 34be4cc..8d8e907 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -62,12 +62,12 @@
if PYTHON_VERSION < (2, 7):
try:
- from future.backports.misc import Counter, OrderedDict
+ import future.backports.misc
except ImportError:
warn("""
pywikibot support of Python 2.6 relies on package future for many features.
Please upgrade to Python 2.7+ or Python 3.3+, or run:
- "pip install future"
+ "pip install future>=0.15.0"
""", RuntimeWarning)
try:
from ordereddict import OrderedDict
@@ -86,10 +86,28 @@
"""Counter not found."""
pass
+ else:
+ Counter = future.backports.misc.Counter
+ OrderedDict = future.backports.misc.OrderedDict
+
+ try:
+ count = future.backports.misc.count
+ except AttributeError:
+ warn('Please update the "future" package to at least version '
+ '0.15.0 to use its count.', RuntimeWarning, 2)
+
+ def count(start=0, step=1):
+ """Backported C{count} to support keyword arguments and step."""
+ while True:
+ yield start
+ start += step
+
+ del future
else:
from collections import Counter # noqa ; unused
from collections import OrderedDict
+ from itertools import count # noqa ; unused
def empty_iterator():
@@ -563,13 +581,13 @@
def active_count(self):
"""Return the number of alive threads, and delete all non-alive ones."""
- count = 0
+ cnt = 0
for item in self[:]:
if item.isAlive():
- count += 1
+ cnt += 1
else:
self.remove(item)
- return count
+ return cnt
def append(self, thd):
"""Add a thread to the pool and start it."""
diff --git a/requirements.txt b/requirements.txt
index 4410981..4505d21 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -30,7 +30,7 @@
ndg-httpsclient ; python_full_version < '2.7.9'
pyasn1 ; python_full_version < '2.7.9'
-future ; python_version < '2.7'
+future>=0.15.0 ; python_version < '2.7'
ipaddr>=2.1.10 ; python_version < '3'
diff --git a/setup.py b/setup.py
index 01920d1..66c0160 100644
--- a/setup.py
+++ b/setup.py
@@ -105,7 +105,7 @@
sys.modules['unittest'] = unittest2
script_deps['replicate_wiki.py'] = ['argparse']
- dependencies.append('future') # provides collections backports
+ dependencies.append('future>=0.15.0') # provides collections backports
dependency_links.append(
'git+https://github.com/jayvdb/unicodedata2@issue_2#egg=unicodedata2-7.0.0')
--
To view, visit https://gerrit.wikimedia.org/r/219396
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I779580054642386c90ef2a10a33cfe64cfa1fd23
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>