Skip to content
Snippets Groups Projects
Commit 690a0ed8 authored by Martin Bauer's avatar Martin Bauer
Browse files

Fixed Cython deployment issues

parent eb7e77eb
No related merge requests found
......@@ -3,17 +3,25 @@ import itertools
import warnings
try:
import pyximport
pyximport.install(language_level=3)
# Try to import right away - assume compiled code is available
# compile with: python setup.py build_ext --inplace --use-cython
from pystencils.boundaries.createindexlistcython import create_boundary_neighbor_index_list_2d, \
create_boundary_neighbor_index_list_3d, create_boundary_cell_index_list_2d, create_boundary_cell_index_list_3d
cython_funcs_available = True
except Exception:
cython_funcs_available = False
create_boundary_index_list_2d = None
create_boundary_index_list_3d = None
except ImportError:
try:
# If not, try development mode and import via pyximport
import pyximport
pyximport.install(language_level=3)
cython_funcs_available = True
except ImportError:
cython_funcs_available = False
if cython_funcs_available:
from pystencils.boundaries.createindexlistcython import create_boundary_neighbor_index_list_2d, \
create_boundary_neighbor_index_list_3d, create_boundary_cell_index_list_2d, \
create_boundary_cell_index_list_3d
boundary_index_array_coordinate_names = ["x", "y", "z"]
direction_member_name = "dir"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
# distutils: language=c
# Workaround for cython bug
# see https://stackoverflow.com/questions/8024805/cython-compiled-c-extension-importerror-dynamic-module-does-not-define-init-fu
WORKAROUND = "Something"
......
......@@ -3,11 +3,18 @@ import sys
import io
from setuptools import setup, find_packages
import distutils
from distutils.extension import Extension
from contextlib import redirect_stdout
from importlib import import_module
sys.path.insert(0, os.path.abspath('doc'))
from version_from_git import version_number_from_git
if '--use-cython' in sys.argv:
USE_CYTHON = True
sys.argv.remove('--use-cython')
else:
USE_CYTHON = False
quick_tests = [
'test_datahandling.test_kernel',
......@@ -52,6 +59,15 @@ def readme():
return f.read()
def cython_extensions(*extensions):
ext = '.pyx' if USE_CYTHON else '.c'
result = [Extension(e, [e.replace('.', '/') + ext]) for e in extensions]
if USE_CYTHON:
from Cython.Build import cythonize
result = cythonize(result, language_level=3)
return result
setup(name='pystencils',
version=version_number_from_git(),
description='Speeding up stencil computations on CPUs and GPUs',
......@@ -64,6 +80,7 @@ setup(name='pystencils',
packages=['pystencils'] + ['pystencils.' + s for s in find_packages('pystencils')],
install_requires=['sympy>=1.1', 'numpy', 'appdirs', 'joblib'],
package_data={'pystencils': ['include/*.h']},
ext_modules = cython_extensions("pystencils.boundaries.createindexlistcython"),
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: Jupyter',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment