diff --git a/scikits/image/opencv/INSTALL.txt b/scikits/image/opencv/INSTALL.txt index 4667f743..02d5eefc 100644 --- a/scikits/image/opencv/INSTALL.txt +++ b/scikits/image/opencv/INSTALL.txt @@ -1,12 +1,7 @@ -You can try to use the setup.py but it may still be broken - -Until we come to a solution for a setup.py, execute the included shell script build.sh and copy the .so's to wherever you want them - -scikit/image/opencv$./build.sh -scikit/image/opencv$cd tests -scikit/image/opencv/tests$python test_opencv_cv.py - -!* make sure the scikits directory is on the python path *! +Using the setup.py in this directory will work. +But the setup.py in the main scikits.image does not (it uses setuptools) +this will be changed in the future. + diff --git a/scikits/image/opencv/build.sh b/scikits/image/opencv/build.sh deleted file mode 100755 index 525692a9..00000000 --- a/scikits/image/opencv/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -cython opencv_backend.pyx && cython opencv_cv.pyx && gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.6 -o opencv_backend.so opencv_backend.c && gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.6 -o opencv_cv.so opencv_cv.c diff --git a/scikits/image/opencv/opencv_backend.c b/scikits/image/opencv/opencv_backend.c index c4c9ba18..8398c38c 100644 --- a/scikits/image/opencv/opencv_backend.c +++ b/scikits/image/opencv/opencv_backend.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.3 on Wed Oct 14 12:47:10 2009 */ +/* Generated by Cython 0.11.3 on Wed Oct 14 17:34:08 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" diff --git a/scikits/image/opencv/opencv_cv.c b/scikits/image/opencv/opencv_cv.c index c851b589..3d2ab972 100644 --- a/scikits/image/opencv/opencv_cv.c +++ b/scikits/image/opencv/opencv_cv.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.3 on Wed Oct 14 12:47:11 2009 */ +/* Generated by Cython 0.11.3 on Wed Oct 14 17:34:09 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" diff --git a/scikits/image/opencv/setup.py b/scikits/image/opencv/setup.py index 01ba61f3..5ac8c718 100644 --- a/scikits/image/opencv/setup.py +++ b/scikits/image/opencv/setup.py @@ -3,55 +3,47 @@ import os import shutil -current_dir = os.path.dirname(__file__) - def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs + config = Configuration('opencv', parent_package, top_path) - config.add_data_dir(os.path.join(current_dir, 'tests')) + config.add_data_dir('tests') # since distutils/cython has problems, we'll check to see if cython is # installed and use that to rebuild the .c files, if not, we'll just build - # direct from the included .c files + # directly from the included .c files - # if the cython compilation fails, it will overwrite the good .c files - # so we back them up first - - src = os.path.join(current_dir, 'opencv_cv.c') - dst = os.path.join(current_dir, 'opencv_cv.c.bak') - shutil.copy(src, dst) - src = os.path.join(current_dir, 'opencv_backend.c') - dst = os.path.join(current_dir, 'opencv_backend.c.bak') - shutil.copy(src, dst) - + cython_files = ['opencv_backend.pyx', 'opencv_cv.pyx'] + try: - import cython - # no way to check the cython version number???? - os.system('cython opencv_backend.pyx') - os.system('cython opencv_cv.pyx') - - # if the cython compilation failed, the resulting file - # size will be very small ~ 78 bytes - f1 = os.path.join(current_dir, 'opencv_cv.c') - f2 = os.path.join(current_dir, 'opencv_backend.c') - size1 = os.path.getsize(f1) - size2 = os.path.getsize(f2) - assert size1 > 100 and size2 > 100 - except: - print 'Cython compilation failed. Building from backups.' - src = os.path.join(current_dir, 'opencv_cv.c.bak') - dst = os.path.join(current_dir, 'opencv_cv.c') - shutil.copy(src, dst) - src = os.path.join(current_dir, 'opencv_backend.c.bak') - dst = os.path.join(current_dir, 'opencv_backend.c') - shutil.copy(src, dst) - - config.add_extension('opencv_backend', sources=['opencv_backend.c'], - include_dirs=[get_numpy_include_dirs()]) + import Cython + for pyxfile in cython_files: + # make a backup of the good c files + c_file = pyxfile.rstrip('pyx') + 'c' + src = c_file + dst = c_file + '.bak' + shutil.copy(src, dst) + + # run cython compiler + os.system('cython ' + pyxfile) + + # if the file is small, cython compilation failed + size = os.path.getsize(c_file) + if size < 100: + print 'Cython compilation failed. Restoring from backup.' + # restore from backup + shutil.copy(dst, src) + + except ImportError: + # if cython is not found, we just build from the include .c files + pass - config.add_extension('opencv_cv', sources=['opencv_cv.c'], - include_dirs=[get_numpy_include_dirs()]) + for pyxfile in cython_files: + c_file = pyxfile.rstrip('pyx') + 'c' + config.add_extension(pyxfile.rstrip('.pyx'), + sources=[c_file], + include_dirs=[get_numpy_include_dirs()]) return config