From: Robert Bradshaw Date: Sun, 5 Dec 2010 09:02:43 +0000 (-0800) Subject: Cython build cleanup. X-Git-Tag: 0.14.alpha0~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bcb9ab3b645d35dd3ceff0dea002b102c68d52cf;p=cython.git Cython build cleanup. --- diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py index 8a0f50d8..89777f79 100644 --- a/Cython/Build/Dependencies.py +++ b/Cython/Build/Dependencies.py @@ -378,12 +378,11 @@ def create_dependency_tree(ctx=None): if _dep_tree is None: if ctx is None: from Cython.Compiler.Main import Context, CompilationOptions - ctx = Context(["."], CompilationOptions()) + ctx = Context(["."], CompilationOptions(default_options)) _dep_tree = DependencyTree(ctx) return _dep_tree -# TODO: Take common options. -# TODO: Symbolic names (e.g. for numpy.include_dirs() +# TODO: This may be useful for advanced users. def create_extension_list(patterns, ctx=None, aliases=None): seen = set() deps = create_dependency_tree(ctx) @@ -423,6 +422,7 @@ def create_extension_list(patterns, ctx=None, aliases=None): seen.add(name) return module_list +# This is the user-exposed entry point. def cythonize(module_list, ctx=None, nthreads=0, aliases=None): module_list = create_extension_list(module_list, ctx=ctx, aliases=aliases) deps = create_dependency_tree(ctx) @@ -456,21 +456,21 @@ def cythonize(module_list, ctx=None, nthreads=0, aliases=None): new_sources.append(source) m.sources = new_sources to_compile.sort() - # TODO: invoke directly if nthreads: # Requires multiprocessing (or Python >= 2.6) try: import multiprocessing + pool = multiprocessing.Pool(nthreads) + pool.map(cythonize_one_helper, to_compile) except ImportError: print("multiprocessing required for parallel cythonization") nthreads = 0 - pool = multiprocessing.Pool(nthreads) - pool.map(cythonize_one_helper, to_compile) if not nthreads: for priority, pyx_file, c_file in to_compile: cythonize_one(pyx_file, c_file) return module_list +# TODO: Share context? Issue: pyx processing leaks into pxd module def cythonize_one(pyx_file, c_file, options=None): from Cython.Compiler.Main import compile, CompilationOptions, default_options from Cython.Compiler.Errors import CompileError, PyrexError diff --git a/Cython/Build/Inline.py b/Cython/Build/Inline.py index ced513c6..4c088eda 100644 --- a/Cython/Build/Inline.py +++ b/Cython/Build/Inline.py @@ -50,12 +50,13 @@ def unbound_symbols(code, context=None): if not tree.scope.lookup(name) and not hasattr(__builtin__, name): unbound.append(name) return unbound - def get_type(arg, context=None): py_type = type(arg) if py_type in [list, tuple, dict, str]: return py_type.__name__ + elif py_type is complex: + return 'double complex' elif py_type is float: return 'double' elif py_type is bool: @@ -75,11 +76,10 @@ def get_type(arg, context=None): return '%s.%s' % (base_type.__module__, base_type.__name__) return 'object' -# TODO: use locals/globals for unbound variables def cython_inline(code, types='aggressive', lib_dir=os.path.expanduser('~/.cython/inline'), - include_dirs=['.'], + cython_include_dirs=['.'], locals=None, globals=None, **kwds): @@ -108,9 +108,6 @@ def cython_inline(code, arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names]) key = code, arg_sigs, sys.version_info, sys.executable, Cython.__version__ module_name = "_cython_inline_" + hashlib.md5(str(key)).hexdigest() -# # TODO: Does this cover all the platforms? -# if (not os.path.exists(os.path.join(lib_dir, module_name + ".so")) and -# not os.path.exists(os.path.join(lib_dir, module_name + ".dll"))): try: if not os.path.exists(lib_dir): os.makedirs(lib_dir) @@ -147,7 +144,7 @@ def __invoke(%(params)s): include_dirs = c_include_dirs) build_extension = build_ext(Distribution()) build_extension.finalize_options() - build_extension.extensions = cythonize([extension]) + build_extension.extensions = cythonize([extension], ctx=ctx) build_extension.build_temp = os.path.dirname(pyx_file) build_extension.build_lib = lib_dir build_extension.run()