from glob import glob
import os
from setuptools import setup, Extension
from distutils.command.build_ext import build_ext
from distutils.command.build_clib import build_clib

import numpy
np_include_path = [numpy.get_include()]
c_options = {}
c_options['use_numpy'] = 1

def generate_cython_c_config_file():
    print('Generate config.pxi')
    d = os.path.dirname(__file__)
    config_file_name = os.path.join(  d , 'config.pxi')
    with open(config_file_name, 'w') as fd:
        for k, v in c_options.items():
            fd.write('DEF %s = %d\n' % (k.upper(), int(v)))

generate_cython_c_config_file()

if glob("*.pyx"):
    from Cython.Build import cythonize
    EXT = 'pyx'                 # file extension to use if cython is installed
else:
    # fallback to compiled cpp
    cythonize = None
    EXT = 'cpp'                 # for distribution we include the generated cpp file, so use it for installation

extension = Extension(
        "primehexagon",
        ["primehexagon.{}".format(EXT)],
        include_dirs=[] + np_include_path,
        language="c++",
        )

ext_modules = cythonize(extension) if cythonize else [extension]

setup(
    name='primehexagon',
    version="0.1.0",
    url = "https://github.com/tsgallion/prime-hexagon",
    description="Exploring prime numbers on the hexagon",
    license = "MIT",
    ext_modules = ext_modules,
    py_modules = ['primespin'],
    install_requires=['numpy'],
    classifiers=[
    'Programming Language :: Python :: 2',
    'Programming Language :: Python :: 2.6',
    'Programming Language :: Python :: 2.7',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.2',
    'Programming Language :: Python :: 3.3',
    'Programming Language :: Python :: 3.4',
    'Programming Language :: Python :: 3.5',
    ],
)

@@ -601,16 +601,77 @@
 file()%0A%0A
+# assume fallback to compiled cpp%0AEXT='cpp'%0Acythonize = None%0A
 if glob(
@@ -680,16 +680,29 @@
 .pyx%22):%0A
+    try:%0A    
     from
@@ -732,16 +732,20 @@
 thonize%0A
+    
     EXT 
@@ -819,178 +819,32 @@
 led%0A
-else:%0A    # fallback to compiled cpp%0A    cythonize = None%0A    EXT = 'cpp'                 # for distribution we include the generated cpp file, so use it for installation
+    except:%0A        pass
 %0A%0Aex

make setup.py not error if no cython installed