-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
63 lines (52 loc) · 1.62 KB
/
setup.py
File metadata and controls
63 lines (52 loc) · 1.62 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
58
59
60
61
62
63
"""Build script for zctw Cython extensions.
This allows pip to build the Cython extension when installing from source.
Usage:
pip install . # Install with pre-built extension if available
pip install --no-binary :all: . # Build from source with Cython
"""
import os
import sys
from pathlib import Path
from setuptools import setup, Extension
from Cython.Build import cythonize
# Get the directory where this setup.py is located
SETUP_DIR = Path(__file__).parent.resolve()
# Change to setup.py directory for relative paths
os.chdir(SETUP_DIR)
# Find .pyx files
src_dir = SETUP_DIR / "src" / "zctw"
pyx_files = list(src_dir.glob("*.pyx"))
if pyx_files:
ext_modules = []
for pyx in pyx_files:
ext_name = f"zctw.{pyx.stem}"
# Use relative path with forward slashes
rel_path = str(pyx.relative_to(SETUP_DIR)).replace(os.sep, "/")
ext_modules.append(
Extension(
ext_name,
sources=[rel_path],
include_dirs=["src"],
extra_compile_args=["-O3", "-ffast-math"],
)
)
ext_modules = cythonize(
ext_modules,
compiler_directives={
"language_level": "3",
"boundscheck": False,
"wraparound": False,
"cdivision": True,
},
)
else:
ext_modules = []
# Read version from pyproject.toml
try:
import tomllib
with open("pyproject.toml", "rb") as f:
config = tomllib.load(f)
version = config["project"]["version"]
except Exception:
version = "0.1.0"
setup(ext_modules=ext_modules, version=version)