Skip to content

Commit

Permalink
Remove dependency on six.
Browse files Browse the repository at this point in the history
Mostly so that Matplotlib doesn't depend *transitively* on six either :)

- six.iteritems() -> dict.items(): OK even on Py2, we directly consume
  the iterator/list with reduce anyways, and I doubt that the perfomance
  change is measurable.
- six.moves.zip() could have been replaced with builtin zip() on both
  Py2 and Py3 because we always exhaust the iterator immediately
  anyways, but it also acts as a lookup key in `Cycler.__len__` so I
  decided to just play it safe and have a conditional import (on Py2,
  six.moves.zip is an alias for itertools.zip).

Also added new .pytest_cache directory to gitignore.
  • Loading branch information
anntzer committed Aug 28, 2018
1 parent ffa3377 commit 5fce18a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -33,6 +33,7 @@ htmlcov/
cover/
.coverage
.cache
.pytest_cache
nosetests.xml
coverage.xml
cover/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -13,7 +13,7 @@ matrix:

install:
- python setup.py install
- pip install pytest pytest-cov coverage six
- pip install pytest pytest-cov coverage

script:
- coverage run run_tests.py
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -20,7 +20,7 @@ install:
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""

# Install the build and runtime dependencies of the project.
- "pip install -v six nose pytest pytest-cov coverage"
- "pip install -v nose pytest pytest-cov coverage"

# Install the generated wheel package to test it
- "python setup.py install"
Expand Down
2 changes: 0 additions & 2 deletions conda-recipe/meta.yaml
Expand Up @@ -30,11 +30,9 @@ requirements:
build:
- python
- setuptools
- six

run:
- python
- six

test:
# Python imports
Expand Down
20 changes: 10 additions & 10 deletions cycler.py
Expand Up @@ -43,11 +43,14 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six
import copy
from functools import reduce
from itertools import product, cycle
from six.moves import zip, reduce
from operator import mul, add
import copy
import sys

if sys.version_info < (3,):
from itertools import izip as zip

__version__ = '0.10.0'

Expand Down Expand Up @@ -183,7 +186,6 @@ def change_key(self, old, new):
def _compose(self):
"""
Compose the 'left' and 'right' components of this cycle
with the proper operation (zip or product as of now)
"""
for a, b in self._op(self._left, self._right):
out = dict()
Expand Down Expand Up @@ -220,8 +222,7 @@ def __getitem__(self, key):
# TODO : maybe add numpy style fancy slicing
if isinstance(key, slice):
trans = self.by_key()
return reduce(add, (_cycler(k, v[key])
for k, v in six.iteritems(trans)))
return reduce(add, (_cycler(k, v[key]) for k, v in trans.items()))
else:
raise ValueError("Can only use slices with Cycler.__getitem__")

Expand Down Expand Up @@ -259,8 +260,7 @@ def __mul__(self, other):
return Cycler(self, other, product)
elif isinstance(other, int):
trans = self.by_key()
return reduce(add, (_cycler(k, v*other)
for k, v in six.iteritems(trans)))
return reduce(add, (_cycler(k, v*other) for k, v in trans.items()))
else:
return NotImplemented

Expand Down Expand Up @@ -396,7 +396,7 @@ def simplify(self):
# I would believe that there is some performance implications

trans = self.by_key()
return reduce(add, (_cycler(k, v) for k, v in six.iteritems(trans)))
return reduce(add, (_cycler(k, v) for k, v in trans.items()))

def concat(self, other):
"""Concatenate this cycler and an other.
Expand Down Expand Up @@ -523,7 +523,7 @@ def cycler(*args, **kwargs):
"positional argument. Use keyword arguments instead.")

if kwargs:
return reduce(add, (_cycler(k, v) for k, v in six.iteritems(kwargs)))
return reduce(add, (_cycler(k, v) for k, v in kwargs.items()))

raise TypeError("Must have at least a positional OR keyword arguments")

Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -8,7 +8,6 @@
description='Composable style cycles',
url='https://github.com/matplotlib/cycler',
platforms='Cross platform (Linux, Mac OSX, Windows)',
install_requires=['six'],
license="BSD",
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
classifiers=['Development Status :: 4 - Beta',
Expand Down
20 changes: 13 additions & 7 deletions test_cycler.py
@@ -1,12 +1,18 @@
from __future__ import (absolute_import, division, print_function)

import six
from six.moves import zip, range
from cycler import cycler, Cycler, concat
import pytest
from itertools import product, cycle, chain
from operator import add, iadd, mul, imul
from collections import defaultdict
from operator import add, iadd, mul, imul
from itertools import product, cycle, chain
import sys

import pytest

from cycler import cycler, Cycler, concat

if sys.version_info < (3,):
from itertools import izip as zip
range = xrange
str = unicode


def _cycler_helper(c, length, keys, values):
Expand Down Expand Up @@ -147,7 +153,7 @@ def test_fail_getime():
def _repr_tester_helper(rpr_func, cyc, target_repr):
test_repr = getattr(cyc, rpr_func)()

assert six.text_type(test_repr) == six.text_type(target_repr)
assert str(test_repr) == str(target_repr)


def test_repr():
Expand Down

0 comments on commit 5fce18a

Please sign in to comment.