Skip to content

Commit 7510561

Browse files
committed
initial upload
1 parent f54bdaf commit 7510561

File tree

7 files changed

+243
-0
lines changed

7 files changed

+243
-0
lines changed

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: python
2+
notifications:
3+
email: false
4+
env:
5+
global:
6+
python:
7+
- 2.6
8+
- 2.7
9+
- 3.3
10+
- 3.4
11+
- pypy
12+
install:
13+
- pip install -r requirements.txt
14+
- pip install -r tests/requirements.txt --use-mirrors
15+
script:
16+
nosetests --rednose --with-cov
17+
after_success:
18+
codecov
File renamed without changes.

pyexcel_text/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#from pyexcel.io import READERS
2+
#from pyexcel.io import WRITERS
3+
#
4+
#READERS["test"] = "test"
5+
#WRITERS["test"] = "test"
6+
from pyexcel.presentation import STRINGIFICATION
7+
8+
9+
TABLEFMT="simple"
10+
11+
12+
def present_matrix(matrix_instance):
13+
import tabulate
14+
return tabulate.tabulate(matrix_instance.to_array(), tablefmt=TABLEFMT)
15+
16+
17+
def present_nominable_sheet(nmsheet_instance):
18+
import tabulate
19+
ret = "Sheet Name: %s\n" % nmsheet_instance.name
20+
if len(nmsheet_instance.colnames) > 0:
21+
data = nmsheet_instance.to_array()
22+
return ret+tabulate.tabulate(data, headers="firstrow")
23+
else:
24+
return ret+present_matrix(nmsheet_instance)
25+
26+
27+
def present_book(book_instance):
28+
ret = ""
29+
for sheet in book_instance.sheets:
30+
ret += present_nominable_sheet(book_instance.sheets[sheet])
31+
ret += "\n"
32+
return ret.strip('\n')
33+
34+
35+
STRINGIFICATION["pyexcel.sheets.matrix.Matrix"] = present_matrix
36+
STRINGIFICATION["pyexcel.sheets.matrix.FormattableSheet"] = present_matrix
37+
STRINGIFICATION["pyexcel.sheets.matrix.FilterableSheet"] = present_matrix
38+
STRINGIFICATION["pyexcel.sheets.sheet.NominableSheet"] = present_nominable_sheet
39+
STRINGIFICATION["pyexcel.sheets.sheet.Sheet"] = present_nominable_sheet
40+
STRINGIFICATION["pyexcel.book.Book"] = present_book
41+

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tabulate
2+
pyexcel

