-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
77 lines (65 loc) · 2.34 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
import os
import os.path as osp
import platform
import sys
import numpy
from Cython.Compiler import Main
from setuptools import Distribution, Extension, setup
LIBNAME = "plotpy"
SRCPATH = osp.join(".", "src")
def is_msvc():
"""Detect if Microsoft Visual C++ compiler was chosen to build package"""
dist = Distribution()
dist.parse_config_files()
bld = dist.get_option_dict("build")
if bld:
comp = bld.get("compiler")
if comp is not None and "mingw32" in comp:
return False # mingw is the compiler
return os.name == "nt" and "mingw" not in "".join(sys.argv)
def compile_cython_extensions():
"""Compile Cython extensions"""
for fname in os.listdir(SRCPATH):
if osp.splitext(fname)[1] == ".pyx":
Main.compile(osp.join(SRCPATH, fname), language_level=2)
compile_cython_extensions()
INCLUDE_DIRS = [SRCPATH, numpy.get_include()]
MACROS_CYTHON = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
CFLAGS_CYTHON = []
MACROS_CPP = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
CFLAGS_CPP = ["/EHsc", "/fp:fast"] if is_msvc() else ["-Wall"]
if platform.system() == "Darwin":
CFLAGS_CPP += ["-std=c++11"]
setup(
ext_modules=[
Extension(
name=f"{LIBNAME}.mandelbrot",
sources=[osp.join(SRCPATH, "mandelbrot.c")],
include_dirs=INCLUDE_DIRS,
extra_compile_args=CFLAGS_CYTHON,
define_macros=MACROS_CYTHON,
),
Extension(
name=f"{LIBNAME}.histogram2d",
sources=[osp.join(SRCPATH, "histogram2d.c")],
include_dirs=INCLUDE_DIRS,
extra_compile_args=CFLAGS_CYTHON,
define_macros=MACROS_CYTHON,
),
Extension(
name=f"{LIBNAME}._scaler",
sources=[osp.join(SRCPATH, "scaler.cpp"), osp.join(SRCPATH, "pcolor.cpp")],
extra_compile_args=CFLAGS_CPP,
depends=[
osp.join(SRCPATH, "traits.hpp"),
osp.join(SRCPATH, "points.hpp"),
osp.join(SRCPATH, "arrays.hpp"),
osp.join(SRCPATH, "scaler.hpp"),
osp.join(SRCPATH, "debug.hpp"),
],
include_dirs=INCLUDE_DIRS,
define_macros=MACROS_CPP,
),
]
)