#!/usr/bin/env python
# coding=utf-8
# Filename: setup.py
"""
KM3Pipe setup script.

"""
from setuptools import setup, Extension
from Cython.Compiler.Options import directive_defaults
import sys

if sys.version_info[0] >= 3:
    import builtins
else:
    import __builtin__ as builtins
try:
    from Cython.Distutils import build_ext
    import numpy
except ImportError:
    raise SystemExit("\nCython and Numpy are required to compile KM3Pipe.\n"
                     "You can install it easily via pip:\n\n"
                     "    > pip install cython numpy")


# This hack is "stolen" from numpy and allows to detect the setup procedure
# to avoid loading modules which are not compiled yet. Ugly but robust.
builtins.__KM3PIPE_SETUP__ = True

# Needed for line_profiler - disable for production code
directive_defaults['linetrace'] = True
directive_defaults['profile'] = True
directive_defaults['binding'] = True
CYTHON_TRACE = str(int(directive_defaults['linetrace']))

from km3pipe import version  # noqa


tools = Extension('km3pipe.tools', sources=['km3pipe/tools.pyx'],
                  extra_compile_args=['-O3', '-march=native', '-w'],
                  include_dirs=[numpy.get_include()],
                  define_macros=[('CYTHON_TRACE', CYTHON_TRACE)])

core = Extension('km3pipe.core', sources=['km3pipe/core.pyx'],
                 extra_compile_args=['-O3', '-march=native', '-w'],
                 include_dirs=[numpy.get_include()],
                 define_macros=[('CYTHON_TRACE', CYTHON_TRACE)])

dataclasses = Extension('km3pipe.dataclasses',
                        sources=['km3pipe/dataclasses.pyx'],
                        extra_compile_args=['-O3', '-march=native', '-w'],
                        include_dirs=[numpy.get_include()],
                        define_macros=[('CYTHON_TRACE', CYTHON_TRACE)])

setup(name='km3pipe',
      version=version,
      url='http://github.com/tamasgal/km3pipe/',
      description='An analysis framework for KM3NeT',
      author='Tamas Gal and Moritz Lotze',
      author_email='tgal@km3net.de',
      packages=['km3pipe', 'km3pipe.testing', 'km3pipe.io', 'km3pipe.utils',
                'km3modules', 'pipeinspector'],
      ext_modules=[tools, core, dataclasses],
      cmdclass={'build_ext': build_ext},
      include_package_data=True,
      platforms='any',
      install_requires=[
          'cython',
          'numpy',
          'controlhost',
          'urwid',
          'docopt',
          'tables',
          'pandas',
          'seaborn',
          'tornado',
          'pytz',
          'six',
          'pytest',
          'mock',
          'websocket-client',
      ],
      extra_require={
          'scikit-learn': ['sklearn'],
          'docs': ['sphinx >= 1.4', 'sphinx-gallery', 'numpydoc'],
          'jppy': ['jppy'],
      },
      entry_points={
          'console_scripts': [
              'km3pipe=km3pipe.cmd:main',
              'km3srv=km3pipe.srv:main',
              'pipeinspector=pipeinspector.app:main',
              'h5tree=km3pipe.utils.h5tree:main',
              'h5info=km3pipe.utils.h5info:main',
              'ztplot=km3pipe.utils.ztplot:main',
          ],
      },
      classifiers=[
          'Development Status :: 3 - Alpha',
          'Intended Audience :: Developers',
          'Intended Audience :: Science/Research',
          'Programming Language :: Python',
      ],
      )

__author__ = 'Tamas Gal'

@@ -126,63 +126,8 @@
 ion%0A
-from Cython.Compiler.Options import directive_defaults%0A
 impo
@@ -272,16 +272,75 @@
 ild_ext%0A
+    from Cython.Compiler.Options import directive_defaults%0A
     impo

Move import into try-block