summaryrefslogtreecommitdiff
path: root/Cython/Build/Inline.py
diff options
context:
space:
mode:
Diffstat (limited to 'Cython/Build/Inline.py')
-rw-r--r--Cython/Build/Inline.py67
1 files changed, 26 insertions, 41 deletions
diff --git a/Cython/Build/Inline.py b/Cython/Build/Inline.py
index 69684e03f..abb891265 100644
--- a/Cython/Build/Inline.py
+++ b/Cython/Build/Inline.py
@@ -10,7 +10,9 @@ from distutils.core import Distribution, Extension
from distutils.command.build_ext import build_ext
import Cython
-from ..Compiler.Main import Context, default_options
+from ..Compiler.Main import Context
+from ..Compiler.Options import (default_options, CompilationOptions,
+ get_directive_defaults)
from ..Compiler.Visitor import CythonTransform, EnvTransform
from ..Compiler.ParseTreeTransforms import SkipDeclarations
@@ -34,6 +36,7 @@ if not IS_PY3:
else:
to_unicode = lambda x: x
+
if sys.version_info < (3, 5):
import imp
def load_dynamic(name, module_path):
@@ -48,9 +51,10 @@ else:
spec.loader.exec_module(module)
return module
+
class UnboundSymbols(EnvTransform, SkipDeclarations):
def __init__(self):
- CythonTransform.__init__(self, None)
+ super(EnvTransform, self).__init__(context=None)
self.unbound = set()
def visit_NameNode(self, node):
if not self.current_env().lookup(node.name):
@@ -65,7 +69,8 @@ class UnboundSymbols(EnvTransform, SkipDeclarations):
def unbound_symbols(code, context=None):
code = to_unicode(code)
if context is None:
- context = Context([], default_options)
+ context = Context([], get_directive_defaults(),
+ options=CompilationOptions(default_options))
from ..Compiler.ParseTreeTransforms import AnalyseDeclarationsTransform
tree = parse_from_strings('(tree fragment)', code)
for phase in Pipeline.create_pipeline(context, 'pyx'):
@@ -126,7 +131,11 @@ def _get_build_extension():
@cached_function
def _create_context(cython_include_dirs):
- return Context(list(cython_include_dirs), default_options)
+ return Context(
+ list(cython_include_dirs),
+ get_directive_defaults(),
+ options=CompilationOptions(default_options)
+ )
_cython_inline_cache = {}
@@ -170,6 +179,8 @@ def cython_inline(code, get_type=unsafe_type,
if language_level is not None:
cython_compiler_directives['language_level'] = language_level
+ key_hash = None
+
# Fast path if this has been called in this session.
_unbound_symbols = _cython_inline_cache.get(code)
if _unbound_symbols is not None:
@@ -205,7 +216,8 @@ def cython_inline(code, get_type=unsafe_type,
del kwds[name]
arg_names = sorted(kwds)
arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names])
- key_hash = _inline_key(orig_code, arg_sigs, language_level)
+ if key_hash is None:
+ key_hash = _inline_key(orig_code, arg_sigs, language_level)
module_name = "_cython_inline_" + key_hash
if module_name in sys.modules:
@@ -224,6 +236,7 @@ def cython_inline(code, get_type=unsafe_type,
os.makedirs(lib_dir)
if force or not os.path.isfile(module_path):
cflags = []
+ define_macros = []
c_include_dirs = []
qualified = re.compile(r'([.\w]+)[.]')
for type, _ in arg_sigs:
@@ -234,6 +247,7 @@ def cython_inline(code, get_type=unsafe_type,
if m.groups()[0] == 'numpy':
import numpy
c_include_dirs.append(numpy.get_include())
+ define_macros.append(("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"))
# cflags.append('-Wno-unused')
module_body, func_body = extract_func_code(code)
params = ', '.join(['%s %s' % a for a in arg_sigs])
@@ -256,10 +270,12 @@ def __invoke(%(params)s):
finally:
fh.close()
extension = Extension(
- name = module_name,
- sources = [pyx_file],
- include_dirs = c_include_dirs,
- extra_compile_args = cflags)
+ name=module_name,
+ sources=[pyx_file],
+ include_dirs=c_include_dirs or None,
+ extra_compile_args=cflags or None,
+ define_macros=define_macros or None,
+ )
if build_extension is None:
build_extension = _get_build_extension()
build_extension.extensions = cythonize(
@@ -322,37 +338,6 @@ def extract_func_code(code):
return '\n'.join(module), ' ' + '\n '.join(function)
-try:
- from inspect import getcallargs
-except ImportError:
- def getcallargs(func, *arg_values, **kwd_values):
- all = {}
- args, varargs, kwds, defaults = inspect.getargspec(func)
- if varargs is not None:
- all[varargs] = arg_values[len(args):]
- for name, value in zip(args, arg_values):
- all[name] = value
- for name, value in list(kwd_values.items()):
- if name in args:
- if name in all:
- raise TypeError("Duplicate argument %s" % name)
- all[name] = kwd_values.pop(name)
- if kwds is not None:
- all[kwds] = kwd_values
- elif kwd_values:
- raise TypeError("Unexpected keyword arguments: %s" % list(kwd_values))
- if defaults is None:
- defaults = ()
- first_default = len(args) - len(defaults)
- for ix, name in enumerate(args):
- if name not in all:
- if ix >= first_default:
- all[name] = defaults[ix - first_default]
- else:
- raise TypeError("Missing argument: %s" % name)
- return all
-
-
def get_body(source):
ix = source.index(':')
if source[:5] == 'lambda':
@@ -370,7 +355,7 @@ class RuntimeCompiledFunction(object):
self._body = get_body(inspect.getsource(f))
def __call__(self, *args, **kwds):
- all = getcallargs(self._f, *args, **kwds)
+ all = inspect.getcallargs(self._f, *args, **kwds)
if IS_PY3:
return cython_inline(self._body, locals=self._f.__globals__, globals=self._f.__globals__, **all)
else: