Skip to content

Commit

Permalink
do not fallback on build error (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane authored Sep 28, 2023
1 parent ecf0374 commit acd0684
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions setup.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,24 @@ class NoCython(Exception):


def cythonize(src):
if not have_cython:
raise Exception("Cython is required for building from checkout")
sys.stderr.write(f"cythonize: {src!r}\n")
cython_compiler.compile([src], cplus=True)


def ensure_source(src):
pyx = os.path.splitext(src)[0] + ".pyx"

if not os.path.exists(src):
if not have_cython:
raise NoCython
if not os.path.exists(src) or have_cython and os.stat(src).st_mtime < os.stat(pyx).st_mtime:
cythonize(pyx)
elif os.path.exists(pyx) and os.stat(src).st_mtime < os.stat(pyx).st_mtime and have_cython:
cythonize(pyx)
return src


class BuildExt(build_ext):
def build_extension(self, ext):
try:
ext.sources = list(map(ensure_source, ext.sources))
except NoCython:
print("WARNING")
print("Cython is required for building extension from checkout.")
print("Install Cython >= 0.16 or install msgpack from PyPI.")
print("Falling back to pure Python implementation.")
return
try:
return build_ext.build_extension(self, ext)
except Exception as e:
print("WARNING: Failed to compile extension modules.")
print("msgpack uses fallback pure python implementation.")
print(e)
for src in ext.sources:
ensure_source(src)
return build_ext.build_extension(self, ext)


# Cython is required for sdist
Expand Down

0 comments on commit acd0684

Please sign in to comment.