From 61460261f0a6f4e6e8fc9ab444bc43f2280f07f2 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Tue, 17 Nov 2015 18:44:13 -0800 Subject: [PATCH] Updates to setup.py Add a cleanall, and try to make the cython build things in the correct place. --- setup.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index bca20d59..04427658 100644 --- a/setup.py +++ b/setup.py @@ -5,10 +5,15 @@ SimPEG is a python package for simulation and gradient based parameter estimation in the context of geophysical applications. """ +import numpy as np + +import os +import sys +import subprocess + from distutils.core import setup from setuptools import find_packages from distutils.extension import Extension -import numpy as np CLASSIFIERS = [ 'Development Status :: 4 - Beta', @@ -26,14 +31,31 @@ CLASSIFIERS = [ 'Natural Language :: English', ] +args = sys.argv[1:] -from distutils.core import setup +# Make a `cleanall` rule to get rid of intermediate and library files +if "cleanall" in args: + print "Deleting cython files..." + # Just in case the build directory was created by accident, + # note that shell=True should be OK here because the command is constant. + subprocess.Popen("rm -rf build", shell=True, executable="/bin/bash") + subprocess.Popen("find . -name \*.c -type f -delete", shell=True, executable="/bin/bash") + subprocess.Popen("find . -name \*.so -type f -delete", shell=True, executable="/bin/bash") + # Now do a normal clean + sys.argv[sys.argv.index('cleanall')] = "clean" + +# We want to always use build_ext --inplace +if args.count("build_ext") > 0 and args.count("--inplace") == 0: + sys.argv.insert(sys.argv.index("build_ext")+1, "--inplace") try: from Cython.Build import cythonize + from Cython.Distutils import build_ext + cythonKwargs = dict(cmdclass={'build_ext': build_ext}) USE_CYTHON = True except Exception, e: USE_CYTHON = False + cythonKwargs = dict() ext = '.pyx' if USE_CYTHON else '.c' @@ -41,9 +63,9 @@ cython_files = [ "SimPEG/Utils/interputils_cython", "SimPEG/Mesh/TreeUtils" ] -extensions = [Extension(f, [f+ext]) for f in cython_files] +extensions = [Extension(f, [f+ext], include_dirs=[np.get_include()]) for f in cython_files] -if USE_CYTHON: +if USE_CYTHON and "cleanall" not in args: from Cython.Build import cythonize extensions = cythonize(extensions) @@ -71,6 +93,6 @@ setup( classifiers=CLASSIFIERS, platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], use_2to3 = False, - include_dirs=[np.get_include()], - ext_modules = extensions + ext_modules = extensions, + **cythonKwargs )