forked from SciTools/mo_pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
46 lines (35 loc) · 1.25 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
from setuptools import Command, Extension, setup
from pathlib import Path
from Cython.Build import cythonize
import numpy as np
BASE_DIR = Path(__file__).resolve().parent
PACKAGE_NAME = "mo_pack"
SRC_DIR = BASE_DIR / "src"
PACKAGE_DIR = SRC_DIR / PACKAGE_NAME
class CleanCython(Command):
description = "Purge artifacts built by Cython"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
for path in PACKAGE_DIR.rglob("*"):
if path.suffix in (".pyc", ".pyo", ".c", ".so"):
msg = f"clean: removing file {path}"
print(msg)
path.unlink()
# https://setuptools.pypa.io/en/latest/userguide/ext_modules.html
extension = Extension(
f"{PACKAGE_NAME}._packing",
[f"src/{PACKAGE_NAME}/_packing.pyx"],
include_dirs=[np.get_include()],
libraries=["mo_unpack"],
# https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html?highlight=NPY_NO_DEPRECATED_API#numpy-c-api
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
extra_compile_args=["-std=c99"],
)
setup(
cmdclass={"clean_cython": CleanCython},
ext_modules=cythonize(extension, language_level="3str"),
)