This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from mehdidc/fixsetupnumpyissue
Fix numpy install issue #60
- Loading branch information
Showing
1 changed file
with
105 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from setuptools import setup, Extension | ||
import numpy | ||
import sys | ||
import os | ||
import codecs | ||
|
@@ -13,90 +12,112 @@ | |
else: | ||
cythonize_switch = False | ||
|
||
# Find all includes | ||
local_inc = 'pyearth' | ||
numpy_inc = numpy.get_include() | ||
|
||
# Set up the ext_modules for Cython or not, depending | ||
if cythonize_switch: | ||
from Cython.Distutils import build_ext | ||
from Cython.Build import cythonize | ||
ext_modules = cythonize( | ||
[Extension( | ||
"pyearth._util", ["pyearth/_util.pyx"], include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._basis", | ||
["pyearth/_basis.pyx"], | ||
include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._record", | ||
["pyearth/_record.pyx"], | ||
include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._pruning", | ||
["pyearth/_pruning.pyx"], | ||
include_dirs=[local_inc, | ||
numpy_inc]), | ||
Extension( | ||
"pyearth._forward", | ||
["pyearth/_forward.pyx"], | ||
include_dirs=[local_inc, | ||
numpy_inc]), | ||
Extension( | ||
"pyearth._types", | ||
["pyearth/_types.pyx"], | ||
include_dirs=[local_inc, | ||
numpy_inc]) | ||
]) | ||
else: | ||
ext_modules = [Extension( | ||
"pyearth._util", ["pyearth/_util.c"], include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._basis", | ||
["pyearth/_basis.c"], | ||
include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._record", | ||
["pyearth/_record.c"], | ||
include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._pruning", | ||
["pyearth/_pruning.c"], | ||
include_dirs=[local_inc, | ||
numpy_inc]), | ||
Extension( | ||
"pyearth._forward", | ||
["pyearth/_forward.c"], | ||
include_dirs=[local_inc, | ||
numpy_inc]), | ||
Extension( | ||
"pyearth._types", | ||
["pyearth/_types.c"], | ||
include_dirs=[local_inc, | ||
numpy_inc]) | ||
] | ||
def get_ext_modules(): | ||
import numpy | ||
# Find all includes | ||
local_inc = 'pyearth' | ||
numpy_inc = numpy.get_include() | ||
|
||
# Set up the ext_modules for Cython or not, depending | ||
if cythonize_switch: | ||
from Cython.Build import cythonize | ||
ext_modules = cythonize( | ||
[Extension( | ||
"pyearth._util", ["pyearth/_util.pyx"], include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._basis", | ||
["pyearth/_basis.pyx"], | ||
include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._record", | ||
["pyearth/_record.pyx"], | ||
include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._pruning", | ||
["pyearth/_pruning.pyx"], | ||
include_dirs=[local_inc, | ||
numpy_inc]), | ||
Extension( | ||
"pyearth._forward", | ||
["pyearth/_forward.pyx"], | ||
include_dirs=[local_inc, | ||
numpy_inc]), | ||
Extension( | ||
"pyearth._types", | ||
["pyearth/_types.pyx"], | ||
include_dirs=[local_inc, | ||
numpy_inc]) | ||
]) | ||
else: | ||
ext_modules = [Extension( | ||
"pyearth._util", ["pyearth/_util.c"], include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._basis", | ||
["pyearth/_basis.c"], | ||
include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._record", | ||
["pyearth/_record.c"], | ||
include_dirs=[numpy_inc]), | ||
Extension( | ||
"pyearth._pruning", | ||
["pyearth/_pruning.c"], | ||
include_dirs=[local_inc, | ||
numpy_inc]), | ||
Extension( | ||
"pyearth._forward", | ||
["pyearth/_forward.c"], | ||
include_dirs=[local_inc, | ||
numpy_inc]), | ||
Extension( | ||
"pyearth._types", | ||
["pyearth/_types.c"], | ||
include_dirs=[local_inc, | ||
numpy_inc]) | ||
] | ||
return ext_modules | ||
|
||
def setup_package(): | ||
# Create a dictionary of arguments for setup | ||
setup_args = { | ||
'name': 'py-earth', | ||
'version': __version__, | ||
'author': 'Jason Rudy', | ||
'author_email': '[email protected]', | ||
'packages': ['pyearth', 'pyearth.test', | ||
'pyearth.test.basis', 'pyearth.test.record'], | ||
'license': 'LICENSE.txt', | ||
'description': | ||
'A Python implementation of Jerome Friedman\'s MARS algorithm.', | ||
'long_description': codecs.open('README.md', mode='r', encoding='utf-8').read(), | ||
'py_modules': ['pyearth.earth', 'pyearth._version'], | ||
'classifiers': ['Development Status :: 3 - Alpha'], | ||
'requires': ['numpy', 'scipy'], | ||
'install_requires': ['scikit-learn >= 0.16', | ||
'sphinx_gallery'], | ||
'setup_requires': ['numpy'] | ||
} | ||
|
||
# Add the build_ext command only if cythonizing | ||
if cythonize_switch: | ||
from Cython.Distutils import build_ext | ||
setup_args['cmdclass'] = {'build_ext': build_ext} | ||
|
||
# Create a dictionary of arguments for setup | ||
setup_args = {'name': 'py-earth', | ||
'version': __version__, | ||
'author': 'Jason Rudy', | ||
'author_email': '[email protected]', | ||
'packages': ['pyearth', 'pyearth.test', | ||
'pyearth.test.basis', 'pyearth.test.record'], | ||
'license': 'LICENSE.txt', | ||
'description': | ||
'A Python implementation of Jerome Friedman\'s MARS algorithm.', | ||
'long_description': codecs.open('README.md', mode='r', encoding='utf-8').read(), | ||
'py_modules': ['pyearth.earth', 'pyearth._version'], | ||
'ext_modules': ext_modules, | ||
'classifiers': ['Development Status :: 3 - Alpha'], | ||
'requires': ['numpy', 'scipy'], | ||
'install_requires': ['scikit-learn >= 0.16', | ||
'sphinx_gallery']} | ||
|
||
def is_special_command(): | ||
special_list = ('--help-commands', | ||
'egg_info', | ||
'--version', | ||
'clean') | ||
return ('--help' in sys.argv[1:] or | ||
sys.argv[1] in special_list) | ||
|
||
# Add the build_ext command only if cythonizing | ||
if cythonize_switch: | ||
setup_args['cmdclass'] = {'build_ext': build_ext} | ||
if len(sys.argv) >= 2 and is_special_command(): | ||
setup(**setup_args) | ||
else: | ||
setup_args['ext_modules'] = get_ext_modules() | ||
setup(**setup_args) | ||
|
||
# Finally | ||
setup(**setup_args) | ||
if __name__ == "__main__": | ||
setup_package() |