from setuptools import setup, find_packages, Extension
from Cython.Build import cythonize
import numpy as np
import os.path as op
import os
import platform
import fnmatch
import versioneer


INCLUDE_DIRS = []
LIBRARY_DIRS = []


def walk_for_package_data(ext_pattern):
    paths = []
    for root, dirnames, filenames in os.walk('cyvlfeat'):
        for filename in fnmatch.filter(filenames, ext_pattern):
            # Slice cyvlfeat off the beginning of the path
            paths.append(
                op.relpath(os.path.join(root, filename), 'cyvlfeat'))
    return paths


def gen_extension(path_name, sources):
    global INCLUDE_DIRS, LIBRARY_DIRS
    return Extension(
        path_name,
        sources=sources,
        include_dirs=INCLUDE_DIRS,
        library_dirs=LIBRARY_DIRS,
        libraries=['vl'],
        language='c'
    )


IS_WIN = platform.system() == 'Windows'
IS_CONDA = os.environ.get('CONDA_BUILD', False)

# If we are building from the conda folder,
# then we know we can manually copy some files around
# because we have control of the setup. If you are
# building this manually or pip installing, you must satisfy
# that the vlfeat vl folder is on the PATH (for the headers)
# and that the vl.dll file is visible to the build system
# as well.
if IS_WIN and IS_CONDA:
    conda_bin_dir = os.environ['LIBRARY_BIN']
    conda_vl_dll_path = op.join(conda_bin_dir, 'vl.dll')
    INCLUDE_DIRS.append(os.environ['LIBRARY_INC'])
    LIBRARY_DIRS.append(conda_bin_dir)

vl_extensions = [
    gen_extension('cyvlfeat.sift.cysift',
                  [op.join('cyvlfeat', 'sift', 'cysift.pyx')]),
    gen_extension('cyvlfeat.fisher.cyfisher',
                  [op.join('cyvlfeat', 'fisher', 'cyfisher.pyx')]),
    gen_extension('cyvlfeat.hog.cyhog',
                  [op.join('cyvlfeat', 'hog', 'cyhog.pyx')]),
    gen_extension('cyvlfeat.kmeans.cykmeans',
                  [op.join('cyvlfeat', 'kmeans', 'cykmeans.pyx')]),
    gen_extension('cyvlfeat.generic.generic',
                  [op.join('cyvlfeat', 'generic', 'generic.pyx')]),
    gen_extension('cyvlfeat.gmm.cygmm',
                  [op.join('cyvlfeat', 'gmm', 'cygmm.pyx')])
]

# Grab all the pyx and pxd Cython files for uploading to pypi
cython_files = walk_for_package_data('*.p[xy][xd]')

setup(
    name='cyvlfeat',
    version=versioneer.get_version(),
    cmdclass=versioneer.get_cmdclass(),
    description='Cython wrapper of the VLFeat toolkit',
    url='https://github.com/menpo/cyvlfeat',
    author='Patrick Snape',
    author_email='p.snape@imperial.ac.uk',
    include_dirs=[np.get_include()],
    ext_modules=cythonize(vl_extensions),
    packages=find_packages(),
    package_data={'cyvlfeat': cython_files}
)

@@ -48,16 +48,37 @@
 tension%0A
+import pkg_resources%0A
 from Cyt
@@ -108,27 +108,8 @@
 ize%0A
-import numpy as np%0A
 impo
@@ -206,27 +206,312 @@
  = %5B
-%5D%0ALIBRARY_DIRS = %5B%5D
+pkg_resources.resource_filename('numpy', 'core/include')%5D%0ALIBRARY_DIRS = %5B%5D%0A%0A%0ASYS_PLATFORM = platform.system().lower()%0AIS_WIN = platform.system() == 'Windows'%0AIS_LINUX = 'linux' in SYS_PLATFORM%0AIS_OSX = 'darwin' == SYS_PLATFORM%0AIS_UNIX = IS_LINUX or IS_OSX%0AIS_CONDA = os.environ.get('CONDA_BUILD', False)
 %0A%0A%0Ad
@@ -907,82 +907,18 @@
     
-global INCLUDE_DIRS, LIBRARY_DIRS%0A    return Extension(%0A        path_name,
+kwargs = %7B
 %0A   
@@ -926,16 +926,19 @@
     
+'
 sources
-=
+': 
 sour
@@ -946,24 +946,25 @@
 es,%0A        
+'
 include_dirs
@@ -963,17 +963,19 @@
 ude_dirs
-=
+': 
 INCLUDE_
@@ -984,24 +984,25 @@
 RS,%0A        
+'
 library_dirs
@@ -1001,17 +1001,19 @@
 ary_dirs
-=
+': 
 LIBRARY_
@@ -1026,16 +1026,17 @@
         
+'
 librarie
@@ -1036,17 +1036,19 @@
 ibraries
-=
+': 
 %5B'vl'%5D,%0A
@@ -1059,16 +1059,17 @@
     
+'
 language
 ='c'
@@ -1068,17 +1068,19 @@
 uage
-=
+': 
 'c'%0A    
 )%0A%0A%0A
@@ -1079,99 +1079,132 @@
     
-)%0A%0A%0AIS_WIN = platform.system() == 'Windows'%0AIS_CONDA = os.environ.get('CONDA_BUILD', False)
+%7D%0A    if IS_UNIX:%0A        kwargs%5B'extra_compile_args'%5D = %5B'-Wno-unused-function'%5D%0A    return Extension(path_name, **kwargs)%0A
 %0A%0A# 
@@ -2828,45 +2828,8 @@
 k',%0A
-    include_dirs=%5Bnp.get_include()%5D,%0A
     

Remove numpy as build dep/quiet cython warnings