Commit cc43e481 authored by Robert Bradshaw's avatar Robert Bradshaw

Allow pure cython directives in inline/compiled code.

parent f81c0b0b
...@@ -16,6 +16,7 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration ...@@ -16,6 +16,7 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration
from Cython.Compiler.TreeFragment import parse_from_strings from Cython.Compiler.TreeFragment import parse_from_strings
from Cython.Build.Dependencies import strip_string_literals, cythonize from Cython.Build.Dependencies import strip_string_literals, cythonize
from Cython.Compiler import Pipeline from Cython.Compiler import Pipeline
import cython as cython_module
# A utility function to convert user-supplied ASCII strings to unicode. # A utility function to convert user-supplied ASCII strings to unicode.
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
...@@ -125,6 +126,11 @@ def cython_inline(code, ...@@ -125,6 +126,11 @@ def cython_inline(code,
if not quiet: if not quiet:
# Parsing from strings not fully supported (e.g. cimports). # Parsing from strings not fully supported (e.g. cimports).
print("Could not parse code as a string (to extract unbound symbols).") print("Could not parse code as a string (to extract unbound symbols).")
cimports = []
for name, arg in kwds.items():
if arg is cython_module:
cimports.append('\ncimport cython as %s' % name)
del kwds[name]
arg_names = kwds.keys() arg_names = kwds.keys()
arg_names.sort() arg_names.sort()
arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names]) arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names])
...@@ -142,7 +148,6 @@ def cython_inline(code, ...@@ -142,7 +148,6 @@ def cython_inline(code,
except ImportError: except ImportError:
cflags = [] cflags = []
c_include_dirs = [] c_include_dirs = []
cimports = []
qualified = re.compile(r'([.\w]+)[.]') qualified = re.compile(r'([.\w]+)[.]')
for type, _ in arg_sigs: for type, _ in arg_sigs:
m = qualified.match(type) m = qualified.match(type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment