setup.py 5.29 KB
Newer Older
Stephan Seitz's avatar
Stephan Seitz committed
1
2
import distutils
import io
3
4
import os
import sys
Martin Bauer's avatar
Martin Bauer committed
5
6
7
from contextlib import redirect_stdout
from importlib import import_module

8
9
import setuptools

Markus Holzer's avatar
Markus Holzer committed
10
11
import versioneer

12
13
try:
    import cython  # noqa
Martin Bauer's avatar
Martin Bauer committed
14
    USE_CYTHON = True
15
except ImportError:
Martin Bauer's avatar
Martin Bauer committed
16
17
    USE_CYTHON = False

Martin Bauer's avatar
Martin Bauer committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
quick_tests = [
    'test_datahandling.test_kernel',
    'test_blocking_staggered.test_blocking_staggered',
    'test_blocking_staggered.test_blocking_staggered',
    'test_vectorization.test_vectorization_variable_size',
]


class SimpleTestRunner(distutils.cmd.Command):
    """A custom command to run selected tests"""

    description = 'run some quick tests'
    user_options = []

    @staticmethod
    def _run_tests_in_module(test):
        """Short test runner function - to work also if py.test is not installed."""
        test = 'pystencils_tests.' + test
        mod, function_name = test.rsplit('.', 1)
        if isinstance(mod, str):
            mod = import_module(mod)

        func = getattr(mod, function_name)
Markus Holzer's avatar
Markus Holzer committed
41
        print(f"   -> {function_name} in {mod.__name__}" )
Martin Bauer's avatar
Martin Bauer committed
42
43
44
45
46
47
48
49
50
51
52
53
54
        with redirect_stdout(io.StringIO()):
            func()

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        """Run command."""
        for test in quick_tests:
            self._run_tests_in_module(test)
55

Stephan Seitz's avatar
Stephan Seitz committed
56

57
58
59
60
def readme():
    with open('README.md') as f:
        return f.read()

61

Martin Bauer's avatar
Martin Bauer committed
62
def cython_extensions(*extensions):
63
    from distutils.extension import Extension
Markus Holzer's avatar
Markus Holzer committed
64
    if USE_CYTHON:
Markus Holzer's avatar
Markus Holzer committed
65
66
        ext = '.pyx'
        result = [Extension(e, [os.path.join(*e.split(".")) + ext]) for e in extensions]
Markus Holzer's avatar
Markus Holzer committed
67
68
        from Cython.Build import cythonize
        result = cythonize(result, language_level=3)
Markus Holzer's avatar
Markus Holzer committed
69
70
71
72
73
74
75
        return result
    elif all([os.path.exists(os.path.join(*e.split(".")) + '.c') for e in extensions]):
        ext = '.c'
        result = [Extension(e, [os.path.join(*e.split(".")) + ext]) for e in extensions]
        return result
    else:
        return None
Martin Bauer's avatar
Martin Bauer committed
76

Markus Holzer's avatar
Markus Holzer committed
77
78
79
80
def get_cmdclass():
    cmdclass={"quicktest": SimpleTestRunner}
    cmdclass.update(versioneer.get_cmdclass())
    return cmdclass
Martin Bauer's avatar
Martin Bauer committed
81

Martin Bauer's avatar
Martin Bauer committed
82

Markus Holzer's avatar
Markus Holzer committed
83
84
setuptools.setup(name='pystencils',
                 description='Speeding up stencil computations on CPUs and GPUs',
Markus Holzer's avatar
Markus Holzer committed
85
                 version=versioneer.get_version(),
Markus Holzer's avatar
Markus Holzer committed
86
87
88
89
90
91
92
                 long_description=readme(),
                 long_description_content_type="text/markdown",
                 author='Martin Bauer',
                 license='AGPLv3',
                 author_email='martin.bauer@fau.de',
                 url='https://i10git.cs.fau.de/pycodegen/pystencils/',
                 packages=['pystencils'] + ['pystencils.' + s for s in setuptools.find_packages('pystencils')],
93
                 install_requires=['sympy>=1.2', 'numpy>=1.8.0', 'appdirs', 'joblib'],
Markus Holzer's avatar
Markus Holzer committed
94
                 package_data={'pystencils': ['include/*.h',
Markus Holzer's avatar
Markus Holzer committed
95
                                              'kerncraft_coupling/templates/*',
Markus Holzer's avatar
Markus Holzer committed
96
                                              'backends/cuda_known_functions.txt',
Markus Holzer's avatar
Markus Holzer committed
97
                                              'backends/opencl1.1_known_functions.txt',
Markus Holzer's avatar
Markus Holzer committed
98
                                              'boundaries/createindexlistcython.c',
Markus Holzer's avatar
Markus Holzer committed
99
                                              'boundaries/createindexlistcython.pyx']},
Markus Holzer's avatar
Markus Holzer committed
100
                 ext_modules=cython_extensions("pystencils.boundaries.createindexlistcython"),
Markus Holzer's avatar
Markus Holzer committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
                 classifiers=[
                     'Development Status :: 4 - Beta',
                     'Framework :: Jupyter',
                     'Topic :: Software Development :: Code Generators',
                     'Topic :: Scientific/Engineering :: Physics',
                     'Intended Audience :: Developers',
                     'Intended Audience :: Science/Research',
                     'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
                 ],
                 project_urls={
                     "Bug Tracker": "https://i10git.cs.fau.de/pycodegen/pystencils/issues",
                     "Documentation": "http://pycodegen.pages.walberla.net/pystencils/",
                     "Source Code": "https://i10git.cs.fau.de/pycodegen/pystencils",
                 },
                 extras_require={
                     'gpu': ['pycuda'],
                     'opencl': ['pyopencl'],
                     'alltrafos': ['islpy', 'py-cpuinfo'],
                     'bench_db': ['blitzdb', 'pymongo', 'pandas'],
                     'interactive': ['matplotlib', 'ipy_table', 'imageio', 'jupyter', 'pyevtk', 'rich', 'graphviz'],
                     'autodiff': ['pystencils-autodiff'],
                     'doc': ['sphinx', 'sphinx_rtd_theme', 'nbsphinx',
                             'sphinxcontrib-bibtex', 'sphinx_autodoc_typehints', 'pandoc'],
Markus Holzer's avatar
Markus Holzer committed
124
                     'use_cython': ['Cython']
Markus Holzer's avatar
Markus Holzer committed
125
126
127
128
129
130
131
132
133
                 },
                 tests_require=['pytest',
                                'pytest-cov',
                                'pytest-html',
                                'ansi2html',
                                'pytest-xdist',
                                'flake8',
                                'nbformat',
                                'nbconvert',
134
135
                                'ipython',
                                'randomgen>=1.18'],
Markus Holzer's avatar
Markus Holzer committed
136

137
                 python_requires=">=3.8",
Markus Holzer's avatar
Markus Holzer committed
138
                 cmdclass=get_cmdclass()
Markus Holzer's avatar
Markus Holzer committed
139
                 )