Skip to content

Code refinement #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
With your PR, here is a check list:

- [ ] Has Test cases written
- [ ] Has all code lines tested
- [ ] Has test cases written?
- [ ] Has all code lines tested?
- [ ] Has `make format` been run?
- [ ] Please update CHANGELOG.yml(not CHANGELOG.rst)
- [ ] Passes all Travis CI builds
- [ ] Has fair amount of documentation if your change is complex
- [ ] run 'make format' so as to confirm the pyexcel organisation's coding style
- [ ] Please add yourself to 'contributors' section of pyexcel-io.yml (if not found, please use CONTRIBUTORS.rst)
- [ ] Agree on NEW BSD License for your contribution
1 change: 0 additions & 1 deletion pyexcel_io/_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def emit(self, record):
from io import BytesIO, StringIO

text_type = str
Iterator = object
irange = range


Expand Down
2 changes: 1 addition & 1 deletion pyexcel_io/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Constants appeared in pyexcel

:copyright: (c) 2014-2019 by Onni Software Ltd.
:copyright: (c) 2014-2020 by Onni Software Ltd.
:license: New BSD License
"""
# flake8: noqa
Expand Down
4 changes: 2 additions & 2 deletions pyexcel_io/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
:copyright: (c) 2014-2020 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
from pyexcel_io.plugins import NewIOPluginInfoChain
from pyexcel_io.plugins import IOPluginInfoChainV2
from pyexcel_io.constants import DB_SQL, DB_DJANGO, DB_QUERYSET

NewIOPluginInfoChain(__name__).add_a_reader(
IOPluginInfoChainV2(__name__).add_a_reader(
relative_plugin_class_path="exporters.queryset.QueryReader",
locations=["file", "memory", "content"],
file_types=[DB_QUERYSET],
Expand Down
6 changes: 3 additions & 3 deletions pyexcel_io/database/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from itertools import chain

from pyexcel_io.constants import DEFAULT_SHEET_NAME
from pyexcel_io.plugin_api.abstract_sheet import Sheet
from pyexcel_io.plugin_api.abstract_sheet import ISheet


class QuerysetsReader(Sheet):
class QuerysetsReader(ISheet):
""" turn querysets into an array """

def __init__(self, query_sets, column_names):
Expand All @@ -32,7 +32,7 @@ def to_array(self):
if len(self.__query_sets) == 0:
yield []

for element in Sheet.to_array(self):
for element in ISheet.to_array(self):
yield element

def column_iterator(self, row):
Expand Down
2 changes: 1 addition & 1 deletion pyexcel_io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The io interface to file extensions

:copyright: (c) 2014-2019 by Onni Software Ltd.
:copyright: (c) 2014-2020 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
import os
Expand Down
2 changes: 1 addition & 1 deletion pyexcel_io/plugin_api/abstract_sheet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Sheet(object):
class ISheet(object):
def to_array(self):
data = []
for row in self.row_iterator():
Expand Down
14 changes: 7 additions & 7 deletions pyexcel_io/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
UPGRADE_MESSAGE = "Please upgrade the plugin '%s' according to \
plugin compactibility table."
READER_PLUGIN = "pyexcel-io reader"
NEW_READER_PLUGIN = "pyexcel-io new reader"
READER_PLUGIN_V2 = "pyexcel-io v2 reader"
WRITER_PLUGIN = "pyexcel-io writer"
NEW_WRITER_PLUGIN = "pyexcel-io new writer"
WRITER_PLUGIN_V2 = "pyexcel-io v2 writer"


class IOPluginInfo(PluginInfo):
Expand Down Expand Up @@ -65,7 +65,7 @@ def add_a_writer(
return self.add_a_plugin_instance(a_plugin_info)


class NewIOPluginInfoChain(PluginInfoChain):
class IOPluginInfoChainV2(PluginInfoChain):
"""provide custom functions to add a reader and a writer """

def add_a_reader(
Expand All @@ -77,7 +77,7 @@ def add_a_reader(
):
""" add pyexcle-io reader plugin info """
a_plugin_info = IOPluginInfo(
NEW_READER_PLUGIN,
READER_PLUGIN_V2,
self._get_abs_path(relative_plugin_class_path),
file_types=[
f"{location}-{file_type}"
Expand All @@ -97,7 +97,7 @@ def add_a_writer(
):
""" add pyexcle-io writer plugin info """
a_plugin_info = IOPluginInfo(
NEW_WRITER_PLUGIN,
WRITER_PLUGIN_V2,
self._get_abs_path(relative_plugin_class_path),
file_types=[
f"{location}-{file_type}"
Expand Down Expand Up @@ -243,8 +243,8 @@ def get_all_formats(self):

OLD_READERS = IOManager(READER_PLUGIN, ioutils.AVAILABLE_READERS)
OLD_WRITERS = IOManager(WRITER_PLUGIN, ioutils.AVAILABLE_WRITERS)
NEW_WRITERS = NewIOManager(NEW_WRITER_PLUGIN, ioutils.AVAILABLE_WRITERS)
NEW_READERS = NewIOManager(NEW_READER_PLUGIN, ioutils.AVAILABLE_READERS)
NEW_WRITERS = NewIOManager(WRITER_PLUGIN_V2, ioutils.AVAILABLE_WRITERS)
NEW_READERS = NewIOManager(READER_PLUGIN_V2, ioutils.AVAILABLE_READERS)
READERS = AllReaders()
WRITERS = AllWriters()

Expand Down
4 changes: 2 additions & 2 deletions pyexcel_io/readers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
:copyright: (c) 2014-2020 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
from pyexcel_io.plugins import NewIOPluginInfoChain
from pyexcel_io.plugins import IOPluginInfoChainV2

NewIOPluginInfoChain(__name__).add_a_reader(
IOPluginInfoChainV2(__name__).add_a_reader(
relative_plugin_class_path="csv_in_file.FileReader",
locations=["file"],
file_types=["csv", "tsv"],
Expand Down
11 changes: 5 additions & 6 deletions pyexcel_io/readers/csv_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pyexcel_io.service as service
import pyexcel_io._compact as compact
import pyexcel_io.constants as constants
from pyexcel_io.sheet import SheetReader
from pyexcel_io.plugin_api.abstract_sheet import ISheet

DEFAULT_SEPARATOR = "__"
DEFAULT_SHEET_SEPARATOR_FORMATTER = "---%s---" % constants.DEFAULT_NAME + "%s"
Expand All @@ -27,7 +27,7 @@
BIG_ENDIAN = 1


class CSVMemoryMapIterator(compact.Iterator):
class CSVMemoryMapIterator(object):
"""
Wrapper class for mmap object

