# -*- coding: utf-8 -*-
# flake8: noqa

"""Spike sorting and ephys data analysis for 1000 channels and beyond."""


#------------------------------------------------------------------------------
# Imports
#------------------------------------------------------------------------------

import logging
import os.path as op
import sys

from six import StringIO

from .utils.datasets import download_sample_data
from .utils._misc import _git_version


#------------------------------------------------------------------------------
# Global variables and functions
#------------------------------------------------------------------------------

__author__ = 'Kwik team'
__email__ = 'cyrille.rossant at gmail.com'
__version__ = '0.3.0.dev0'
__version_git__ = __version__ + _git_version()


# Set a null handler on the root logger
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.NullHandler())


_logger_fmt = '%(asctime)s  [%(levelname)s]  %(caller)s %(message)s'
_logger_date_fmt = '%H:%M:%S'


class _Formatter(logging.Formatter):
    def format(self, record):
        # Only keep the first character in the level name.
        record.levelname = record.levelname[0]
        filename = op.splitext(op.basename(record.pathname))[0]
        record.caller = '{:s}:{:d}'.format(filename, record.lineno).ljust(16)
        return super(_Formatter, self).format(record)


def add_default_handler(level='INFO'):
    handler = logging.StreamHandler()
    handler.setLevel(level)

    formatter = _Formatter(fmt=_logger_fmt,
                           datefmt=_logger_date_fmt)
    handler.setFormatter(formatter)

    logger.addHandler(handler)


if '--debug' in sys.argv:  # pragma: no cover
    add_default_handler('DEBUG')
    logger.info("Activate DEBUG level.")


def test():  # pragma: no cover
    """Run the full testing suite of phy."""
    import pytest
    pytest.main()

@@ -1787,24 +1787,295 @@
  level.%22)%0A%0A%0A
+# Force dask to use the synchronous scheduler: we'll use ipyparallel%0A# manually for parallel processing.%0Atry:%0A    import dask.async%0A    from dask import set_options%0A    set_options(get=dask.async.get_sync)%0Aexcept ImportError:%0A    logger.debug(%22dask is not available.%22)%0A%0A%0A
 def test(): 

Use synchronous dask scheduler