From ba5e2645bf9dd706fc0296b0cf7aeff1b42a660c Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Tue, 16 Oct 2018 09:01:39 -0500 Subject: [PATCH] Build with Cython 0.29 using '3str' as the language level. Fixes #94 --- CHANGES.rst | 2 +- requirements.txt | 2 +- setup.py | 59 ++++++++++++++++++++++++++++++------------------ tox.ini | 2 +- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8493d02..6d532ad 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,7 @@ 1.0.0a14 (unreleased) ===================== -- Nothing changed yet. +- Build with Cython 0.29 using '3str' as the language level. 1.0.0a13 (2018-09-20) diff --git a/requirements.txt b/requirements.txt index f1fc108..5140e27 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -cython >= 0.28.4 +cython >= 0.29 .[test,docs,benchmarks] diff --git a/setup.py b/setup.py index dee8258..d454b18 100755 --- a/setup.py +++ b/setup.py @@ -31,24 +31,26 @@ def _read(fname): # Cython +# Based on code from +# http://cython.readthedocs.io/en/latest/src/reference/compilation.html#distributing-cython-modules +def _dummy_cythonize(extensions, **_kwargs): + for extension in extensions: + sources = [] + for sfile in extension.sources: + path, ext = os.path.splitext(sfile) + if ext in ('.pyx', '.py'): + ext = '.c' + sfile = path + ext + sources.append(sfile) + extension.sources[:] = sources + return extensions + try: from Cython.Build import cythonize except ImportError: # The .c files had better already exist, as they should in - # an sdist. Based on code from - # http://cython.readthedocs.io/en/latest/src/reference/compilation.html#distributing-cython-modules - def cythonize(extensions, **_kwargs): - for extension in extensions: - sources = [] - for sfile in extension.sources: - path, ext = os.path.splitext(sfile) - if ext in ('.pyx', '.py'): - ext = '.c' - sfile = path + ext - sources.append(sfile) - extension.sources[:] = sources - return extensions - + # an sdist. + cythonize = _dummy_cythonize ext_modules = [] @@ -119,14 +121,27 @@ def _c(m): define_macros=[('CYTHON_TRACE', '1')], )) - ext_modules = cythonize( - ext_modules, - annotate=True, - compiler_directives={ - #'linetrace': True, - 'infer_types': True, - }, - ) + try: + ext_modules = cythonize( + ext_modules, + annotate=True, + compiler_directives={ + #'linetrace': True, + 'infer_types': True, + 'language_level': '3str', + 'always_allow_keywords': False, + 'nonecheck': False, + }, + ) + except ValueError: + # 'invalid literal for int() with base 10: '3str' + # This is seen when an older version of Cython is installed. + # It's a bit of a chicken-and-egg, though, because installing + # from dev-requirements first scans this egg for its requirements + # before doing any updates. + import traceback + traceback.print_exc() + ext_modules = _dummy_cythonize(ext_modules) setup( name='nti.externalization', diff --git a/tox.ini b/tox.ini index abe7b08..fde1eac 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ envlist = commands = zope-testrunner --test-path=src [] deps = - Cython >= 0.28.4 + Cython >= 0.29 .[test] [testenv:py27-pure]