Skip to content

Commit

Permalink
Update setup.py to compile Cython code in ndindex/
Browse files Browse the repository at this point in the history
  • Loading branch information
asmeurer committed Jul 23, 2024
1 parent 5bfd96e commit d3ee33c
Showing 1 changed file with 3 additions and 38 deletions.
41 changes: 3 additions & 38 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,9 @@
with open("README.md", "r") as fh:
long_description = fh.read()

def check_cython():
"""
Check to see if Cython is installed and able to compile extensions (which
requires a C compiler and the Python headers to be installed).
Return True on success, False on failure.
"""
argv_org = list(sys.argv)
try:
from Cython.Build import cythonize
sys.argv = argv_org[:1] + ["build_ext"]
setuptools.setup(name="foo", version="1.0.0",
ext_modules=cythonize(
["ndindex/__init__.py"],
language_level="3"))
except:
return False
finally:
sys.argv = argv_org
return True

CYTHONIZE_NDINDEX = os.getenv("CYTHONIZE_NDINDEX")
if CYTHONIZE_NDINDEX is None:
use_cython = check_cython()
else:
try:
use_cython = bool(int(CYTHONIZE_NDINDEX))
except ValueError:
sys.exit("Acceptable values for CYTHONIZE_NDINDEX are '0' and '1', "
"got: %r" % CYTHONIZE_NDINDEX)

if use_cython:
from Cython.Build import cythonize
ext_modules = cythonize(["ndindex/*.py"],
language_level="3")
else:
ext_modules = []
from Cython.Build import cythonize
ext_modules = cythonize(["ndindex/*.pyx"],
language_level="3")

setuptools.setup(
name="ndindex",
Expand Down Expand Up @@ -72,5 +39,3 @@ def check_cython():
],
python_requires='>=3.8',
)

print("CYTHONIZE_NDINDEX: %r" % CYTHONIZE_NDINDEX)

0 comments on commit d3ee33c

Please sign in to comment.