plugin and writer interfaces update (#79)
* 🚜 update new io plugin adder * 🔨 interface update * This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst Co-authored-by: chfw <chfw@users.noreply.github.com>
This commit is contained in:
parent
9fa3f4051e
commit
093c937773
3
lint.sh
3
lint.sh
|
@ -1,3 +1,2 @@
|
|||
pip install flake8
|
||||
flake8 . --exclude=.moban.d,docs,setup.py --builtins=unicode,xrange,long
|
||||
python setup.py checkdocs
|
||||
flake8 . --exclude=.moban.d,docs,setup.py --builtins=unicode,xrange,long && python setup.py checkdocs
|
||||
|
|
|
@ -12,15 +12,7 @@ from pyexcel_io.constants import DB_SQL, DB_DJANGO
|
|||
|
||||
NewIOPluginInfoChain(__name__).add_a_reader(
|
||||
relative_plugin_class_path="exporters.django.DjangoBookReader",
|
||||
location="file",
|
||||
file_types=[DB_DJANGO],
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="exporters.django.DjangoBookReader",
|
||||
location="memory",
|
||||
file_types=[DB_DJANGO],
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="exporters.django.DjangoBookReader",
|
||||
location="content",
|
||||
locations=["file", "memory", "content"],
|
||||
file_types=[DB_DJANGO],
|
||||
).add_a_writer(
|
||||
relative_plugin_class_path="importers.django.DjangoBookWriter",
|
||||
|
@ -28,15 +20,7 @@ NewIOPluginInfoChain(__name__).add_a_reader(
|
|||
file_types=[DB_DJANGO],
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="exporters.sqlalchemy.SQLBookReader",
|
||||
location="file",
|
||||
file_types=[DB_SQL],
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="exporters.sqlalchemy.SQLBookReader",
|
||||
location="memory",
|
||||
file_types=[DB_SQL],
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="exporters.sqlalchemy.SQLBookReader",
|
||||
location="content",
|
||||
locations=["file", "memory", "content"],
|
||||
file_types=[DB_SQL],
|
||||
).add_a_writer(
|
||||
relative_plugin_class_path="importers.sqlalchemy.SQLBookWriter",
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
import logging
|
||||
|
||||
import pyexcel_io.constants as constants
|
||||
from pyexcel_io.book import BookWriter
|
||||
from pyexcel_io.sheet import SheetWriter
|
||||
from pyexcel_io.utils import is_empty_array, swap_empty_string_for_none
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
:license: New BSD License, see LICENSE for more details
|
||||
"""
|
||||
import pyexcel_io.constants as constants
|
||||
from pyexcel_io.book import BookWriter
|
||||
from pyexcel_io.sheet import SheetWriter
|
||||
from pyexcel_io.utils import is_empty_array, swap_empty_string_for_none
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class NewIOPluginInfoChain(PluginInfoChain):
|
|||
def add_a_reader(
|
||||
self,
|
||||
relative_plugin_class_path=None,
|
||||
location="file",
|
||||
locations=(),
|
||||
file_types=None,
|
||||
stream_type=None,
|
||||
):
|
||||
|
@ -79,7 +79,11 @@ class NewIOPluginInfoChain(PluginInfoChain):
|
|||
a_plugin_info = IOPluginInfo(
|
||||
NEW_READER_PLUGIN,
|
||||
self._get_abs_path(relative_plugin_class_path),
|
||||
file_types=[f"{location}-{file_type}" for file_type in file_types],
|
||||
file_types=[
|
||||
f"{location}-{file_type}"
|
||||
for file_type in file_types
|
||||
for location in locations
|
||||
],
|
||||
stream_type=stream_type,
|
||||
)
|
||||
return self.add_a_plugin_instance(a_plugin_info)
|
||||
|
|
|
@ -11,52 +11,42 @@ from pyexcel_io.plugins import NewIOPluginInfoChain
|
|||
|
||||
NewIOPluginInfoChain(__name__).add_a_reader(
|
||||
relative_plugin_class_path="csv_in_file.FileReader",
|
||||
location="file",
|
||||
locations=["file"],
|
||||
file_types=["csv"],
|
||||
stream_type="text",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="csv_content.ContentReader",
|
||||
location="content",
|
||||
locations=["content"],
|
||||
file_types=["csv"],
|
||||
stream_type="text",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="csv_in_memory.MemoryReader",
|
||||
location="memory",
|
||||
locations=["memory"],
|
||||
file_types=["csv"],
|
||||
stream_type="text",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="tsv.TSVMemoryReader",
|
||||
location="memory",
|
||||
locations=["memory"],
|
||||
file_types=["tsv"],
|
||||
stream_type="text",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="tsv.TSVFileReader",
|
||||
location="file",
|
||||
locations=["file"],
|
||||
file_types=["tsv"],
|
||||
stream_type="text",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="tsv.TSVContentReader",
|
||||
location="content",
|
||||
locations=["content"],
|
||||
file_types=["tsv"],
|
||||
stream_type="text",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="csvz.FileReader",
|
||||
file_types=["csvz"],
|
||||
location="file",
|
||||
stream_type="binary",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="csvz.FileReader",
|
||||
file_types=["csvz"],
|
||||
location="memory",
|
||||
locations=["file", "memory"],
|
||||
stream_type="binary",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="tsvz.TSVZipFileReader",
|
||||
file_types=["tsvz"],
|
||||
location="file",
|
||||
stream_type="binary",
|
||||
).add_a_reader(
|
||||
relative_plugin_class_path="tsvz.TSVZipFileReader",
|
||||
file_types=["tsvz"],
|
||||
location="memory",
|
||||
locations=["file", "memory"],
|
||||
stream_type="binary",
|
||||
)
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
from pyexcel_io.plugins import NEW_WRITERS
|
||||
from pyexcel_io._compact import isstream
|
||||
|
||||
from .constants import MESSAGE_ERROR_03
|
||||
|
||||
|
||||
class Writer(object):
|
||||
|
@ -31,13 +28,7 @@ class Writer(object):
|
|||
self.writer = writer_class(file_stream, **keywords)
|
||||
|
||||
def write(self, incoming_dict):
|
||||
for sheet_name in incoming_dict:
|
||||
sheet_writer = self.writer.create_sheet(sheet_name)
|
||||
if sheet_writer:
|
||||
sheet_writer.write_array(incoming_dict[sheet_name])
|
||||
sheet_writer.close()
|
||||
else:
|
||||
raise Exception("Cannot create a sheet writer!")
|
||||
self.writer.write(incoming_dict)
|
||||
|
||||
def close(self):
|
||||
self.writer.close()
|
||||
|
|
|
@ -18,6 +18,15 @@ class CsvFileWriter:
|
|||
self.__index = self.__index + 1
|
||||
return self.writer
|
||||
|
||||
def write(self, incoming_dict):
|
||||
for sheet_name in incoming_dict:
|
||||
sheet_writer = self.create_sheet(sheet_name)
|
||||
if sheet_writer:
|
||||
sheet_writer.write_array(incoming_dict[sheet_name])
|
||||
sheet_writer.close()
|
||||
else:
|
||||
raise Exception("Cannot create a sheet writer!")
|
||||
|
||||
def close(self):
|
||||
if self.writer:
|
||||
self.writer.close()
|
||||
|
|
|
@ -18,5 +18,14 @@ class CsvMemoryWriter:
|
|||
self.__index = self.__index + 1
|
||||
return writer
|
||||
|
||||
def write(self, incoming_dict):
|
||||
for sheet_name in incoming_dict:
|
||||
sheet_writer = self.create_sheet(sheet_name)
|
||||
if sheet_writer:
|
||||
sheet_writer.write_array(incoming_dict[sheet_name])
|
||||
sheet_writer.close()
|
||||
else:
|
||||
raise Exception("Cannot create a sheet writer!")
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
|
|
@ -27,6 +27,15 @@ class CsvZipWriter(object):
|
|||
)
|
||||
return writer
|
||||
|
||||
def write(self, incoming_dict):
|
||||
for sheet_name in incoming_dict:
|
||||
sheet_writer = self.create_sheet(sheet_name)
|
||||
if sheet_writer:
|
||||
sheet_writer.write_array(incoming_dict[sheet_name])
|
||||
sheet_writer.close()
|
||||
else:
|
||||
raise Exception("Cannot create a sheet writer!")
|
||||
|
||||
def close(self):
|
||||
if self.zipfile:
|
||||
self.zipfile.close()
|
||||
|
|
|
@ -6,7 +6,6 @@ from pyexcel_io.book import (
|
|||
)
|
||||
from pyexcel_io._compact import BytesIO, StringIO
|
||||
|
||||
from nose import SkipTest
|
||||
from nose.tools import raises
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue