Cython build cleanup.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 5 Dec 2010 09:02:43 +0000 (01:02 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 5 Dec 2010 09:02:43 +0000 (01:02 -0800)
Cython/Build/Dependencies.py
Cython/Build/Inline.py

index 8a0f50d857c3ee6ab27d45ac04204b4147219d25..89777f79fd5bb5150b973cad7809c8aabbaec68b 100644 (file)
@@ -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
index ced513c65e442358ef6e4fb049c2f2a8f5bc214a..4c088eda9c3874b1523af3bfd0c739591d2f5512 100644 (file)
@@ -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()