#!/usr/bin/env python
import os
import sys
import Cython
from Cython.Build import cythonize
from glob import glob

if Cython.__version__ < '0.21':
    sys.stderr.write('require cython version >=0.21')
    sys.exit(1)

print("Cython version", Cython.__version__)

DEBUG = False

pxd_include_dirs = [
    directory for directory, dirs, files in os.walk('pytraj')
    if '__init__.pyx' in files or '__init__.pxd' in files or
    '__init__.py' in files
]

pyxfiles = []
for p in pxd_include_dirs:
    pyxfiles.extend(
        [ext.split(".")[0] for ext in glob(p + '/*.pyx') if '.pyx' in ext])

cython_directives = {
    'embedsignature': True,
    'boundscheck': False,
    'wraparound': False,
    'language_level' : "3"
}

if DEBUG:
    cython_directives.update({
        'profile': True,
        'linetrace': True,
        'binding': True
    })
    define_macros = [
        ('CYTHON_TRACE', 1),
    ]
else:
    define_macros = []

cythonize(
    [pfile + '.pyx' for pfile in pyxfiles],
    compiler_directives=cython_directives, )
