|
1 | 1 | from distutils.core import setup |
2 | 2 | from distutils.extension import Extension |
3 | | -from Cython.Distutils import build_ext |
4 | 3 | import os |
5 | | -import numpy |
6 | 4 |
|
7 | | -gco_directory = "gco_src" |
| 5 | +try: |
| 6 | + # Attempt to set up the cython module |
| 7 | + from Cython.Distutils import build_ext |
| 8 | + import numpy |
8 | 9 |
|
9 | | -files = ['GCoptimization.cpp', 'graph.cpp', 'LinkedBlockList.cpp', |
10 | | - 'maxflow.cpp'] |
| 10 | + gco_directory = "gco_src" |
11 | 11 |
|
12 | | -files = [os.path.join(gco_directory, f) for f in files] |
13 | | -files.insert(0, "gco_python.pyx") |
| 12 | + files = ['GCoptimization.cpp', 'graph.cpp', 'LinkedBlockList.cpp', |
| 13 | + 'maxflow.cpp'] |
14 | 14 |
|
15 | | -setup(cmdclass={'build_ext': build_ext}, |
16 | | - ext_modules=[Extension("pygco", files, language="c++", |
17 | | - include_dirs=[gco_directory, numpy.get_include()], |
18 | | - library_dirs=[gco_directory], |
19 | | - extra_compile_args=["-fpermissive"])]) |
| 15 | + files = [os.path.join(gco_directory, f) for f in files] |
| 16 | + files.insert(0, "gco_python.pyx") |
| 17 | + |
| 18 | + setup( |
| 19 | + name='pygco', |
| 20 | + install_requires=['cython', 'numpy'], |
| 21 | + cmdclass={'build_ext': build_ext}, |
| 22 | + ext_modules=[Extension( |
| 23 | + "pygco", files, language="c++", |
| 24 | + include_dirs=[gco_directory, numpy.get_include()], |
| 25 | + library_dirs=[gco_directory], |
| 26 | + extra_compile_args=["-fpermissive"] |
| 27 | + )], |
| 28 | + ) |
| 29 | +except ImportError: |
| 30 | + # If cython or numpy are not available, then do not try to configure the |
| 31 | + # cython extension, just record that we need them as dependencies |
| 32 | + setup( |
| 33 | + name='pygco', |
| 34 | + install_requires=['cython', 'numpy'] |
| 35 | + ) |
0 commit comments