Skip to content

Commit

Permalink
Unconditionalize Cython build crap.
Browse files Browse the repository at this point in the history
Always use Cython's build_ext.  To build from sdist, you will need
Cython.  It is a *source* distribution, after all.  If you want a
pre-compiled distribution, make it yourself.
  • Loading branch information
riastradh-probcomp committed Nov 2, 2015
1 parent 6b389c8 commit cd874d0
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,13 @@
with open('src/version.py', 'w') as f:
f.writelines(version_new)

# If we're building from Git (no PKG-INFO), we use Cython. If we're
# building from an sdist (PKG-INFO exists), we will already have run
# Cython to compile the .pyx files into .cpp files, and we can treat
# them as normal C++ extensions.
USE_CYTHON = not os.path.exists('PKG-INFO')

cmdclass = dict()
if USE_CYTHON:
try:
from Cython.Distutils import build_ext
except ImportError:
source_ext = '.cpp'
else:
cmdclass = {'build_ext': build_ext}
source_ext = '.pyx'
else:
source_ext = '.cpp'
try:
from Cython.Distutils import build_ext
except ImportError:
import distutils.command.build_ext
class build_ext(distutils.command.build_ext.build_ext):
def build_extension(self, extension):
raise Exception('Cython is unavailable to compile .pyx files.')


try:
Expand Down Expand Up @@ -111,7 +101,7 @@ def generate_sources(dir_files_tuples):


# specify sources
ContinuousComponentModel_pyx_sources = ['ContinuousComponentModel'+source_ext]
ContinuousComponentModel_pyx_sources = ['ContinuousComponentModel.pyx']
ContinuousComponentModel_cpp_sources = [
'utils.cpp',
'numerics.cpp',
Expand All @@ -124,7 +114,7 @@ def generate_sources(dir_files_tuples):
(cpp_src_dir, ContinuousComponentModel_cpp_sources),
])
#
MultinomialComponentModel_pyx_sources = ['MultinomialComponentModel'+source_ext]
MultinomialComponentModel_pyx_sources = ['MultinomialComponentModel.pyx']
MultinomialComponentModel_cpp_sources = [
'utils.cpp',
'numerics.cpp',
Expand All @@ -137,7 +127,7 @@ def generate_sources(dir_files_tuples):
(cpp_src_dir, MultinomialComponentModel_cpp_sources),
])
#
CyclicComponentModel_pyx_sources = ['CyclicComponentModel'+source_ext]
CyclicComponentModel_pyx_sources = ['CyclicComponentModel.pyx']
CyclicComponentModel_cpp_sources = [
'utils.cpp',
'numerics.cpp',
Expand All @@ -150,7 +140,7 @@ def generate_sources(dir_files_tuples):
(cpp_src_dir, CyclicComponentModel_cpp_sources),
])
#
State_pyx_sources = ['State'+source_ext]
State_pyx_sources = ['State.pyx']
State_cpp_sources = [
'utils.cpp',
'numerics.cpp',
Expand Down Expand Up @@ -207,11 +197,6 @@ def generate_sources(dir_files_tuples):
State_ext,
]

# XXX Mega-kludge!
if USE_CYTHON and len(sys.argv) > 1 and sys.argv[1] == 'sdist':
from Cython.Build import cythonize
ext_modules = cythonize(ext_modules)

packages = [
'crosscat',
'crosscat.utils',
Expand Down Expand Up @@ -262,5 +247,7 @@ def generate_sources(dir_files_tuples):
'crosscat.utils': 'src/utils',
},
ext_modules=ext_modules,
cmdclass=cmdclass,
cmdclass={
'build_ext': build_ext,
},
)

0 comments on commit cd874d0

Please sign in to comment.