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

Fixed Cython deployment issues

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