From 9726dae38ecfe5f4a728a9869d7f427b855e13f1 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 3 Oct 2020 10:07:59 +0100 Subject: [PATCH 01/13] :tada: new style ods reader --- pyexcel_ods3/__init__.py | 19 +++++--- pyexcel_ods3/odsr.py | 101 ++++++++++++++------------------------- pyexcel_ods3/odsw.py | 1 - tests/test_bug_fixes.py | 2 +- tests/test_filter.py | 3 +- tests/test_ods_reader.py | 10 ++-- tests/test_writer.py | 3 +- 7 files changed, 58 insertions(+), 81 deletions(-) diff --git a/pyexcel_ods3/__init__.py b/pyexcel_ods3/__init__.py index 6929798..753a381 100644 --- a/pyexcel_ods3/__init__.py +++ b/pyexcel_ods3/__init__.py @@ -15,18 +15,25 @@ # this line has to be place above all else # because of dynamic import -from pyexcel_io.plugins import IOPluginInfoChain +from pyexcel_io.plugins import IOPluginInfoChain, IOPluginInfoChainV2 __FILE_TYPE__ = "ods" -IOPluginInfoChain(__name__).add_a_reader( - relative_plugin_class_path="odsr.ODSBook", - file_types=[__FILE_TYPE__], - stream_type="binary", -).add_a_writer( +IOPluginInfoChain(__name__).add_a_writer( relative_plugin_class_path="odsw.ODSWriter", file_types=[__FILE_TYPE__], stream_type="binary", ) +IOPluginInfoChainV2(__name__).add_a_reader( + relative_plugin_class_path="odsr.ODSBook", + locations=["file", "memory"], + file_types=[__FILE_TYPE__, 'fods'], + stream_type="binary", +).add_a_reader( + relative_plugin_class_path="odsr.ODSBookInContent", + locations=["content"], + file_types=[__FILE_TYPE__, 'fods'], + stream_type="binary", +) def save_data(afile, data, file_type=None, **keywords): diff --git a/pyexcel_ods3/odsr.py b/pyexcel_ods3/odsr.py index 2dc8d1a..da1a011 100644 --- a/pyexcel_ods3/odsr.py +++ b/pyexcel_ods3/odsr.py @@ -4,39 +4,41 @@ ods reader - :copyright: (c) 2015-2017 by Onni Software Ltd. & its contributors + :copyright: (c) 2015-2020 by Onni Software Ltd. & its contributors :license: New BSD License """ -import ezodf +from io import BytesIO +import ezodf import pyexcel_io.service as service -from pyexcel_io.book import BookReader -from pyexcel_io.sheet import SheetReader -from pyexcel_io._compact import OrderedDict +from pyexcel_io.plugin_api.abstract_sheet import ISheet +from pyexcel_io.plugin_api.abstract_reader import IReader -class ODSSheet(SheetReader): +class ODSSheet(ISheet): """ODS sheet representation""" def __init__(self, sheet, auto_detect_int=True, **keywords): - SheetReader.__init__(self, sheet, **keywords) self.auto_detect_int = auto_detect_int + self._native_sheet = sheet + self._keywords = keywords @property def name(self): return self._native_sheet.name - def number_of_rows(self): + def row_iterator(self): """ Number of rows in the xls sheet """ - return self._native_sheet.nrows() + return range(self._native_sheet.nrows()) - def number_of_columns(self): + def column_iterator(self, row): """ Number of columns in the xls sheet """ - return self._native_sheet.ncols() + for column in range(self._native_sheet.ncols()): + yield self.cell_value(row, column) def cell_value(self, row, column): cell = self._native_sheet.get_cell((row, column)) @@ -63,63 +65,34 @@ def cell_value(self, row, column): return ret -class ODSBook(BookReader): - """read a ods book out""" - - def open(self, file_name, **keywords): - """load ods from file""" - BookReader.open(self, file_name, **keywords) - self._load_from_file() - - def open_stream(self, file_stream, **keywords): - """load ods from file stream""" - BookReader.open_stream(self, file_stream, **keywords) - self._load_from_memory() - - def read_sheet_by_name(self, sheet_name): - """read a named sheet""" - rets = [ - sheet - for sheet in self._native_book.sheets - if sheet.name == sheet_name +class ODSBook(IReader): + def __init__(self, file_alike_object, file_type, **keywords): + self._native_book = ezodf.opendoc(file_alike_object) + self._keywords = keywords + self.content_array = [ + NameObject(sheet.name, sheet) for sheet in self._native_book.sheets ] - if len(rets) == 0: - raise ValueError("%s cannot be found" % sheet_name) - elif len(rets) == 1: - return self.read_sheet(rets[0]) - else: - raise ValueError( - "More than 1 sheet named as %s are found" % sheet_name - ) - - def read_sheet_by_index(self, sheet_index): - """read a sheet at an index""" - sheets = self._native_book.sheets - length = len(sheets) - if sheet_index < length: - return self.read_sheet(sheets[sheet_index]) - else: - raise IndexError( - "Index %d of out bound %d." % (sheet_index, length) - ) - - def read_all(self): - """read all available sheets""" - result = OrderedDict() - for sheet in self._native_book.sheets: - data_dict = self.read_sheet(sheet) - result.update(data_dict) - return result - - def read_sheet(self, native_sheet): + + def read_sheet(self, native_sheet_index): + native_sheet = self.content_array[native_sheet_index].sheet sheet = ODSSheet(native_sheet, **self._keywords) - return {native_sheet.name: sheet.to_array()} + return sheet def close(self): self._native_book = None - def _load_from_file(self): - self._native_book = ezodf.opendoc(self._file_name) - def _load_from_memory(self): - self._native_book = ezodf.opendoc(self._file_stream) +class ODSBookInContent(ODSBook): + """ + Open xlsx as read only mode + """ + + def __init__(self, file_content, file_type, **keywords): + io = BytesIO(file_content) + super().__init__(io, file_type, **keywords) + + +class NameObject(object): + def __init__(self, name, sheet): + self.name = name + self.sheet = sheet diff --git a/pyexcel_ods3/odsw.py b/pyexcel_ods3/odsw.py index 76a0ebe..85d638a 100644 --- a/pyexcel_ods3/odsw.py +++ b/pyexcel_ods3/odsw.py @@ -10,7 +10,6 @@ import types import ezodf - import pyexcel_io.service as service from pyexcel_io.book import BookWriter from pyexcel_io.sheet import SheetWriter diff --git a/tests/test_bug_fixes.py b/tests/test_bug_fixes.py index 925fdc2..218758a 100644 --- a/tests/test_bug_fixes.py +++ b/tests/test_bug_fixes.py @@ -4,10 +4,10 @@ import psutil import pyexcel as pe +from pyexcel_io.exceptions import IntegerAccuracyLossError from nose import SkipTest from nose.tools import eq_, raises -from pyexcel_io.exceptions import IntegerAccuracyLossError IN_TRAVIS = "TRAVIS" in os.environ diff --git a/tests/test_filter.py b/tests/test_filter.py index 1031451..376d6fc 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -1,8 +1,9 @@ import os -from nose.tools import eq_ from pyexcel_io import get_data, save_data +from nose.tools import eq_ + class TestFilter: def setUp(self): diff --git a/tests/test_ods_reader.py b/tests/test_ods_reader.py index e1dc898..8716578 100644 --- a/tests/test_ods_reader.py +++ b/tests/test_ods_reader.py @@ -7,8 +7,7 @@ class TestODSReader(ODSCellTypes): def setUp(self): - r = ODSBook() - r.open(os.path.join("tests", "fixtures", "ods_formats.ods")) + r = ODSBook(os.path.join("tests", "fixtures", "ods_formats.ods"), 'ods') self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) @@ -17,9 +16,9 @@ def setUp(self): class TestODSWriter(ODSCellTypes): def setUp(self): - r = ODSBook() - r.open( + r = ODSBook( os.path.join("tests", "fixtures", "ods_formats.ods"), + 'ods', skip_empty_rows=True, ) self.data1 = r.read_all() @@ -28,8 +27,7 @@ def setUp(self): w.open(self.testfile) w.write(self.data1) w.close() - r2 = ODSBook() - r2.open(self.testfile) + r2 = ODSBook(self.testfile, 'ods') self.data = r2.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) diff --git a/tests/test_writer.py b/tests/test_writer.py index 93d5efb..b8ec312 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -17,8 +17,7 @@ def test_write_book(self): writer.open(self.testfile) writer.write(self.content) writer.close() - reader = Reader() - reader.open(self.testfile) + reader = Reader(self.testfile, 'ods') content = reader.read_all() for key in content.keys(): content[key] = list(content[key]) From fa79bee6e32c1954e9b99d70a63a2c815acc875a Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 3 Oct 2020 10:17:35 +0100 Subject: [PATCH 02/13] :tada: new style ods writer --- pyexcel_ods3/__init__.py | 14 +++++++------- pyexcel_ods3/odsw.py | 30 ++++++++++++------------------ tests/test_ods_reader.py | 3 +-- tests/test_writer.py | 3 +-- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/pyexcel_ods3/__init__.py b/pyexcel_ods3/__init__.py index 753a381..1c01207 100644 --- a/pyexcel_ods3/__init__.py +++ b/pyexcel_ods3/__init__.py @@ -18,20 +18,20 @@ from pyexcel_io.plugins import IOPluginInfoChain, IOPluginInfoChainV2 __FILE_TYPE__ = "ods" -IOPluginInfoChain(__name__).add_a_writer( - relative_plugin_class_path="odsw.ODSWriter", - file_types=[__FILE_TYPE__], - stream_type="binary", -) IOPluginInfoChainV2(__name__).add_a_reader( relative_plugin_class_path="odsr.ODSBook", locations=["file", "memory"], - file_types=[__FILE_TYPE__, 'fods'], + file_types=[__FILE_TYPE__], stream_type="binary", ).add_a_reader( relative_plugin_class_path="odsr.ODSBookInContent", locations=["content"], - file_types=[__FILE_TYPE__, 'fods'], + file_types=[__FILE_TYPE__], + stream_type="binary", +).add_a_writer( + relative_plugin_class_path="odsw.ODSWriter", + locations=["file", "memory"], + file_types=[__FILE_TYPE__], stream_type="binary", ) diff --git a/pyexcel_ods3/odsw.py b/pyexcel_ods3/odsw.py index 85d638a..e6bacc7 100644 --- a/pyexcel_ods3/odsw.py +++ b/pyexcel_ods3/odsw.py @@ -11,22 +11,22 @@ import ezodf import pyexcel_io.service as service -from pyexcel_io.book import BookWriter -from pyexcel_io.sheet import SheetWriter from pyexcel_io.constants import MAX_INTEGER from pyexcel_io.exceptions import IntegerAccuracyLossError +from pyexcel_io.plugin_api.abstract_writer import IWriter +from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter -class ODSSheetWriter(SheetWriter): +class ODSSheetWriter(ISheetWriter): """ ODS sheet writer """ - - def set_sheet_name(self, name): - self._native_sheet = ezodf.Sheet(name) + def __init__(self, ods_book, ods_sheet, sheet_name, **keywords): + self._native_book = ods_book + self._native_sheet = ezodf.Sheet(sheet_name) self.current_row = 0 - def set_size(self, size): + def _set_size(self, size): self._native_sheet.reset(size=size) def write_row(self, array): @@ -61,7 +61,7 @@ def write_array(self, table): if rows < 1: return columns = max([len(row) for row in to_write_data]) - self.set_size((rows, columns)) + self._set_size((rows, columns)) for row in to_write_data: self.write_row(row) @@ -73,25 +73,19 @@ def close(self): self._native_book.sheets += self._native_sheet -class ODSWriter(BookWriter): +class ODSWriter(IWriter): """ open document spreadsheet writer """ - def __init__(self): - BookWriter.__init__(self) - self._native_book = None - - def open(self, file_name, **keywords): + def __init__(self, file_alike_object, file_type, skip_backup=True, **keywords): """open a file for writing ods""" - BookWriter.open(self, file_name, **keywords) self._native_book = ezodf.newdoc( - doctype="ods", filename=self._file_alike_object + doctype=file_type, filename=file_alike_object ) - skip_backup_flag = self._keywords.get("skip_backup", True) - if skip_backup_flag: + if skip_backup: self._native_book.backup = False def create_sheet(self, name): diff --git a/tests/test_ods_reader.py b/tests/test_ods_reader.py index 8716578..c424b57 100644 --- a/tests/test_ods_reader.py +++ b/tests/test_ods_reader.py @@ -23,8 +23,7 @@ def setUp(self): ) self.data1 = r.read_all() self.testfile = "odswriter.ods" - w = ODSWriter() - w.open(self.testfile) + w = ODSWriter(self.testfile, 'ods') w.write(self.data1) w.close() r2 = ODSBook(self.testfile, 'ods') diff --git a/tests/test_writer.py b/tests/test_writer.py index b8ec312..a4ddb1c 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -13,8 +13,7 @@ def test_write_book(self): "Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]], } self.testfile = "writer.ods" - writer = Writer() - writer.open(self.testfile) + writer = Writer(self.testfile, 'ods') writer.write(self.content) writer.close() reader = Reader(self.testfile, 'ods') From b4b6dfd803241e878224c21c93a375ca42cd3faf Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 3 Oct 2020 10:18:35 +0100 Subject: [PATCH 03/13] :books: update changelog --- changelog.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog.yml b/changelog.yml index fcecf33..576a596 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,6 +1,12 @@ name: pyexcel-ods3 organisation: pyexcel releases: +- changes: + - action: added + details: + - 'new style reader and writer plugins. works with pyexcel-io v0.6.0' + date: 2020 + version: 0.6.0 - changes: - action: added details: From 167f1fc3b4b21c1eb40d77fc2b14965c1821a3ee Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 3 Oct 2020 09:19:05 +0000 Subject: [PATCH 04/13] This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst --- CHANGELOG.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4051698..9213781 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ Change log ================================================================================ +0.6.0 - 2020 +-------------------------------------------------------------------------------- + +**added** + +#. new style reader and writer plugins. works with pyexcel-io v0.6.0 + 0.5.3 - 27.11.2018 -------------------------------------------------------------------------------- From a774692c94e0562061602b9ae02fcf4bb2b039c4 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 3 Oct 2020 10:19:47 +0100 Subject: [PATCH 05/13] :lipstick: update coding style --- pyexcel_ods3/odsw.py | 7 +++++-- tests/test_ods_reader.py | 10 ++++++---- tests/test_writer.py | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pyexcel_ods3/odsw.py b/pyexcel_ods3/odsw.py index e6bacc7..183cd36 100644 --- a/pyexcel_ods3/odsw.py +++ b/pyexcel_ods3/odsw.py @@ -13,14 +13,15 @@ import pyexcel_io.service as service from pyexcel_io.constants import MAX_INTEGER from pyexcel_io.exceptions import IntegerAccuracyLossError -from pyexcel_io.plugin_api.abstract_writer import IWriter from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter +from pyexcel_io.plugin_api.abstract_writer import IWriter class ODSSheetWriter(ISheetWriter): """ ODS sheet writer """ + def __init__(self, ods_book, ods_sheet, sheet_name, **keywords): self._native_book = ods_book self._native_sheet = ezodf.Sheet(sheet_name) @@ -79,7 +80,9 @@ class ODSWriter(IWriter): """ - def __init__(self, file_alike_object, file_type, skip_backup=True, **keywords): + def __init__( + self, file_alike_object, file_type, skip_backup=True, **keywords + ): """open a file for writing ods""" self._native_book = ezodf.newdoc( doctype=file_type, filename=file_alike_object diff --git a/tests/test_ods_reader.py b/tests/test_ods_reader.py index c424b57..075bf5a 100644 --- a/tests/test_ods_reader.py +++ b/tests/test_ods_reader.py @@ -7,7 +7,9 @@ class TestODSReader(ODSCellTypes): def setUp(self): - r = ODSBook(os.path.join("tests", "fixtures", "ods_formats.ods"), 'ods') + r = ODSBook( + os.path.join("tests", "fixtures", "ods_formats.ods"), "ods" + ) self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) @@ -18,15 +20,15 @@ class TestODSWriter(ODSCellTypes): def setUp(self): r = ODSBook( os.path.join("tests", "fixtures", "ods_formats.ods"), - 'ods', + "ods", skip_empty_rows=True, ) self.data1 = r.read_all() self.testfile = "odswriter.ods" - w = ODSWriter(self.testfile, 'ods') + w = ODSWriter(self.testfile, "ods") w.write(self.data1) w.close() - r2 = ODSBook(self.testfile, 'ods') + r2 = ODSBook(self.testfile, "ods") self.data = r2.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) diff --git a/tests/test_writer.py b/tests/test_writer.py index a4ddb1c..8435a1f 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -13,10 +13,10 @@ def test_write_book(self): "Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]], } self.testfile = "writer.ods" - writer = Writer(self.testfile, 'ods') + writer = Writer(self.testfile, "ods") writer.write(self.content) writer.close() - reader = Reader(self.testfile, 'ods') + reader = Reader(self.testfile, "ods") content = reader.read_all() for key in content.keys(): content[key] = list(content[key]) From 633d87ad7da02d99a02dac47fd36b9f64227e6f1 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 3 Oct 2020 10:27:08 +0100 Subject: [PATCH 06/13] :green_heart: use pyexcel-io v0.6.0 in test --- rnd_requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rnd_requirements.txt b/rnd_requirements.txt index 0a8701a..a4748b0 100644 --- a/rnd_requirements.txt +++ b/rnd_requirements.txt @@ -1,2 +1 @@ -https://github.com/pyexcel/pyexcel-ezodf/archive/master.zip -https://github.com/pyexcel/pyexcel-io/archive/v0.5.10.zip +https://github.com/pyexcel/pyexcel-io/archive/dev.zip From 83be637f0a3a2874b2f310594b7f03122fc30964 Mon Sep 17 00:00:00 2001 From: chfw Date: Tue, 6 Oct 2020 23:28:55 +0100 Subject: [PATCH 07/13] :hammer: code refactoring --- pyexcel_ods3/odsr.py | 17 +++++------------ pyexcel_ods3/odsw.py | 5 ++--- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/pyexcel_ods3/odsr.py b/pyexcel_ods3/odsr.py index da1a011..4719a2f 100644 --- a/pyexcel_ods3/odsr.py +++ b/pyexcel_ods3/odsr.py @@ -11,17 +11,15 @@ import ezodf import pyexcel_io.service as service -from pyexcel_io.plugin_api.abstract_sheet import ISheet -from pyexcel_io.plugin_api.abstract_reader import IReader +from pyexcel_io.plugin_api import ISheet, IReader, NamedContent class ODSSheet(ISheet): """ODS sheet representation""" - def __init__(self, sheet, auto_detect_int=True, **keywords): + def __init__(self, sheet, auto_detect_int=True): self.auto_detect_int = auto_detect_int self._native_sheet = sheet - self._keywords = keywords @property def name(self): @@ -70,11 +68,12 @@ def __init__(self, file_alike_object, file_type, **keywords): self._native_book = ezodf.opendoc(file_alike_object) self._keywords = keywords self.content_array = [ - NameObject(sheet.name, sheet) for sheet in self._native_book.sheets + NameContent(sheet.name, sheet) + for sheet in self._native_book.sheets ] def read_sheet(self, native_sheet_index): - native_sheet = self.content_array[native_sheet_index].sheet + native_sheet = self.content_array[native_sheet_index].payload sheet = ODSSheet(native_sheet, **self._keywords) return sheet @@ -90,9 +89,3 @@ class ODSBookInContent(ODSBook): def __init__(self, file_content, file_type, **keywords): io = BytesIO(file_content) super().__init__(io, file_type, **keywords) - - -class NameObject(object): - def __init__(self, name, sheet): - self.name = name - self.sheet = sheet diff --git a/pyexcel_ods3/odsw.py b/pyexcel_ods3/odsw.py index 183cd36..d27749e 100644 --- a/pyexcel_ods3/odsw.py +++ b/pyexcel_ods3/odsw.py @@ -4,7 +4,7 @@ ods writer using ezodf - :copyright: (c) 2015-2017 by Onni Software Ltd. & its contributors + :copyright: (c) 2015-2020 by Onni Software Ltd. & its contributors :license: New BSD License """ import types @@ -13,8 +13,7 @@ import pyexcel_io.service as service from pyexcel_io.constants import MAX_INTEGER from pyexcel_io.exceptions import IntegerAccuracyLossError -from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter -from pyexcel_io.plugin_api.abstract_writer import IWriter +from pyexcel_io.plugin_api import IWriter, ISheetWriter class ODSSheetWriter(ISheetWriter): From 86b8e90a76968dd08b30a08979eaea6307a229ed Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 7 Oct 2020 08:10:19 +0100 Subject: [PATCH 08/13] :bug: fix typo --- pyexcel_ods3/odsr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyexcel_ods3/odsr.py b/pyexcel_ods3/odsr.py index 4719a2f..7961cf5 100644 --- a/pyexcel_ods3/odsr.py +++ b/pyexcel_ods3/odsr.py @@ -68,7 +68,7 @@ def __init__(self, file_alike_object, file_type, **keywords): self._native_book = ezodf.opendoc(file_alike_object) self._keywords = keywords self.content_array = [ - NameContent(sheet.name, sheet) + NamedContent(sheet.name, sheet) for sheet in self._native_book.sheets ] From 36f13e0cff7766eb2ee2221c96f1628731c263ed Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 7 Oct 2020 22:54:36 +0100 Subject: [PATCH 09/13] :hammer: code refactoring --- pyexcel-ods3.yml | 3 ++- pyexcel_ods3/odsr.py | 17 ++++++++--------- pyexcel_ods3/odsw.py | 20 ++++++++++---------- tests/test_ods_reader.py | 17 +++++++++-------- tests/test_writer.py | 6 ++---- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/pyexcel-ods3.yml b/pyexcel-ods3.yml index 9209539..4b7940c 100644 --- a/pyexcel-ods3.yml +++ b/pyexcel-ods3.yml @@ -15,4 +15,5 @@ test_dependencies: - psutil - pyexcel-xls description: | - A wrapper library to read, manipulate and write data in ods format \ No newline at end of file + A wrapper library to read, manipulate and write data in ods format +moban_command: false diff --git a/pyexcel_ods3/odsr.py b/pyexcel_ods3/odsr.py index 7961cf5..3250a7d 100644 --- a/pyexcel_ods3/odsr.py +++ b/pyexcel_ods3/odsr.py @@ -19,27 +19,27 @@ class ODSSheet(ISheet): def __init__(self, sheet, auto_detect_int=True): self.auto_detect_int = auto_detect_int - self._native_sheet = sheet + self.ods_sheet = sheet @property def name(self): - return self._native_sheet.name + return self.ods_sheet.name def row_iterator(self): """ Number of rows in the xls sheet """ - return range(self._native_sheet.nrows()) + return range(self.ods_sheet.nrows()) def column_iterator(self, row): """ Number of columns in the xls sheet """ - for column in range(self._native_sheet.ncols()): + for column in range(self.ods_sheet.ncols()): yield self.cell_value(row, column) def cell_value(self, row, column): - cell = self._native_sheet.get_cell((row, column)) + cell = self.ods_sheet.get_cell((row, column)) cell_type = cell.value_type ret = None if cell_type == "currency": @@ -65,11 +65,10 @@ def cell_value(self, row, column): class ODSBook(IReader): def __init__(self, file_alike_object, file_type, **keywords): - self._native_book = ezodf.opendoc(file_alike_object) + self.ods_book = ezodf.opendoc(file_alike_object) self._keywords = keywords self.content_array = [ - NamedContent(sheet.name, sheet) - for sheet in self._native_book.sheets + NamedContent(sheet.name, sheet) for sheet in self.ods_book.sheets ] def read_sheet(self, native_sheet_index): @@ -78,7 +77,7 @@ def read_sheet(self, native_sheet_index): return sheet def close(self): - self._native_book = None + self.ods_book = None class ODSBookInContent(ODSBook): diff --git a/pyexcel_ods3/odsw.py b/pyexcel_ods3/odsw.py index d27749e..474ca43 100644 --- a/pyexcel_ods3/odsw.py +++ b/pyexcel_ods3/odsw.py @@ -22,12 +22,12 @@ class ODSSheetWriter(ISheetWriter): """ def __init__(self, ods_book, ods_sheet, sheet_name, **keywords): - self._native_book = ods_book - self._native_sheet = ezodf.Sheet(sheet_name) + self.ods_book = ods_book + self.ods_sheet = ezodf.Sheet(sheet_name) self.current_row = 0 def _set_size(self, size): - self._native_sheet.reset(size=size) + self.ods_sheet.reset(size=size) def write_row(self, array): """ @@ -47,7 +47,7 @@ def write_row(self, array): elif value_type == "float": if cell > MAX_INTEGER: raise IntegerAccuracyLossError("%s is too big" % cell) - self._native_sheet[self.current_row, count].set_value( + self.ods_sheet[self.current_row, count].set_value( cell, value_type=value_type ) count += 1 @@ -70,7 +70,7 @@ def close(self): This call writes file """ - self._native_book.sheets += self._native_sheet + self.ods_book.sheets += self.ods_sheet class ODSWriter(IWriter): @@ -83,23 +83,23 @@ def __init__( self, file_alike_object, file_type, skip_backup=True, **keywords ): """open a file for writing ods""" - self._native_book = ezodf.newdoc( + self.ods_book = ezodf.newdoc( doctype=file_type, filename=file_alike_object ) if skip_backup: - self._native_book.backup = False + self.ods_book.backup = False def create_sheet(self, name): """ write a row into the file """ - return ODSSheetWriter(self._native_book, None, name) + return ODSSheetWriter(self.ods_book, None, name) def close(self): """ This call writes file """ - self._native_book.save() - self._native_book = None + self.ods_book.save() + self.ods_book = None diff --git a/tests/test_ods_reader.py b/tests/test_ods_reader.py index 075bf5a..8e95cb8 100644 --- a/tests/test_ods_reader.py +++ b/tests/test_ods_reader.py @@ -1,15 +1,14 @@ import os from base import ODSCellTypes -from pyexcel_ods3.odsr import ODSBook +from pyexcel_io.reader import Reader from pyexcel_ods3.odsw import ODSWriter class TestODSReader(ODSCellTypes): def setUp(self): - r = ODSBook( - os.path.join("tests", "fixtures", "ods_formats.ods"), "ods" - ) + r = Reader("ods") + r.open(os.path.join("tests", "fixtures", "ods_formats.ods")) self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) @@ -18,20 +17,22 @@ def setUp(self): class TestODSWriter(ODSCellTypes): def setUp(self): - r = ODSBook( + r = Reader("ods") + r.open( os.path.join("tests", "fixtures", "ods_formats.ods"), - "ods", skip_empty_rows=True, ) self.data1 = r.read_all() + r.close() self.testfile = "odswriter.ods" w = ODSWriter(self.testfile, "ods") w.write(self.data1) w.close() - r2 = ODSBook(self.testfile, "ods") - self.data = r2.read_all() + r.open(self.testfile) + self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) + r.close() def tearDown(self): if os.path.exists(self.testfile): diff --git a/tests/test_writer.py b/tests/test_writer.py index 8435a1f..739515c 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -1,7 +1,7 @@ import os from base import PyexcelWriterBase, PyexcelHatWriterBase -from pyexcel_ods3.odsr import ODSBook as Reader +from pyexcel_ods3 import get_data from pyexcel_ods3.odsw import ODSWriter as Writer @@ -16,12 +16,10 @@ def test_write_book(self): writer = Writer(self.testfile, "ods") writer.write(self.content) writer.close() - reader = Reader(self.testfile, "ods") - content = reader.read_all() + content = get_data(self.testfile) for key in content.keys(): content[key] = list(content[key]) assert content == self.content - reader.close() def tearDown(self): if os.path.exists(self.testfile): From 209fabcd051b877e130fce354b93110384a0f774 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 7 Oct 2020 21:55:05 +0000 Subject: [PATCH 10/13] This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst --- .travis.yml | 11 ----------- docs/source/conf.py | 3 ++- setup.py | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index b457dd1..9cb4e91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ python: stages: - lint - - moban - test @@ -23,16 +22,6 @@ stages: stage: lint script: make lint -.moban: &moban - python: 3.6 - env: - - MINREQ=0 - stage: moban - install: pip install moban gitfs2 pypifs moban-jinja2-github moban-ansible - script: - - moban - - git diff --exit-code - jobs: include: - *moban diff --git a/docs/source/conf.py b/docs/source/conf.py index 24a1fe9..596caef 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- DESCRIPTION = ( - 'A wrapper library to read, manipulate and write data in ods format' + + 'A wrapper library to read, manipulate and write data in ods format +' + '' ) # Configuration file for the Sphinx documentation builder. diff --git a/setup.py b/setup.py index 70c2fc8..742a368 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ EMAIL = "info@pyexcel.org" LICENSE = "New BSD" DESCRIPTION = ( - "A wrapper library to read, manipulate and write data in ods format" + "A wrapper library to read, manipulate and write data in ods format " ) URL = "https://github.com/pyexcel/pyexcel-ods3" DOWNLOAD_URL = "%s/archive/0.5.3.tar.gz" % URL From 8ff646b37389920ae8168514de4b55a46d782313 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 7 Oct 2020 23:12:51 +0100 Subject: [PATCH 11/13] :green_heart: update merge problem --- pyexcel-ods3.yml | 2 +- pyexcel_ods3/odsr.py | 1 - pyexcel_ods3/odsw.py | 22 ---------------------- 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/pyexcel-ods3.yml b/pyexcel-ods3.yml index 4b7940c..02edb32 100644 --- a/pyexcel-ods3.yml +++ b/pyexcel-ods3.yml @@ -14,6 +14,6 @@ test_dependencies: - pyexcel - psutil - pyexcel-xls +moban_command: false description: | A wrapper library to read, manipulate and write data in ods format -moban_command: false diff --git a/pyexcel_ods3/odsr.py b/pyexcel_ods3/odsr.py index 4996a32..3250a7d 100644 --- a/pyexcel_ods3/odsr.py +++ b/pyexcel_ods3/odsr.py @@ -80,7 +80,6 @@ def close(self): self.ods_book = None - class ODSBookInContent(ODSBook): """ Open xlsx as read only mode diff --git a/pyexcel_ods3/odsw.py b/pyexcel_ods3/odsw.py index 1d2f50c..474ca43 100644 --- a/pyexcel_ods3/odsw.py +++ b/pyexcel_ods3/odsw.py @@ -13,12 +13,7 @@ import pyexcel_io.service as service from pyexcel_io.constants import MAX_INTEGER from pyexcel_io.exceptions import IntegerAccuracyLossError -<<<<<<< HEAD from pyexcel_io.plugin_api import IWriter, ISheetWriter -======= -from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter -from pyexcel_io.plugin_api.abstract_writer import IWriter ->>>>>>> dev class ODSSheetWriter(ISheetWriter): @@ -27,21 +22,12 @@ class ODSSheetWriter(ISheetWriter): """ def __init__(self, ods_book, ods_sheet, sheet_name, **keywords): -<<<<<<< HEAD self.ods_book = ods_book self.ods_sheet = ezodf.Sheet(sheet_name) self.current_row = 0 def _set_size(self, size): self.ods_sheet.reset(size=size) -======= - self._native_book = ods_book - self._native_sheet = ezodf.Sheet(sheet_name) - self.current_row = 0 - - def _set_size(self, size): - self._native_sheet.reset(size=size) ->>>>>>> dev def write_row(self, array): """ @@ -97,20 +83,12 @@ def __init__( self, file_alike_object, file_type, skip_backup=True, **keywords ): """open a file for writing ods""" -<<<<<<< HEAD self.ods_book = ezodf.newdoc( -======= - self._native_book = ezodf.newdoc( ->>>>>>> dev doctype=file_type, filename=file_alike_object ) if skip_backup: -<<<<<<< HEAD self.ods_book.backup = False -======= - self._native_book.backup = False ->>>>>>> dev def create_sheet(self, name): """ From 7e75ace8cbe5829b2093767a3d5f0c354ca63ccf Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 7 Oct 2020 23:15:21 +0100 Subject: [PATCH 12/13] :green_heart: update conf.py --- docs/source/conf.py | 3 +-- pyexcel-ods3.yml | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 596caef..24a1fe9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- DESCRIPTION = ( - 'A wrapper library to read, manipulate and write data in ods format -' + + 'A wrapper library to read, manipulate and write data in ods format' + '' ) # Configuration file for the Sphinx documentation builder. diff --git a/pyexcel-ods3.yml b/pyexcel-ods3.yml index 02edb32..de6d545 100644 --- a/pyexcel-ods3.yml +++ b/pyexcel-ods3.yml @@ -15,5 +15,5 @@ test_dependencies: - psutil - pyexcel-xls moban_command: false -description: | +description: |- A wrapper library to read, manipulate and write data in ods format diff --git a/setup.py b/setup.py index 742a368..70c2fc8 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ EMAIL = "info@pyexcel.org" LICENSE = "New BSD" DESCRIPTION = ( - "A wrapper library to read, manipulate and write data in ods format " + "A wrapper library to read, manipulate and write data in ods format" ) URL = "https://github.com/pyexcel/pyexcel-ods3" DOWNLOAD_URL = "%s/archive/0.5.3.tar.gz" % URL From e69589d32d77b194cc5a589aacb5d158c37723d4 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 7 Oct 2020 23:19:28 +0100 Subject: [PATCH 13/13] :green_heart: fix unit test --- tests/test_ods_reader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_ods_reader.py b/tests/test_ods_reader.py index 234f8dd..d32cd01 100644 --- a/tests/test_ods_reader.py +++ b/tests/test_ods_reader.py @@ -20,7 +20,6 @@ def setUp(self): r = Reader("ods") r.open( os.path.join("tests", "fixtures", "ods_formats.ods"), - "ods", skip_empty_rows=True, ) self.data1 = r.read_all()