-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
65 lines (53 loc) · 1.9 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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from pathlib import Path
from typing import List
import numpy
from Cython.Build import cythonize
from setuptools import find_packages, setup
from setuptools.command.build_ext import build_ext
from setuptools.extension import Extension
def find_files(root: Path, ext: str) -> List[str]:
"""
Search for files of given extension recursively within root
"""
return [str(file) for file in Path(root).glob("*" + ext)]
class Build(build_ext):
def build_extensions(self):
if self.compiler.compiler_type in ["unix", "mingw32"]:
for e in self.extensions:
if e.name == "picoscenes":
e.extra_compile_args = ["-std=c++2a", "-Wno-attributes", "-O3"]
if self.compiler.compiler_type in ["msvc"]:
for e in self.extensions:
if e.name == "picoscenes":
e.extra_compile_args = ["/std:c++latest"]
super(Build, self).build_extensions()
pico_root = Path.cwd() / "rxs_parsing_core"
pico_generated = pico_root / "preprocess" / "generated"
pico_include = pico_root / "preprocess"
pico_source = find_files(pico_root, ".cxx") + find_files(pico_generated, ".cpp")
pico_extension = Extension(
"picoscenes",
["./picoscenes.pyx"] + pico_source,
include_dirs=[numpy.get_include(), str(pico_include)],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
if not pico_root.is_dir():
raise RuntimeError(
f"Parsing core submodule {pico_root} is not a directory; "
+ "Did you initialize the submodule?"
)
EXTENSIONS = [pico_extension]
setup(
name="picoscenes",
version="0.1.0",
packages=find_packages(),
install_requires=["numpy"],
python_requires=">=3",
ext_modules=cythonize(
EXTENSIONS, compiler_directives={"language_level": 3, "binding": False}
),
cmdclass={"build_ext": Build},
)