self_pxd = []
a = self.cimports(filename)
b = filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)])
- if len(a) != len(b):
- print(filename)
+ if len(a) - int('cython' in a) != len(b):
+ print("missing cimport", filename)
print("\n\t".join(a))
print("\n\t".join(b))
return tuple(self_pxd + filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)]))
return module_list
# This is the user-exposed entry point.
-def cythonize(module_list, exclude=[], nthreads=0, aliases=None, **options):
+def cythonize(module_list, exclude=[], nthreads=0, aliases=None, quiet=False, **options):
if 'include_path' not in options:
options['include_path'] = ['.']
c_options = CompilationOptions(**options)
dep_timestamp, dep = deps.newest_dependency(source)
priority = 2 - (dep in deps.immediate_dependencies(source))
if c_timestamp < dep_timestamp:
- if source == dep:
- print("Cythonizing %s because it changed." % source)
- else:
- print("Cythonizing %s because it depends on %s." % (source, dep))
+ if not quiet:
+ if source == dep:
+ print("Cythonizing %s because it changed." % source)
+ else:
+ print("Cythonizing %s because it depends on %s." % (source, dep))
to_compile.append((priority, source, c_file, options))
new_sources.append(c_file)
else:
-#no doctest
-print "Warning: Using prototype cython.inline code..."
-
import tempfile
import sys, os, re, inspect
lib_dir=os.path.expanduser('~/.cython/inline'),
cython_include_dirs=['.'],
force=False,
+ quiet=False,
locals=None,
globals=None,
**kwds):
elif symbol in globals:
kwds[symbol] = globals[symbol]
else:
- print "Couldn't find ", symbol
+ print("Couldn't find ", symbol)
except AssertionError:
- # Parsing from strings not fully supported (e.g. cimports).
- print "Could not parse code as a string (to extract unbound symbols)."
+ if not quiet:
+ # Parsing from strings not fully supported (e.g. cimports).
+ print("Could not parse code as a string (to extract unbound symbols).")
arg_names = kwds.keys()
arg_names.sort()
arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names])
extra_compile_args = cflags)
build_extension = build_ext(Distribution())
build_extension.finalize_options()
- build_extension.extensions = cythonize([extension], ctx=ctx)
+ build_extension.extensions = cythonize([extension], ctx=ctx, quiet=quiet)
build_extension.build_temp = os.path.dirname(pyx_file)
build_extension.build_lib = lib_dir
build_extension.run()
from Cython.Shadow import inline
-
+from Cython.Build.Inline import safe_type
from Cython.TestUtils import CythonTest
+try:
+ import numpy
+ has_numpy = True
+except:
+ has_numpy = False
+
+test_kwds = dict(force=True, quiet=True)
+
+global_value = 100
+
class TestStripLiterals(CythonTest):
- def test_inline(self):
- self.assertEquals(inline("return 1+2"), 3)
+ def test_simple(self):
+ self.assertEquals(inline("return 1+2", **test_kwds), 3)
+
+ def test_types(self):
+ self.assertEquals(inline("""
+ cimport cython
+ return cython.typeof(a), cython.typeof(b)
+ """, a=1.0, b=[], **test_kwds), ('double', 'list object'))
+
+ def test_locals(self):
+ a = 1
+ b = 2
+ self.assertEquals(inline("return a+b", **test_kwds), 3)
+
+ def test_globals(self):
+ self.assertEquals(inline("return global_value + 1", **test_kwds), global_value + 1)
+
+ if has_numpy:
+
+ def test_numpy(self):
+ import numpy
+ a = numpy.ndarray((10, 20))
+ a[0,0] = 10
+ self.assertEquals(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]')
+ self.assertEquals(inline("return a[0,0]", a=a, **test_kwds), 10.0)
if not f.endswith('.py'): continue
filepath = os.path.join(dirpath, f)
if os.path.getsize(filepath) == 0: continue
- if 'no doctest' in open(filepath).next(): continue
filepath = filepath[:-len(".py")]
modulename = module_prefix + filepath[len(path)+1:].replace(os.path.sep, '.')
if not [ 1 for match in selectors if match(modulename) ]: