From f43a1f0d6559fca24d3b77a69ba202e9df95aba3 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Fri, 9 Aug 2013 00:00:49 -0700 Subject: [PATCH] Tests for common include dir. --- Cython/Build/Dependencies.py | 6 +++++ Cython/Compiler/Code.py | 2 +- tests/build/common_include_dir.srctree | 49 ++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/build/common_include_dir.srctree diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py index 2032318..b7c521c 100644 --- a/Cython/Build/Dependencies.py +++ b/Cython/Build/Dependencies.py @@ -652,6 +652,9 @@ def cythonize(module_list, exclude=[], nthreads=0, aliases=None, quiet=False, fo """ if 'include_path' not in options: options['include_path'] = ['.'] + if 'common_utility_include_dir' in options: + if not os.path.exists(options['common_utility_include_dir']): + os.makedirs(options['common_utility_include_dir']) c_options = CompilationOptions(**options) cpp_options = CompilationOptions(**options); cpp_options.cplus = True ctx = c_options.create_context() @@ -811,6 +814,9 @@ def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None, raise_on_f except (EnvironmentError, PyrexError), e: sys.stderr.write('%s\n' % e) any_failures = 1 + # XXX + import traceback + traceback.print_exc() except Exception: if raise_on_failure: raise diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index b608104..2a0213c 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -1540,7 +1540,7 @@ class CCodeWriter(object): def put_or_include(self, code, name): include_dir = self.globalstate.common_utility_include_dir - if include_dir and len(code) > 1042: + if include_dir and len(code) > 1024: include_file = "%s_%s.h" % ( name, hashlib.md5(code).hexdigest()) path = os.path.join(include_dir, include_file) diff --git a/tests/build/common_include_dir.srctree b/tests/build/common_include_dir.srctree new file mode 100644 index 0000000..94626d1 --- /dev/null +++ b/tests/build/common_include_dir.srctree @@ -0,0 +1,49 @@ +PYTHON setup.py build_ext --inplace +PYTHON -c "import runner" + +# Verify some files were created. +ls common/AddTraceback_impl*.h common/RaiseException_impl_*.h + +# Verify that they're used. +grep -c '#include "common/AddTraceback_impl_.*h"' a.c +grep -c '#include "common/AddTraceback_impl_.*h"' b.c +grep -c '#include "common/AddTraceback_impl_.*h"' c.c + + +######## setup.py ######## + +from Cython.Build.Dependencies import cythonize + +from distutils.core import setup + +setup( + ext_modules = cythonize("*.pyx", common_utility_include_dir='common', nthreads=2), +) + +######## a.pyx ######## + +def generator(n): + for k in range(n): + yield k + +assert list(generator(10)) == list(range(10)) + +######## b.pyx ######## + +def generator(n): + for k in range(n): + yield k + +assert list(generator(10)) == list(range(10)) + +if __name__ == "__main__": + print "here", "b" + +######## c.pyx ######## + +if __name__ == "__main__": + print "here", "c" + +######## runner.py ######## + +import a, b, c -- 2.7.4