| 1 |
#! /usr/bin/env python |
| 2 |
''' |
| 3 |
Brian2 setup script |
| 4 |
''' |
| 5 |
|
| 6 |
# isort:skip_file |
| 7 |
|
| 8 |
import os |
| 9 |
import numpy |
| 10 |
from setuptools import setup, Extension |
| 11 |
from typing import List |
| 12 |
|
| 13 |
# A Helper function to require cython extension |
| 14 |
def require_cython_extension(module_path, module_name,extra_include_dirs=None): |
| 15 |
""" |
| 16 |
Create a cythonized Extension object from a .pyx source. |
| 17 |
""" |
| 18 |
# File paths |
| 19 |
base_path = os.path.join(*module_path) |
| 20 |
pyx_file = os.path.join(base_path, f"{module_name}.pyx") |
| 21 |
|
| 22 |
# Module name for setuptools |
| 23 |
full_module_name = ".".join(module_path + [module_name]) |
| 24 |
|
| 25 |
include_dirs = [numpy.get_include()] |
| 26 |
if extra_include_dirs: |
| 27 |
include_dirs.extend(extra_include_dirs) |
| 28 |
|
| 29 |
ext = Extension(full_module_name, [pyx_file],include_dirs=include_dirs) |
| 30 |
return ext |
| 31 |
|
| 32 |
|
| 33 |
# Collect Extensions |
| 34 |
extensions : List[Extension]=[] |
| 35 |
|
| 36 |
# Now Cython is required and no python fallback is possible |
| 37 |
spike_queue_ext = require_cython_extension( |
| 38 |
module_path=["brian2", "synapses"], |
| 39 |
module_name="cythonspikequeue", |
| 40 |
) |
| 41 |
|
| 42 |
extensions.append(spike_queue_ext) |
| 43 |
|
| 44 |
dynamic_array_ext = require_cython_extension( |
| 45 |
module_path=["brian2", "memory"], |
| 46 |
module_name="cythondynamicarray", |
| 47 |
extra_include_dirs=["brian2/devices/cpp_standalone/brianlib"] |
| 48 |
) |
| 49 |
|
| 50 |
extensions.append(dynamic_array_ext) |
| 51 |
|
| 52 |
|
| 53 |
setup(ext_modules=extensions) |