File size: 1,525 Bytes
1936615 295a180 78550c2 295a180 1936615 295a180 1936615 295a180 78550c2 295a180 | 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 | from setuptools import setup, Extension
import os
# Allow building from .py (via Cython) if present, otherwise from .c files already generated.
use_cython = False
try:
from Cython.Build import cythonize
use_cython = True
except Exception:
use_cython = False
exts = []
# Determine sources for each extension: prefer .py when cython is available and .py exists,
# otherwise use .c if present.
modules = [
("utils.__init__", "utils/__init__"),
("utils.benchmark_utils", "utils/benchmark_utils"),
]
for mod_name, base in modules:
py = base + ".py"
c = base + ".c"
if use_cython and os.path.exists(py):
exts.append(Extension(mod_name, [py]))
elif os.path.exists(c):
exts.append(Extension(mod_name, [c]))
elif os.path.exists(py):
# Cython might not be installed but .py sources exist; fall back to pure-Python install (no ext)
# In this case, don't create an Extension; the package will use pure Python files.
pass
else:
# Nothing to compile for this module; that may be fine if a compiled .so already exists.
pass
if use_cython and exts:
setup(
name="my_utils_package",
ext_modules=cythonize(
exts,
compiler_directives={'language_level': "3"}
)
)
elif exts:
setup(
name="my_utils_package",
ext_modules=exts
)
else:
# Nothing to build; create a minimal package metadata so setup.py can be called harmlessly.
setup(name="my_utils_package")
|