diff --git a/Makefile b/Makefile index b857377..48ac0a6 100644 --- a/Makefile +++ b/Makefile @@ -7,13 +7,12 @@ document: sphinx-autogen -o docs/source/generated/ docs/source/*.rst sphinx-build -b html docs/source/ docs/build/ -<<<<<<< HEAD format: isort -y $(find pyexcel_io -name "*.py"|xargs echo) $(find tests -name "*.py"|xargs echo) black -l 79 pyexcel_io black -l 79 tests -======= + lint: bash lint.sh ->>>>>>> master + diff --git a/docs/source/conf.py b/docs/source/conf.py index 21c4baf..37c4e22 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -69,4 +69,4 @@ # -- Options for intersphinx extension --------------------------------------- # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://docs.python.org/': None} \ No newline at end of file +intersphinx_mapping = {'https://docs.python.org/': None} diff --git a/pyexcel_io/__init__.py b/pyexcel_io/__init__.py index b50c3e3..3362892 100644 --- a/pyexcel_io/__init__.py +++ b/pyexcel_io/__init__.py @@ -8,12 +8,13 @@ :license: New BSD License, see LICENSE for more details """ import logging -from ._compact import NullHandler -logging.getLogger(__name__).addHandler(NullHandler()) # noqa +import pyexcel_io.plugins as plugins from .io import get_data, iget_data, save_data # noqa -import pyexcel_io.plugins as plugins +from ._compact import NullHandler + +logging.getLogger(__name__).addHandler(NullHandler()) # noqa BLACK_LIST = [__name__, "pyexcel_webio", "pyexcel_text"] @@ -25,7 +26,5 @@ PREFIX_PATTERN = "^pyexcel_.*$" plugins.load_plugins( - PREFIX_PATTERN, - __path__, # noqa: F821 - BLACK_LIST, - WHITE_LIST) + PREFIX_PATTERN, __path__, BLACK_LIST, WHITE_LIST # noqa: F821 +) diff --git a/pyexcel_io/book.py b/pyexcel_io/book.py index 21db709..5eb3072 100644 --- a/pyexcel_io/book.py +++ b/pyexcel_io/book.py @@ -9,6 +9,7 @@ """ import pyexcel_io.manager as manager from pyexcel_io._compact import PY2, OrderedDict, isstream + from .constants import MESSAGE_ERROR_03, MESSAGE_WRONG_IO_INSTANCE diff --git a/pyexcel_io/database/__init__.py b/pyexcel_io/database/__init__.py index e015023..addf50d 100644 --- a/pyexcel_io/database/__init__.py +++ b/pyexcel_io/database/__init__.py @@ -8,8 +8,7 @@ :license: New BSD License, see LICENSE for more details """ from pyexcel_io.plugins import IOPluginInfoChain -from pyexcel_io.constants import DB_DJANGO, DB_SQL - +from pyexcel_io.constants import DB_SQL, DB_DJANGO IOPluginInfoChain(__name__).add_a_reader( relative_plugin_class_path="exporters.django.DjangoBookReader", diff --git a/pyexcel_io/exceptions.py b/pyexcel_io/exceptions.py index a971cb0..458ad2c 100644 --- a/pyexcel_io/exceptions.py +++ b/pyexcel_io/exceptions.py @@ -46,11 +46,13 @@ class IntegerAccuracyLossError(Exception): b=get_sheet(file_name='abc.ods') b[0,0] != s[0,0] """ + def __init__(self, message): custom_message = ( - message + '\n' + - "In order to keep its accuracy, please save as string. Then " + - "convert to int, long or float after the value will be read back" + message + + "\n" + + "In order to keep its accuracy, please save as string. Then " + + "convert to int, long or float after the value will be read back" ) super(IntegerAccuracyLossError, self).__init__(custom_message) diff --git a/pyexcel_io/io.py b/pyexcel_io/io.py index c02ab77..73646d1 100644 --- a/pyexcel_io/io.py +++ b/pyexcel_io/io.py @@ -11,8 +11,9 @@ import warnings from types import GeneratorType -from pyexcel_io._compact import isstream, PY2 +from pyexcel_io import constants from pyexcel_io.plugins import READERS, WRITERS +from pyexcel_io._compact import PY2, isstream from pyexcel_io.exceptions import NoSupportingPluginFound @@ -124,7 +125,7 @@ def save_data(afile, data, file_type=None, **keywords): keywords.update(dict(file_stream=afile, file_type=file_type)) else: keywords.update(dict(file_name=afile, file_type=file_type)) - keywords['single_sheet_in_book'] = single_sheet_in_book + keywords["single_sheet_in_book"] = single_sheet_in_book with get_writer(**keywords) as writer: writer.write(to_store) diff --git a/pyexcel_io/plugins.py b/pyexcel_io/plugins.py index b36047c..2c350ef 100644 --- a/pyexcel_io/plugins.py +++ b/pyexcel_io/plugins.py @@ -7,14 +7,12 @@ :copyright: (c) 2014-2017 by Onni Software Ltd. :license: New BSD License, see LICENSE for more details """ -from lml.loader import scan_plugins_regex -from lml.plugin import PluginManager -from lml.plugin import PluginInfoChain, PluginInfo - import pyexcel_io.utils as ioutils import pyexcel_io.manager as manager import pyexcel_io.constants as constants import pyexcel_io.exceptions as exceptions +from lml.loader import scan_plugins_regex +from lml.plugin import PluginInfo, PluginManager, PluginInfoChain ERROR_MESSAGE_FORMATTER = "one of these plugins for %s data in '%s': %s" UPGRADE_MESSAGE = "Please upgrade the plugin '%s' according to \ @@ -137,5 +135,5 @@ def load_plugins(plugin_name_patterns, path, black_list, white_list): plugin_name_patterns=plugin_name_patterns, pyinstaller_path=path, black_list=black_list, - white_list=white_list + white_list=white_list, ) diff --git a/pyexcel_io/readers/__init__.py b/pyexcel_io/readers/__init__.py index 59bcfea..754e022 100644 --- a/pyexcel_io/readers/__init__.py +++ b/pyexcel_io/readers/__init__.py @@ -9,7 +9,6 @@ """ from pyexcel_io.plugins import IOPluginInfoChain - IOPluginInfoChain(__name__).add_a_reader( relative_plugin_class_path="csvr.CSVBookReader", file_types=["csv"], diff --git a/pyexcel_io/readers/csvz.py b/pyexcel_io/readers/csvz.py index 24410b1..c956eea 100644 --- a/pyexcel_io/readers/csvz.py +++ b/pyexcel_io/readers/csvz.py @@ -12,6 +12,7 @@ from pyexcel_io.book import BookReader from pyexcel_io._compact import PY2, StringIO from pyexcel_io.constants import FILE_FORMAT_CSVZ + from .csvr import NamedContent, CSVinMemoryReader diff --git a/pyexcel_io/readers/tsv.py b/pyexcel_io/readers/tsv.py index 8ac135a..35829ae 100644 --- a/pyexcel_io/readers/tsv.py +++ b/pyexcel_io/readers/tsv.py @@ -8,6 +8,7 @@ :license: New BSD License, see LICENSE for more details """ import pyexcel_io.constants as constants + from .csvr import CSVBookReader diff --git a/pyexcel_io/readers/tsvz.py b/pyexcel_io/readers/tsvz.py index c7b7310..9dc7d6d 100644 --- a/pyexcel_io/readers/tsvz.py +++ b/pyexcel_io/readers/tsvz.py @@ -8,6 +8,7 @@ :license: New BSD License, see LICENSE for more details """ from pyexcel_io.constants import FILE_FORMAT_TSVZ, KEYWORD_TSV_DIALECT + from .csvz import CSVZipBookReader diff --git a/pyexcel_io/service.py b/pyexcel_io/service.py index d5ffc63..a074c27 100644 --- a/pyexcel_io/service.py +++ b/pyexcel_io/service.py @@ -11,9 +11,8 @@ import math import datetime +from pyexcel_io import constants, exceptions from pyexcel_io._compact import PY2 -from pyexcel_io import constants -from pyexcel_io import exceptions def has_no_digits_in_float(value): @@ -234,7 +233,7 @@ def ods_timedelta_value(cell): "boolean": ods_bool_value, "timedelta": ods_timedelta_value, "float": ods_float_value, - "long": ods_float_value + "long": ods_float_value, } diff --git a/pyexcel_io/writers/__init__.py b/pyexcel_io/writers/__init__.py index bc5d767..30f62eb 100644 --- a/pyexcel_io/writers/__init__.py +++ b/pyexcel_io/writers/__init__.py @@ -9,7 +9,6 @@ """ from pyexcel_io.plugins import IOPluginInfoChain - IOPluginInfoChain(__name__).add_a_writer( relative_plugin_class_path="csvw.CSVBookWriter", file_types=["csv"], diff --git a/pyexcel_io/writers/csvz.py b/pyexcel_io/writers/csvz.py index 76d291b..3c3c3de 100644 --- a/pyexcel_io/writers/csvz.py +++ b/pyexcel_io/writers/csvz.py @@ -12,6 +12,7 @@ from pyexcel_io.book import BookWriter from pyexcel_io._compact import PY2, StringIO from pyexcel_io.constants import FILE_FORMAT_CSVZ, DEFAULT_SHEET_NAME + from .csvw import UnicodeWriter, CSVSheetWriter diff --git a/pyexcel_io/writers/tsv.py b/pyexcel_io/writers/tsv.py index 778372b..757cad2 100644 --- a/pyexcel_io/writers/tsv.py +++ b/pyexcel_io/writers/tsv.py @@ -8,6 +8,7 @@ :license: New BSD License, see LICENSE for more details """ import pyexcel_io.constants as constants + from .csvw import CSVBookWriter diff --git a/pyexcel_io/writers/tsvz.py b/pyexcel_io/writers/tsvz.py index 255730a..b12814d 100644 --- a/pyexcel_io/writers/tsvz.py +++ b/pyexcel_io/writers/tsvz.py @@ -8,6 +8,7 @@ :license: New BSD License, see LICENSE for more details """ from pyexcel_io.constants import FILE_FORMAT_TSVZ, KEYWORD_TSV_DIALECT + from .csvz import CSVZipBookWriter diff --git a/tests/test_base.py b/tests/test_base.py index a7c890e..df4dfb1 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,8 +1,9 @@ -from nose.tools import raises from pyexcel_io.book import BookWriter from pyexcel_io.sheet import SheetReader, SheetWriter, NamedContent from pyexcel_io.utils import is_empty_array +from nose.tools import raises + @raises(NotImplementedError) def test_book_writer(): diff --git a/tests/test_book.py b/tests/test_book.py index 0e98e57..70ad3c3 100644 --- a/tests/test_book.py +++ b/tests/test_book.py @@ -1,6 +1,7 @@ -from nose.tools import raises from pyexcel_io.book import BookReader, BookWriter, RWInterface +from nose.tools import raises + @raises(NotImplementedError) def test_rwinterface(): diff --git a/tests/test_csv_book.py b/tests/test_csv_book.py index c530f7b..ecbacb6 100644 --- a/tests/test_csv_book.py +++ b/tests/test_csv_book.py @@ -6,7 +6,6 @@ from unittest import TestCase import pyexcel_io.manager as manager -from nose.tools import eq_, raises from pyexcel_io.sheet import NamedContent from pyexcel_io._compact import PY2, BytesIO, StringIO from pyexcel_io.readers.csvr import ( @@ -16,6 +15,8 @@ ) from pyexcel_io.writers.csvw import CSVFileWriter, CSVMemoryWriter +from nose.tools import eq_, raises + class TestReaders(TestCase): def setUp(self): diff --git a/tests/test_django_book.py b/tests/test_django_book.py index 95239df..7ad4a6a 100644 --- a/tests/test_django_book.py +++ b/tests/test_django_book.py @@ -1,4 +1,3 @@ -from nose.tools import eq_, raises from pyexcel_io import save_data from pyexcel_io._compact import OrderedDict from pyexcel_io.constants import DB_DJANGO @@ -17,6 +16,8 @@ DjangoModelWriter, ) +from nose.tools import eq_, raises + class Package: def __init__(self, raiseException=False, **keywords): diff --git a/tests/test_filter.py b/tests/test_filter.py index 3af8eac..a3d3591 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -1,10 +1,11 @@ import os import pyexcel_io.constants as constants -from nose.tools import eq_ from pyexcel_io import get_data, save_data from pyexcel_io.utils import _index_filter +from nose.tools import eq_ + def test_index_filter(): current_index, start, limit, expected = (0, 1, -1, constants.SKIP_DATA) diff --git a/tests/test_io.py b/tests/test_io.py index 298eb65..ae7d148 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -6,11 +6,12 @@ import pyexcel_io.manager as manager import pyexcel_io.exceptions as exceptions -from nose.tools import eq_, raises from pyexcel_io import get_data, iget_data, save_data from pyexcel_io.io import load_data, get_writer from pyexcel_io._compact import BytesIO, StringIO, OrderedDict, is_string +from nose.tools import eq_, raises + PY2 = sys.version_info[0] == 2 @@ -25,7 +26,7 @@ def test_force_file_type(): @raises(IOError) def test_invalid_file(): - load_data('/something/does/not/exist') + load_data("/something/does/not/exist") @raises(IOError) diff --git a/tests/test_issues.py b/tests/test_issues.py index 7a436d2..09582e0 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -4,11 +4,11 @@ import os import pyexcel as p +from pyexcel_io import get_data, save_data +from pyexcel_io._compact import PY26 from nose import SkipTest from nose.tools import eq_ -from pyexcel_io import get_data, save_data -from pyexcel_io._compact import PY26 IN_TRAVIS = "TRAVIS" in os.environ diff --git a/tests/test_new_csv_book.py b/tests/test_new_csv_book.py index 857f4ee..930a58a 100644 --- a/tests/test_new_csv_book.py +++ b/tests/test_new_csv_book.py @@ -3,13 +3,14 @@ from unittest import TestCase import pyexcel_io.manager as manager -from nose.tools import raises from pyexcel_io._compact import OrderedDict from pyexcel_io.readers.tsv import TSVBookReader from pyexcel_io.writers.tsv import TSVBookWriter from pyexcel_io.readers.csvr import CSVBookReader from pyexcel_io.writers.csvw import CSVBookWriter +from nose.tools import raises + class TestCSVReaders(TestCase): file_type = "csv" diff --git a/tests/test_new_csvz_book.py b/tests/test_new_csvz_book.py index fdf8620..b73faed 100644 --- a/tests/test_new_csvz_book.py +++ b/tests/test_new_csvz_book.py @@ -5,7 +5,6 @@ from unittest import TestCase import pyexcel_io.manager as manager -from nose.tools import raises from pyexcel_io import save_data from pyexcel_io._compact import OrderedDict from pyexcel_io.readers.csvz import CSVZipBookReader @@ -13,6 +12,8 @@ from pyexcel_io.writers.csvz import CSVZipBookWriter from pyexcel_io.writers.tsvz import TSVZipBookWriter +from nose.tools import raises + PY2 = sys.version_info[0] == 2 diff --git a/tests/test_pyexcel_integration.py b/tests/test_pyexcel_integration.py index e198c74..963da21 100644 --- a/tests/test_pyexcel_integration.py +++ b/tests/test_pyexcel_integration.py @@ -4,7 +4,6 @@ from unittest import TestCase import pyexcel as pe - from pyexcel_io._compact import text_type diff --git a/tests/test_renderer.py b/tests/test_renderer.py index 5be2174..209bad9 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.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 TestRenderer: def setUp(self): diff --git a/tests/test_service.py b/tests/test_service.py index 1c234f1..5971708 100644 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -1,13 +1,17 @@ -from nose.tools import eq_, raises -from pyexcel_io.service import date_value, time_value -from pyexcel_io.service import detect_int_value -from pyexcel_io.service import detect_float_value -from pyexcel_io.service import ODS_WRITE_FORMAT_COVERSION -from pyexcel_io.service import ods_float_value -from pyexcel_io.service import throw_exception +from pyexcel_io.service import ( + ODS_WRITE_FORMAT_COVERSION, + date_value, + time_value, + ods_float_value, + throw_exception, + detect_int_value, + detect_float_value, +) from pyexcel_io._compact import PY2 from pyexcel_io.exceptions import IntegerAccuracyLossError + from nose import SkipTest +from nose.tools import eq_, raises def test_date_util_parse(): @@ -100,7 +104,7 @@ def test_detect_float_value_on_custom_nan_text2(): def test_ods_write_format_conversion(): if PY2: expected = ODS_WRITE_FORMAT_COVERSION[long] # noqa: F821 - eq_('long', expected) + eq_("long", expected) else: raise SkipTest() @@ -120,7 +124,7 @@ def test_max_value_on_python_2(): @raises(IntegerAccuracyLossError) def test_really_long_value_on_python2(): if PY2: - ods_float_value(long(999999999999999+1)) + ods_float_value(long(999999999999999 + 1)) else: raise SkipTest("No long in python 3") diff --git a/tests/test_sheet.py b/tests/test_sheet.py index 789317a..d82cb30 100644 --- a/tests/test_sheet.py +++ b/tests/test_sheet.py @@ -1,7 +1,8 @@ import pyexcel_io.constants as constants -from nose.tools import eq_ from pyexcel_io.sheet import SheetReader, SheetWriter +from nose.tools import eq_ + class MyWriter(SheetWriter): def set_size(self, size): diff --git a/tests/test_sql_book.py b/tests/test_sql_book.py index 6927056..47bc5c9 100644 --- a/tests/test_sql_book.py +++ b/tests/test_sql_book.py @@ -3,18 +3,6 @@ import datetime import platform -from nose.tools import eq_, raises -from sqlalchemy import ( - Date, - Float, - Column, - String, - Integer, - DateTime, - ForeignKey, - create_engine, -) -from sqlalchemy.orm import backref, relationship, sessionmaker from pyexcel_io._compact import OrderedDict from pyexcel_io.database.common import ( SQLTableExporter, @@ -22,7 +10,6 @@ SQLTableExportAdapter, SQLTableImportAdapter, ) -from sqlalchemy.ext.declarative import declarative_base from pyexcel_io.database.querysets import QuerysetsReader from pyexcel_io.database.exporters.sqlalchemy import ( SQLBookReader, @@ -34,6 +21,20 @@ PyexcelSQLSkipRowException, ) +from nose.tools import eq_, raises +from sqlalchemy import ( + Date, + Float, + Column, + String, + Integer, + DateTime, + ForeignKey, + create_engine, +) +from sqlalchemy.orm import backref, relationship, sessionmaker +from sqlalchemy.ext.declarative import declarative_base + PY3 = sys.version_info[0] == 3 PY36 = PY3 and sys.version_info[1] == 6