Skip to content

Commit

Permalink
Reinstate setup.py to build Cython modules
Browse files Browse the repository at this point in the history
  • Loading branch information
johnveitch committed Jul 11, 2024
1 parent 15dbd24 commit ace24de
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os
import platform
import numpy
# Always prefer setuptools over distutils
from setuptools import setup
from setuptools import Extension

WINDOWS = platform.system().lower() == "windows"

# check whether user has Cython
try:
import Cython
except ImportError:
have_cython = False
else:
have_cython = True

# set extension
libraries = [] if WINDOWS else ["m"]
if have_cython: # convert the pyx file to a .c file if cython is available
from Cython.Build import cythonize
print('Running cython')
ext_modules = [Extension("cpnest.parameter",
sources=[os.path.join("cpnest", "parameter.pyx")],
include_dirs=['cpnest', numpy.get_include()],
libraries=libraries,
extra_compile_args=["-O3","-ffast-math"])]
ext_modules = cythonize(ext_modules)
else:
# just compile the included parameter.c (already converted from
# parameter.pyx) file
ext_modules = [Extension("cpnest.parameter",
sources=[os.path.join("cpnest", "parameter.c")],
include_dirs=['cpnest', numpy.get_include()],
libraries=libraries,
extra_compile_args=["-O3","-ffast-math"])]

here = os.path.abspath(os.path.dirname(__file__))

# Get the long description from the relevant file
with open(os.path.join(here, 'DESCRIPTION.rst'), encoding='utf-8') as f:
long_description = f.read()


setup(
name='cpnest',
use_scm_version=True,
description='CPNest: Parallel nested sampling',
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.9'
],
packages=['cpnest'],
include_dirs = [numpy.get_include()],
setup_requires=['numpy', 'cython', 'setuptools_scm'],
package_data={"": ['*.c', '*.pyx', '*.pxd']},
entry_points={},
test_suite='tests',
ext_modules=ext_modules
)

0 comments on commit ace24de

Please sign in to comment.