🔨 code refactoring using isort and black

This commit is contained in:
chfw 2018-11-09 20:56:34 +00:00
parent 48f45f192c
commit 41ef6d1310
34 changed files with 110 additions and 95 deletions

View File

@ -12,4 +12,3 @@ def setup(app):
{%endblock%}

View File

@ -6,4 +6,3 @@
{%block pyexcel_extra_classifiers%}
'Programming Language :: Python :: Implementation :: PyPy'
{%endblock%}}

View File

@ -6,3 +6,8 @@ test:
document:
sphinx-autogen -o docs/source/generated/ docs/source/*.rst
sphinx-build -b html docs/source/ docs/build/
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

View File

@ -8,7 +8,7 @@
:license: New BSD License, see LICENSE for more details
"""
import pyexcel_io.manager as manager
from pyexcel_io._compact import OrderedDict, isstream, PY2
from pyexcel_io._compact import PY2, OrderedDict, isstream
from .constants import MESSAGE_ERROR_03, MESSAGE_WRONG_IO_INSTANCE

View File

@ -9,10 +9,10 @@
"""
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
import pyexcel_io.constants as constants
log = logging.getLogger(__name__)

View File

@ -7,10 +7,10 @@
:copyright: (c) 2014-2017 by Onni Software Ltd.
: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
import pyexcel_io.constants as constants
class PyexcelSQLSkipRowException(Exception):

View File

@ -7,12 +7,12 @@
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
from types import GeneratorType
import warnings
from types import GeneratorType
from pyexcel_io._compact import isstream, PY2
from pyexcel_io.plugins import READERS, WRITERS
import pyexcel_io.constants as constants
from pyexcel_io.plugins import READERS, WRITERS
from pyexcel_io._compact import PY2, isstream
def iget_data(afile, file_type=None, **keywords):

View File

@ -7,8 +7,7 @@
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
from pyexcel_io._compact import StringIO, BytesIO
from pyexcel_io._compact import BytesIO, StringIO
MIME_TYPES = {}
FILE_TYPES = ()

View File

@ -8,14 +8,12 @@
:license: New BSD License, see LICENSE for more details
"""
from lml.loader import scan_plugins
from lml.plugin import PluginManager
from lml.plugin import PluginInfoChain, PluginInfo
from lml.plugin import PluginInfo, PluginManager, PluginInfoChain
import pyexcel_io.utils as ioutils
import pyexcel_io.manager as manager
import pyexcel_io.exceptions as exceptions
import pyexcel_io.constants as constants
import pyexcel_io.exceptions as exceptions
ERROR_MESSAGE_FORMATTER = "one of these plugins for %s data in '%s': %s"
UPGRADE_MESSAGE = "Please upgrade the plugin '%s' according to \

View File

@ -7,18 +7,17 @@
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
import re
import os
import re
import csv
import glob
import codecs
from pyexcel_io.book import BookReader
from pyexcel_io.sheet import SheetReader, NamedContent
import pyexcel_io.service as service
import pyexcel_io._compact as compact
import pyexcel_io.constants as constants
import pyexcel_io.service as service
from pyexcel_io.book import BookReader
from pyexcel_io.sheet import SheetReader, NamedContent
DEFAULT_SEPARATOR = "__"
DEFAULT_SHEET_SEPARATOR_FORMATTER = "---%s---" % constants.DEFAULT_NAME + "%s"
@ -84,7 +83,7 @@ class CSVMemoryMapIterator(compact.Iterator):
if bom_header == BOM_BIG_ENDIAN:
self.__endian = BIG_ENDIAN
elif self.__endian == LITTLE_ENDIAN:
line = line[self.__zeros_left_in_2_row :] # flake8: noqa
line = line[self.__zeros_left_in_2_row :] # noqa: E203
if self.__endian == LITTLE_ENDIAN:
line = line.rstrip()
line = line.decode(self.__encoding)

View File

@ -9,11 +9,10 @@
"""
import zipfile
from pyexcel_io._compact import StringIO, PY2
from pyexcel_io.book import BookReader
from pyexcel_io._compact import PY2, StringIO
from pyexcel_io.constants import FILE_FORMAT_CSVZ
from .csvr import CSVinMemoryReader, NamedContent
from .csvr import NamedContent, CSVinMemoryReader
class CSVZipBookReader(BookReader):

View File

@ -8,7 +8,6 @@
:license: New BSD License, see LICENSE for more details
"""
from pyexcel_io.constants import FILE_FORMAT_TSVZ, KEYWORD_TSV_DIALECT
from .csvz import CSVZipBookReader

View File

@ -127,7 +127,7 @@ def time_value(value):
"""convert to time value accroding the specification"""
import re
results = re.match("PT(\d+)H(\d+)M(\d+)S", value)
results = re.match(r"PT(\d+)H(\d+)M(\d+)S", value)
if results and len(results.groups()) == 3:
hour = int(results.group(1))
minute = int(results.group(2))

View File

@ -7,9 +7,9 @@
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
"""
from pyexcel_io._compact import irange
from pyexcel_io.utils import _index_filter
import pyexcel_io.constants as constants
from pyexcel_io.utils import _index_filter
from pyexcel_io._compact import irange
class NamedContent(object):

View File

@ -9,7 +9,6 @@
"""
import pyexcel_io.constants as constants
XLS_PLUGIN = "pyexcel-xls"
XLSX_PLUGIN = "pyexcel-xlsx"
ODS_PLUGIN = "pyexcel-ods"

View File

@ -10,10 +10,10 @@
import csv
import codecs
from pyexcel_io.book import BookWriter
from pyexcel_io.sheet import SheetWriter
import pyexcel_io._compact as compact
import pyexcel_io.constants as constants
from pyexcel_io.book import BookWriter
from pyexcel_io.sheet import SheetWriter
class UnicodeWriter(object):

View File

@ -9,11 +9,10 @@
"""
import zipfile
from pyexcel_io._compact import StringIO, PY2
from pyexcel_io.book import BookWriter
from pyexcel_io.constants import DEFAULT_SHEET_NAME, FILE_FORMAT_CSVZ
from .csvw import CSVSheetWriter, UnicodeWriter
from pyexcel_io._compact import PY2, StringIO
from pyexcel_io.constants import FILE_FORMAT_CSVZ, DEFAULT_SHEET_NAME
from .csvw import UnicodeWriter, CSVSheetWriter
class CSVZipSheetWriter(CSVSheetWriter):

View File

@ -8,7 +8,6 @@
:license: New BSD License, see LICENSE for more details
"""
from pyexcel_io.constants import FILE_FORMAT_TSVZ, KEYWORD_TSV_DIALECT
from .csvz import CSVZipBookWriter

View File

@ -5,7 +5,9 @@ import os
import sys
import codecs
from shutil import rmtree
from setuptools import setup, find_packages, Command
from setuptools import Command, setup, find_packages
PY2 = sys.version_info[0] == 2
PY26 = PY2 and sys.version_info[1] < 7

View File

@ -6,3 +6,7 @@ flake8
SQLAlchemy
pyexcel>=0.2.0
pyexcel-xls>=0.1.0
moban
black;python_version>="3.6"
isort;python_version>="3.6"

View File

@ -1,7 +1,7 @@
from pyexcel_io.sheet import SheetReader, SheetWriter, NamedContent
from pyexcel_io.book import BookWriter
from pyexcel_io.utils import is_empty_array
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
@raises(NotImplementedError)

View File

@ -1,5 +1,5 @@
from nose.tools import raises
from pyexcel_io.book import RWInterface, BookReader, BookWriter
from pyexcel_io.book import BookReader, BookWriter, RWInterface
@raises(NotImplementedError)

View File

@ -2,18 +2,19 @@
# -*- coding: utf-8 -*-
import os
from unittest import TestCase
from textwrap import dedent
from nose.tools import raises, eq_
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 (
CSVSheetReader,
CSVFileReader,
CSVSheetReader,
CSVinMemoryReader,
)
from pyexcel_io.writers.csvw import CSVFileWriter, CSVMemoryWriter
from pyexcel_io._compact import BytesIO, PY2, StringIO
class TestReaders(TestCase):

View File

@ -1,20 +1,20 @@
from nose.tools import raises, eq_
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
from pyexcel_io.database.common import (
DjangoModelImporter,
DjangoModelImportAdapter,
DjangoModelExporter,
DjangoModelImporter,
DjangoModelExportAdapter,
)
from pyexcel_io.database.importers.django import (
DjangoModelWriter,
DjangoBookWriter,
DjangoModelImportAdapter,
)
from pyexcel_io.database.exporters.django import (
DjangoModelReader,
DjangoBookReader,
DjangoModelReader,
)
from pyexcel_io.database.importers.django import (
DjangoBookWriter,
DjangoModelWriter,
)

View File

@ -1,9 +1,9 @@
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_
import pyexcel_io.constants as constants
def test_index_filter():

View File

@ -1,16 +1,15 @@
import os
import sys
import types
from zipfile import BadZipfile
from unittest import TestCase
import pyexcel_io.manager as manager
import pyexcel_io.exceptions as exceptions
from pyexcel_io._compact import StringIO, BytesIO, is_string
from pyexcel_io._compact import OrderedDict
from pyexcel_io import save_data, get_data, iget_data
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 nose.tools import raises, eq_
from zipfile import BadZipfile
from pyexcel_io._compact import BytesIO, StringIO, OrderedDict, is_string
PY2 = sys.version_info[0] == 2

View File

@ -2,11 +2,13 @@
# -*- coding: utf-8 -*-
import os
import pyexcel as p
from nose import SkipTest
from nose.tools import eq_
from pyexcel_io import get_data, save_data
from pyexcel_io._compact import PY26
import pyexcel as p
IN_TRAVIS = "TRAVIS" in os.environ

View File

@ -1,13 +1,14 @@
import os
from unittest import TestCase
from textwrap import dedent
from nose.tools import raises
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.csvr import CSVBookReader
from pyexcel_io.readers.tsv import TSVBookReader
from pyexcel_io.writers.csvw import CSVBookWriter
from pyexcel_io.writers.tsv import TSVBookWriter
from pyexcel_io.readers.csvr import CSVBookReader
from pyexcel_io.writers.csvw import CSVBookWriter
class TestCSVReaders(TestCase):

View File

@ -1,16 +1,17 @@
# -*- coding: utf-8 -*-
import os
from unittest import TestCase
from pyexcel_io._compact import OrderedDict
from pyexcel_io import save_data
import pyexcel_io.manager as manager
from pyexcel_io.readers.csvz import CSVZipBookReader
from pyexcel_io.writers.csvz import CSVZipBookWriter
from pyexcel_io.readers.tsvz import TSVZipBookReader
from pyexcel_io.writers.tsvz import TSVZipBookWriter
import zipfile
from nose.tools import raises
import sys
import zipfile
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
from pyexcel_io.readers.tsvz import TSVZipBookReader
from pyexcel_io.writers.csvz import CSVZipBookWriter
from pyexcel_io.writers.tsvz import TSVZipBookWriter
PY2 = sys.version_info[0] == 2

View File

@ -1,9 +1,10 @@
import os
import datetime
from unittest import TestCase
from textwrap import dedent
from unittest import TestCase
import pyexcel as pe
from pyexcel_io._compact import text_type

View File

@ -1,4 +1,5 @@
import os
from nose.tools import eq_
from pyexcel_io import get_data, save_data

View File

@ -1,7 +1,10 @@
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 (
date_value,
time_value,
detect_int_value,
detect_float_value,
)
def test_date_util_parse():

View File

@ -1,6 +1,6 @@
from nose.tools import eq_
from pyexcel_io.sheet import SheetWriter, SheetReader
import pyexcel_io.constants as constants
from nose.tools import eq_
from pyexcel_io.sheet import SheetReader, SheetWriter
class MyWriter(SheetWriter):

View File

@ -1,32 +1,38 @@
import sys
import json
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy import Float, Date, DateTime, ForeignKey
from sqlalchemy.orm import sessionmaker
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,
SQLTableExportAdapter,
SQLTableImporter,
SQLTableExportAdapter,
SQLTableImportAdapter,
)
from sqlalchemy.ext.declarative import declarative_base
from pyexcel_io.database.querysets import QuerysetsReader
from pyexcel_io.database.exporters.sqlalchemy import (
SQLTableReader,
SQLBookReader,
SQLTableReader,
)
from pyexcel_io.database.importers.sqlalchemy import (
PyexcelSQLSkipRowException,
SQLTableWriter,
SQLBookWriter,
SQLTableWriter,
PyexcelSQLSkipRowException,
)
from pyexcel_io.database.querysets import QuerysetsReader
from sqlalchemy.orm import relationship, backref
from nose.tools import raises, eq_
import platform
PY3 = sys.version_info[0] == 3
PY36 = PY3 and sys.version_info[1] == 6