setup.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
pyexcel-tabulate
3+
~~~~~~~~~~~~~~
4+
5+
textual plugin for pyexcel
6+
"""
7+
8+
try:
9+
from setuptools import setup, find_packages
10+
except ImportError:
11+
from ez_setup import use_setuptools
12+
use_setuptools()
13+
from setuptools import setup, find_packages
14+
15+
with open("README.rst", 'r') as readme:
16+
README_txt = readme.read()
17+
18+
setup(
19+
name='pyexcel-text',
20+
author="C. W.",
21+
version='0.0.1',
22+
author_email="wangc_2011@hotmail.com",
23+
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
24+
include_package_data=True,
25+
dependencies=[
26+
'pyexcel>=0.0.8',
27+
'tabulate'
28+
],
29+
description="It is a plugin to pyexcel and provides the capbility to present and write data in text fromats",
30+
long_description=__doc__,
31+
zip_safe=False,
32+
classifiers=[
33+
'Development Status :: 3 - Alpha',
34+
'Topic :: Office/Business',
35+
'Topic :: Utilities',
36+
'Topic :: Software Development :: Libraries',
37+
'Programming Language :: Python',
38+
'License :: OSI Approved :: GNU General Public License v3',
39+
'Intended Audience :: Developers',
40+
'Programming Language :: Python :: 2.6',
41+
'Programming Language :: Python :: 2.7'
42+
]
43+
)

tests/requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
nose
2+
rednose
3+
nose-cov
4+
python-coveralls
5+
coverage
6+

tests/test_presentation.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
from textwrap import dedent
2+
import pyexcel as pe
3+
from pyexcel.ext import text
4+
5+
6+
class TestPresentation:
7+
def test_normal_usage(self):
8+
content = [
9+
[1, 2, 3],
10+
[4, 588, 6],
11+
[7, 8, 999]
12+
]
13+
s = pe.Sheet(content)
14+
content = dedent("""
15+
Sheet Name: pyexcel
16+
- --- ---
17+
1 2 3
18+
4 588 6
19+
7 8 999
20+
- --- ---""").strip('\n')
21+
assert str(s) == content
22+
23+
def test_irregular_usage(self):
24+
"""textable doesn't like empty string """
25+
content = [
26+
[1, 2, 3],
27+
[4, 588, 6],
28+
[7, 8] # one empty string
29+
]
30+
s = pe.Sheet(content)
31+
content = dedent("""
32+
Sheet Name: pyexcel
33+
- --- -
34+
1 2 3
35+
4 588 6
36+
7 8
37+
- --- -""").strip('\n')
38+
assert str(s) == content
39+
40+
41+
def test_column_series(self):
42+
content = [
43+
["Column 1", "Column 2", "Column 3"],
44+
[1, 2, 3],
45+
[4, 5, 6],
46+
[7, 8, 9]
47+
]
48+
s = pe.Sheet(content, name_columns_by_row=0)
49+
content = dedent("""
50+
Sheet Name: pyexcel
51+
Column 1 Column 2 Column 3
52+
---------- ---------- ----------
53+
1 2 3
54+
4 5 6
55+
7 8 9""").strip('\n')
56+
assert str(s) == content
57+
58+
def test_data_frame(self):
59+
content = [
60+
["", "Column 1", "Column 2", "Column 3"],
61+
["Row 1", 1, 2, 3],
62+
["Row 2", 4, 5, 6],
63+
["Row 3", 7, 8, 9]
64+
]
65+
s = pe.Sheet(content, name_rows_by_column=0, name_columns_by_row=0)
66+
content = dedent("""
67+
Sheet Name: pyexcel
68+
Column 1 Column 2 Column 3
69+
----- ---------- ---------- ----------
70+
Row 1 1 2 3
71+
Row 2 4 5 6
72+
Row 3 7 8 9""").strip('\n')
73+
assert str(s) == content
74+
75+
def test_row_series(self):
76+
content = [
77+
["Row 1", 1, 2, 3],
78+
["Row 2", 4, 5, 6],
79+
["Row 3", 7, 8, 9]
80+
]
81+
s = pe.Sheet(content, name_rows_by_column=0)
82+
content = dedent("""
83+
Sheet Name: pyexcel
84+
----- - - -
85+
Row 1 1 2 3
86+
Row 2 4 5 6
87+
Row 3 7 8 9
88+
----- - - -""").strip('\n')
89+
assert str(s) == content
90+
91+
def test_book_presentation(self):
92+
data = {
93+
'Sheet 1':
94+
[
95+
[1.0, 2.0, 3.0],
96+
[4.0, 5.0, 6.0],
97+
[7.0, 8.0, 9.0]
98+
],
99+
'Sheet 2':
100+
[
101+
['X', 'Y', 'Z'],
102+
[1.0, 2.0, 3.0],
103+
[4.0, 5.0, 6.0]
104+
],
105+
'Sheet 3':
106+
[
107+
['O', 'P', 'Q'],
108+
[3.0, 2.0, 1.0],
109+
[4.0, 3.0, 2.0]
110+
]
111+
}
112+
book = pe.Book(data)
113+
content = dedent("""
114+
Sheet Name: Sheet 1
115+
- - -
116+
1 2 3
117+
4 5 6
118+
7 8 9
119+
- - -
120+
Sheet Name: Sheet 2
121+
--- --- ---
122+
X Y Z
123+
1.0 2.0 3.0
124+
4.0 5.0 6.0
125+
--- --- ---
126+
Sheet Name: Sheet 3
127+
--- --- ---
128+
O P Q
129+
3.0 2.0 1.0
130+
4.0 3.0 2.0
131+
--- --- ---""").strip("\n")
132+
assert str(book) == content
133+

0 commit comments

Comments
 (0)