Skip to content

Commit 974f66e

Browse files
committed
fix #10 support two dimensional generators: a generator list of a generator list
1 parent 97a81fb commit 974f66e

File tree

9 files changed

+72
-30
lines changed

9 files changed

+72
-30
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Change log
22
================================================================================
33

4+
0.2.3 - unreleased
5+
--------------------------------------------------------------------------------
6+
7+
Updated
8+
********************************************************************************
9+
10+
#. `#10 <https://github.com/pyexcel/pyexcel-xls/issues/10>`_, To support
11+
generator as member of the incoming two dimensional data
12+
413
0.2.2 - 31.08.2016
514
--------------------------------------------------------------------------------
615

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ Development steps for code changes
280280

281281
Upgrade your setup tools and pip. They are needed for development and testing only:
282282

283-
#. pip install --upgrade setuptools "pip==7.1"
283+
#. pip install --upgrade setuptools "pip==7.1"
284284

285285
Then install relevant development requirements:
286286

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
project = u'pyexcel-xls'
1818
copyright = u'2015-2016 Onni Software Ltd.'
19-
version = '0.2.1'
20-
release = '0.2.2'
19+
version = '0.2.2'
20+
release = '0.2.3'
2121
exclude_patterns = []
2222
pygments_style = 'sphinx'
2323
html_theme = 'default'

pyexcel_xls.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
overrides: "pyexcel.yaml"
22
name: "pyexcel-xls"
33
nick_name: xls
4-
version: 0.2.2
5-
release: 0.2.1
4+
version: 0.2.3
5+
release: 0.2.2
66
file_type: xls
77
dependencies:
88
- pyexcel-io>=0.2.2

pyexcel_xls/xls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ def write_row(self, array):
190190
"""
191191
write a row into the file
192192
"""
193-
for i in range(len(array)):
194-
value = array[i]
193+
for i, value in enumerate(array):
195194
style = None
196195
tmp_array = []
197196
if isinstance(value, datetime.datetime):

setup.py

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
NAME = 'pyexcel-xls'
1212
AUTHOR = 'C.W.'
13-
VERSION = '0.2.2'
13+
VERSION = '0.2.3'
1414
EMAIL = 'wangc_2011 (at) hotmail.com'
1515
LICENSE = 'New BSD'
16-
PACKAGES = find_packages(exclude=['ez_setup', 'examples', 'tests'])
1716
DESCRIPTION = (
1817
'A wrapper library to read, manipulate and write data in xls format. It' +
1918
' reads xlsx and xlsm format' +
@@ -28,19 +27,6 @@
2827
'xlsm'
2928
]
3029

31-
INSTALL_REQUIRES = [
32-
'pyexcel-io>=0.2.2',
33-
'xlrd',
34-
]
35-
36-
if PY2:
37-
INSTALL_REQUIRES.append('xlwt')
38-
if not PY2:
39-
INSTALL_REQUIRES.append('xlwt-future')
40-
41-
EXTRAS_REQUIRE = {
42-
}
43-
4430
CLASSIFIERS = [
4531
'Topic :: Office/Business',
4632
'Topic :: Utilities',
@@ -57,19 +43,56 @@
5743
'Programming Language :: Python :: Implementation :: PyPy'
5844
]
5945

46+
INSTALL_REQUIRES = [
47+
'pyexcel-io>=0.2.2',
48+
'xlrd',
49+
]
50+
51+
if PY2:
52+
INSTALL_REQUIRES.append('xlwt')
53+
if not PY2:
54+
INSTALL_REQUIRES.append('xlwt-future')
55+
56+
PACKAGES = find_packages(exclude=['ez_setup', 'examples', 'tests'])
57+
EXTRAS_REQUIRE = {
58+
}
59+
6060

6161
def read_files(*files):
6262
"""Read files into setup"""
6363
text = ""
6464
for single_file in files:
65-
text = text + read(single_file) + "\n"
65+
content = read(single_file)
66+
text = text + content + "\n"
6667
return text
6768

6869

6970
def read(afile):
7071
"""Read a file into setup"""
7172
with open(afile, 'r') as opened_file:
72-
return opened_file.read()
73+
content = filter_out_test_code(opened_file)
74+
content = "".join(list(content))
75+
return content
76+
77+
78+
def filter_out_test_code(file_handle):
79+
found_test_code = False
80+
for line in file_handle.readlines():
81+
if line.startswith('.. testcode:'):
82+
found_test_code = True
83+
continue
84+
if found_test_code is True:
85+
if line.startswith(' '):
86+
continue
87+
else:
88+
empty_line = line.strip()
89+
if len(empty_line) == 0:
90+
continue
91+
else:
92+
found_test_code = False
93+
yield line
94+
else:
95+
yield line
7396

7497

7598
if __name__ == '__main__':
@@ -79,14 +102,14 @@ def read(afile):
79102
version=VERSION,
80103
author_email=EMAIL,
81104
description=DESCRIPTION,
82-
install_requires=INSTALL_REQUIRES,
105+
long_description=read_files('README.rst', 'CHANGELOG.rst'),
106+
license=LICENSE,
83107
keywords=KEYWORDS,
84108
extras_require=EXTRAS_REQUIRE,
109+
tests_require=['nose'],
110+
install_requires=INSTALL_REQUIRES,
85111
packages=PACKAGES,
86112
include_package_data=True,
87-
long_description=read_files('README.rst', 'CHANGELOG.rst'),
88113
zip_safe=False,
89-
tests_require=['nose'],
90-
license=LICENSE,
91114
classifiers=CLASSIFIERS
92115
)

test.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

2+
23
pip freeze
3-
nosetests --with-cov --cover-package pyexcel_xls --cover-package tests --with-doctest --doctest-extension=.rst tests README.rst pyexcel_xls && flake8 . --exclude=.moban.d --builtins=unicode,xrange,long
4+
nosetests --with-cov --cover-package pyexcel_xls --cover-package tests --with-doctest --doctest-extension=.rst tests README.rst pyexcel_xls && flake8 . --exclude=.moban.d --builtins=unicode,xrange,long

test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

2+
23
pip freeze
3-
nosetests --with-cov --cover-package pyexcel_xls --cover-package tests --with-doctest --doctest-extension=.rst tests README.rst pyexcel_xls && flake8 . --exclude=.moban.d --builtins=unicode,xrange,long
4+
nosetests --with-cov --cover-package pyexcel_xls --cover-package tests --with-doctest --doctest-extension=.rst tests README.rst pyexcel_xls && flake8 . --exclude=.moban.d --builtins=unicode,xrange,long

tests/test_bug_fixes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ def test_issue_9_hidden_sheet_2(self):
4545
assert "hidden" in book_dict
4646
eq_(book_dict['shown'], [['A', 'B']])
4747
eq_(book_dict['hidden'], [['a', 'b']])
48+
49+
def test_issue_10_generator_as_content(self):
50+
def data_gen():
51+
def custom_row_renderer(row):
52+
for e in row:
53+
yield e
54+
for i in range(2):
55+
yield custom_row_renderer([1,2])
56+
save_data("test.xls", {"sheet": data_gen()})

0 commit comments

Comments
 (0)