From 2627b6ae9f0606b388a3a3ec0110d1fdb33d082e Mon Sep 17 00:00:00 2001 From: Bas Westerbaan Date: Mon, 28 Jan 2013 12:27:46 +0100 Subject: setup: automatically fallback to pure Python module Signed-off-by: Bas Westerbaan --- setup.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index ac3eeb5..3d7fc04 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,9 @@ from setuptools import setup, Extension from distutils.command.build_ext import build_ext +class NoCython(Exception): + pass + try: import Cython.Compiler.Main as cython_compiler have_cython = True @@ -24,10 +27,7 @@ def ensure_source(src): if not os.path.exists(src): if not have_cython: - raise Exception("""\ -Cython is required for building extension from checkout. -Install Cython >= 0.16 or install msgpack from PyPI. -""") + raise NoCython cythonize(pyx) elif (os.path.exists(pyx) and os.stat(src).st_mtime < os.stat(pyx).st_mtime and @@ -38,7 +38,14 @@ Install Cython >= 0.16 or install msgpack from PyPI. class BuildExt(build_ext): def build_extension(self, ext): - ext.sources = list(map(ensure_source, ext.sources)) + 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 return build_ext.build_extension(self, ext) -- cgit v1.2.1 From 6fa0f46a122c4f6be35415a3e65dcdc542fd3acd Mon Sep 17 00:00:00 2001 From: Bas Westerbaan Date: Mon, 28 Jan 2013 14:32:01 +0100 Subject: setup: remove Python 2 only syntax --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index 3d7fc04..d4808d6 100644 --- a/setup.py +++ b/setup.py @@ -41,10 +41,10 @@ class BuildExt(build_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." + 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 return build_ext.build_extension(self, ext) -- cgit v1.2.1