Skip to content

Commit

Permalink
Merge pull request #1 from arghdos/master
Browse files Browse the repository at this point in the history
Add reset ("copy") interface, and enforce python3 compatibility
  • Loading branch information
arghdos authored Apr 20, 2017
2 parents bc0b52a + e49f5f5 commit 86596cd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ for a in [False, True]:
for c in [1, 2, 3]:
....
```

Additionally, an option loop (or combination thereof) can be reset using the copy
interface:

```python
d1 = {'lang' : ['c'], 'doThingX' : [True, False]}
oploop1 = optionloop(d1)

# iterate through 1

oploop2 = oploop1.copy()
```
1 change: 1 addition & 0 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ requirements:
build:
- python >=2.7,<3|>=3.5,{{PY_VER}}*
- setuptools
- six

run:
- python {{PY_VER}}*
Expand Down
2 changes: 1 addition & 1 deletion optionloop/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version_info__ = (1, 0, 5, '')
__version_info__ = (1, 0, 6, '')
__version__ = '.'.join(map(str, __version_info__[:3]))
if len(__version_info__) == 4:
__version__ += __version_info__[-1]
9 changes: 5 additions & 4 deletions optionloop/optionloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"""

from collections import defaultdict
import six


class OptionLoop(object):
Expand Down Expand Up @@ -149,7 +150,7 @@ def __init__(self, initializing_dictionary, default_dict_factory=None):
self.mydict = initializing_dictionary.copy()
self.index = 0
self.end_index = None
for key, value in self.mydict.iteritems():
for key, value in six.iteritems(self.mydict):
if isinstance(value, (str, bytes)):
self.mydict[key] = [value]
size = 1
Expand Down Expand Up @@ -178,9 +179,9 @@ def __next__(self):
else:
value_list = {}
startlen = 1
if self.index < self.end_index:
for key, value in self.mydict.iteritems():
value_list[key] = value[(self.index / startlen) % len(value)]
if self.end_index is not None and self.index < self.end_index:
for key, value in six.iteritems(self.mydict):
value_list[key] = value[int(self.index / startlen) % len(value)]
startlen *= len(value)

self.index += 1
Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
print('Warning: pypandoc module not found, could not convert Markdown to RST')
long_description = desc

install_requires = [
'six'
]

tests_require = [
'nose',
]
Expand All @@ -37,6 +41,7 @@
packages=['optionloop', 'optionloop.tests'],
zip_safe=True,
test_suite='nose.collector',
install_requires=install_requires,
tests_require=tests_require,
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down

0 comments on commit 86596cd

Please sign in to comment.