import os, sys

from Cython.Build import build_ext, cythonize
from setuptools import setup, Extension, find_packages

def ext_modules():
    import numpy as np

    include_dirs = ['.', np.get_include()]
    root_dir = os.path.abspath(os.path.dirname(__file__))
    root_dir += "/fastXPCS/cython/"
    dense_ext = Extension(
        "dense",
        sources=[root_dir + "dense.pyx"],
        include_dirs=include_dirs,
    )
    sparse_ext = Extension(
        "fxpcs_sparse",
        sources=[root_dir + "fxpcs_sparse.pyx"],
        include_dirs=include_dirs
    )

    wf_ext = Extension(
        "welford",
        sources=[root_dir + "welford.pyx"],
        include_dirs=include_dirs
    )


    exts = [dense_ext, sparse_ext, wf_ext]

    return cythonize(exts, language_level=3)

REQUIREMENTS = [
    "h5py",
    "numpy",
    "cython",
]

setup(
    name="fastXPCS",
    packages=find_packages(),
    ext_package="fastXPCS",
    ext_modules=ext_modules(),
    cmdclass={"build_ext" : build_ext},
    zip_safe=False,
    install_requires=REQUIREMENTS
)