setup.py
changeset 132 0260aeca943c
parent 117 2da34e3aa885
child 151 dfd8022d000e
equal deleted inserted replaced
131:4e6e067b3472 132:0260aeca943c
     1 from distutils.core import setup
     1 from distutils.core import setup
     2 from distutils.extension import Extension
     2 from distutils.extension import Extension
     3 
     3 
     4 import os.path
     4 import os.path
     5 
     5 
     6 build_root = os.path.abspath(os.path.dirname(__file__))
     6 try :
       
     7     from Cython.Build import cythonize
     7 
     8 
     8 pypngtile_c = "python/pypngtile.c"
     9     CYTHON = True
     9 pypngtile_name = "python/pypngtile.pyx"
    10 except ImportError :
       
    11     CYTHON = False
    10 
    12 
    11 cmdclass = dict()
    13 if CYTHON:
       
    14     pypngtile_sources = [ "python/pypngtile.pyx" ]
       
    15 elif os.path.exists("python/pypngtile.c"):
       
    16     pypngtile_sources = [ "python/pypngtile.c" ]
       
    17 else:
       
    18     raise Exception("Building from source requires Cython")
    12 
    19 
    13 try :
    20 ext_modules = [Extension("pypngtile",
    14     from Cython.Distutils import build_ext
    21     sources         = pypngtile_sources,
    15     
    22     libraries       = ['pngtile'],
    16     cmdclass['build_ext'] = build_ext
    23 )]
    17 
    24 
    18 except ImportError :
    25 if CYTHON:
    19     path = os.path.join(build_root, pypngtile_c)
    26     ext_modules = cythonize(ext_modules)
    20 
       
    21     if os.path.exists(path) :
       
    22         print "Warning: falling back from .pyx -> .c due to missing Cython"
       
    23         # just use the .c
       
    24         pypngtile_name = pypngtile_c
       
    25     
       
    26     else :
       
    27         # fail
       
    28         raise
       
    29 
    27 
    30 setup(
    28 setup(
    31     name = 'pngtiles',
    29     name            = 'pngtile',
    32     cmdclass = cmdclass,
    30     version         = '1.0-dev',
    33     ext_modules = [
    31 
    34         Extension("pypngtile", [pypngtile_name],
    32     ext_modules     = ext_modules,
    35             include_dirs = ['include'],
       
    36             library_dirs = ['lib'],
       
    37             libraries = ['pngtile'],
       
    38         ),
       
    39     ],
       
    40 )
    33 )
    41 
    34