-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.py
80 lines (63 loc) · 2.23 KB
/
build.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
78
79
80
import os
import sys
import numpy as np
from Cython.Build import cythonize
from setuptools import Extension
from setuptools import setup
# skgrf project directory
top = os.path.dirname(os.path.abspath(__file__))
# include skgrf, grf, and numpy headers
# requires running buildpre.py to find src in this location
include_dirs = [
top,
os.path.join(top, "skgrf"),
*[d[0] for d in os.walk(os.path.join(top, "skgrf", "grf", "src"))],
*[d[0] for d in os.walk(os.path.join(top, "skgrf", "grf", "third_party"))],
np.get_include(),
]
def find_ext_files(directory, ext="pyx", files=None):
"""Recursively find all Cython extension files.
:param str directory: The directory in which to recursively crawl for .pyx files.
:param list files: A list of files in which to append discovered .pyx files.
"""
if files is None:
files = []
for file in os.listdir(directory):
path = os.path.join(directory, file)
if os.path.isfile(path) and path.endswith("." + ext):
files.append(path)
elif os.path.isdir(path):
find_ext_files(path, ext, files)
return files
def create_extension(module_name, additional_sources=None):
"""Create a setuptools build extension for a Cython extension file.
:param str module_name: The name of the module
:param list(str) additional_sources: A list of additional source filenames
"""
path = module_name.replace(".", os.path.sep) + ".pyx"
additional_sources = additional_sources or []
return Extension(
module_name,
sources=[path] + additional_sources,
include_dirs=include_dirs,
language="c++",
extra_compile_args=["-std=c++11", "-Wall", "-O3"],
extra_link_args=["-std=c++11", "-g"],
# define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
ext_modules = [create_extension("skgrf.grf")]
def build_ext():
setup(
name="skgrf",
ext_modules=cythonize(
ext_modules,
gdb_debug=False,
force=True,
annotate=False,
compiler_directives={"language_level": "3"},
),
)
if "clean" in sys.argv or "build_ext" in sys.argv:
build_ext()
def build(setup_kwargs):
build_ext()