-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathsetup.py
More file actions
57 lines (49 loc) · 1.6 KB
/
Copy pathsetup.py
File metadata and controls
57 lines (49 loc) · 1.6 KB
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
import os
import shutil
import sys
import numpy as np
from setuptools import setup
from setuptools_rust import RustExtension
def _should_build_wheel():
for wheel_type in ["bdist_wheel", "editable_wheel"]:
if wheel_type in sys.argv:
return True
return False
if _should_build_wheel():
if not os.environ.get("BIOTITE_OMIT_RUST", False):
if not shutil.which("cargo"):
# Rust compiler is not installed -> Install it temporarily
# `puccinialin` is only required in this fallback case
from puccinialin import setup_rust
extra_env = setup_rust()
env = {**os.environ, **extra_env}
else:
env = None
rust_extensions = [
RustExtension(
target="biotite.rust",
path="Cargo.toml",
env=env,
)
]
else:
rust_extensions = None
if not os.environ.get("BIOTITE_OMIT_CYTHON", False):
from Cython.Build import cythonize
# Only build C files and compile them when building a wheel
cython_extensions = cythonize(
"src/**/*.pyx",
include_path=[np.get_include()],
)
for mod in cython_extensions:
mod.define_macros = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
mod.include_dirs = [np.get_include()]
else:
cython_extensions = None
setup(
ext_modules=cython_extensions,
rust_extensions=rust_extensions,
)
else:
# In the source distribution, the `.pyx` files are considered the source files
setup()