Expand All @@ -52,7 +52,7 @@ def __init__(self, mmap_obj, encoding):
# \r\x00\x00\x00\n
# \x00\x00\x00\x..
self.__zeros_left_in_2_row = 3
elif encoding == "utf-32-be" or encoding == "utf-16-be":
elif encoding in ["utf-32-be", "utf-16-be"]:
self.__zeros_left_in_2_row = 0
self.__endian = BIG_ENDIAN
elif encoding == "utf-32-le":
Expand Down Expand Up @@ -92,7 +92,7 @@ def close(self):
pass


class CSVSheetReader(SheetReader):
class CSVSheetReader(ISheet):
""" generic csv file reader"""

def __init__(
Expand All @@ -108,9 +108,7 @@ def __init__(
default_float_nan=None,
**keywords
):
SheetReader.__init__(self, sheet, **keywords)
self._native_sheet = sheet
self._keywords = keywords
self._encoding = encoding
self.__auto_detect_int = auto_detect_int
self.__auto_detect_float = auto_detect_float
Expand All @@ -120,6 +118,7 @@ def __init__(
self.__pep_0515_off = pep_0515_off
self.__ignore_nan_text = ignore_nan_text
self.__default_float_nan = default_float_nan
self._keywords = keywords

def get_file_handle(self):
""" return me unicde reader for csv """
Expand Down
4 changes: 2 additions & 2 deletions pyexcel_io/writers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
:copyright: (c) 2014-2020 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
from pyexcel_io.plugins import NewIOPluginInfoChain
from pyexcel_io.plugins import IOPluginInfoChainV2

NewIOPluginInfoChain(__name__).add_a_writer(
IOPluginInfoChainV2(__name__).add_a_writer(
relative_plugin_class_path="csv_in_file.CsvFileWriter",
locations=["file", "content"],
file_types=["csv", "tsv"],
Expand Down
5 changes: 4 additions & 1 deletion tests/test_csv_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pyexcel_io.manager as manager
from pyexcel_io.sheet import NamedContent
from pyexcel_io.reader import EncapsulatedSheetReader
from pyexcel_io._compact import BytesIO, StringIO
from pyexcel_io.readers.csv_sheet import (
CSVFileReader,
Expand Down Expand Up @@ -108,7 +109,9 @@ def setUp(self):
f.write(",".join(row) + "\n")

def test_sheet_file_reader(self):
r = CSVFileReader(NamedContent(self.file_type, self.test_file))
r = EncapsulatedSheetReader(
CSVFileReader(NamedContent(self.file_type, self.test_file))
)
result = list(r.to_array())
self.assertEqual(result, [[1], [4, 5, 6], ["", 7]])

Expand Down