from distutils.extension import Extension
from Cython import Utils
+from Cython.Compiler.Main import Context, CompilationOptions, default_options
# Unfortunately, Python 2.3 doesn't support decorators.
def cached_method(f):
global _dep_tree
if _dep_tree is None:
if ctx is None:
- from Cython.Compiler.Main import Context, CompilationOptions
ctx = Context(["."], CompilationOptions(default_options))
_dep_tree = DependencyTree(ctx)
return _dep_tree
-# TODO: This may be useful for advanced users.
+# This may be useful for advanced users?
def create_extension_list(patterns, ctx=None, aliases=None):
seen = set()
deps = create_dependency_tree(ctx)
return module_list
# This is the user-exposed entry point.
-def cythonize(module_list, ctx=None, nthreads=0, aliases=None):
+def cythonize(module_list, nthreads=0, aliases=None, **options):
+ c_options = CompilationOptions(options)
+ cpp_options = CompilationOptions(options); cpp_options.cplus = True
+ ctx = options.create_context()
module_list = create_extension_list(module_list, ctx=ctx, aliases=aliases)
deps = create_dependency_tree(ctx)
to_compile = []
if ext in ('.pyx', '.py'):
if m.language == 'c++':
c_file = base + '.cpp'
+ options = cpp_options
else:
c_file = base + '.c'
+ options = c_options
if os.path.exists(c_file):
c_timestamp = os.path.getmtime(c_file)
else:
priority = 2 - (dep in deps.immediate_dependencies(source))
if c_timestamp < dep_timestamp:
print("Compiling %s because it depends on %s" % (source, dep))
- to_compile.append((priority, source, c_file))
+ to_compile.append((priority, source, c_file, options))
new_sources.append(c_file)
else:
new_sources.append(source)
print("multiprocessing required for parallel cythonization")
nthreads = 0
if not nthreads:
- for priority, pyx_file, c_file in to_compile:
- cythonize_one(pyx_file, c_file)
+ for priority, pyx_file, c_file, options in to_compile:
+ cythonize_one(pyx_file, c_file, options)
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.Main import compile, default_options
from Cython.Compiler.Errors import CompileError, PyrexError
if options is None:
def run_pipeline(source, options, full_module_name = None):
# Set up context
- context = Context(options.include_path, options.compiler_directives,
- options.cplus, options.language_level)
+ context = optons.create_context()
# Set up source object
cwd = os.getcwd()
self.__dict__.update(defaults)
self.__dict__.update(kw)
+ def create_context(self):
+ return Context(self.include_path, self.compiler_directives,
+ self.cplus, self.language_level)
+
class CompilationResult(object):
"""