Commit e023f0e3 authored by Mark Florisson's avatar Mark Florisson

Defer loading cython scope until necessary

parent 602b8cff
...@@ -9,6 +9,7 @@ import MemoryView ...@@ -9,6 +9,7 @@ import MemoryView
class CythonScope(ModuleScope): class CythonScope(ModuleScope):
is_cython_builtin = 1 is_cython_builtin = 1
_cythonscope_initialized = False
def __init__(self, context): def __init__(self, context):
ModuleScope.__init__(self, u'cython', None, None) ModuleScope.__init__(self, u'cython', None, None)
...@@ -23,11 +24,26 @@ class CythonScope(ModuleScope): ...@@ -23,11 +24,26 @@ class CythonScope(ModuleScope):
if type: if type:
return type return type
return super(CythonScope, self).lookup_type(name)
def lookup(self, name):
entry = super(CythonScope, self).lookup(name)
if entry is None and not self._cythonscope_initialized:
self.load_cythonscope()
entry = super(CythonScope, self).lookup(name)
return entry
def find_module(self, module_name, pos): def find_module(self, module_name, pos):
error("cython.%s is not available" % module_name, pos) error("cython.%s is not available" % module_name, pos)
def find_submodule(self, module_name): def find_submodule(self, module_name):
entry = self.entries.get(module_name, None) entry = self.entries.get(module_name, None)
if not entry:
self.load_cythonscope()
entry = self.entries.get(module_name, None)
if entry and entry.as_module: if entry and entry.as_module:
return entry.as_module return entry.as_module
else: else:
...@@ -68,13 +84,15 @@ class CythonScope(ModuleScope): ...@@ -68,13 +84,15 @@ class CythonScope(ModuleScope):
defining = 1, defining = 1,
cname = 'PyObject_TypeCheck') cname = 'PyObject_TypeCheck')
# self.test_cythonscope() def load_cythonscope(self):
def test_cythonscope(self):
""" """
Creates some entries for testing purposes and entries for Creates some entries for testing purposes and entries for
cython.array() and for cython.view.*. cython.array() and for cython.view.*.
""" """
if self._cythonscope_initialized:
return
self._cythonscope_initialized = True
cython_testscope_utility_code.declare_in_scope( cython_testscope_utility_code.declare_in_scope(
self, cython_scope=self) self, cython_scope=self)
cython_test_extclass_utility_code.declare_in_scope( cython_test_extclass_utility_code.declare_in_scope(
...@@ -100,16 +118,11 @@ class CythonScope(ModuleScope): ...@@ -100,16 +118,11 @@ class CythonScope(ModuleScope):
# MemoryView.memview_fromslice_utility_code.declare_in_scope(viewscope) # MemoryView.memview_fromslice_utility_code.declare_in_scope(viewscope)
def create_cython_scope(context, create_testscope): def create_cython_scope(context):
# One could in fact probably make it a singleton, # One could in fact probably make it a singleton,
# but not sure yet whether any code mutates it (which would kill reusing # but not sure yet whether any code mutates it (which would kill reusing
# it across different contexts) # it across different contexts)
scope = CythonScope(context) return CythonScope(context)
if create_testscope:
scope.test_cythonscope()
return scope
# Load test utilities for the cython scope # Load test utilities for the cython scope
...@@ -137,4 +150,4 @@ cython_test_extclass_utility_code = \ ...@@ -137,4 +150,4 @@ cython_test_extclass_utility_code = \
requires=[undecorated_methods_protos, requires=[undecorated_methods_protos,
test_cython_utility_dep]) test_cython_utility_dep])
cythonview_testscope_utility_code = load_testscope_utility("View.TestScope") cythonview_testscope_utility_code = load_testscope_utility("View.TestScope")
\ No newline at end of file
...@@ -65,9 +65,7 @@ class Context(object): ...@@ -65,9 +65,7 @@ class Context(object):
import Builtin, CythonScope import Builtin, CythonScope
self.modules = {"__builtin__" : Builtin.builtin_scope} self.modules = {"__builtin__" : Builtin.builtin_scope}
if self.cython_scope is None: self.cython_scope = CythonScope.create_cython_scope(self)
Context.cython_scope = CythonScope.create_cython_scope(
self, create_testscope=create_testscope)
self.modules["cython"] = self.cython_scope self.modules["cython"] = self.cython_scope
self.include_directories = include_directories self.include_directories = include_directories
self.future_directives = set() self.future_directives = set()
......
...@@ -686,6 +686,7 @@ def get_axes_specs(env, axes): ...@@ -686,6 +686,7 @@ def get_axes_specs(env, axes):
''' '''
cythonscope = env.global_scope().context.cython_scope cythonscope = env.global_scope().context.cython_scope
cythonscope.load_cythonscope()
viewscope = cythonscope.viewscope viewscope = cythonscope.viewscope
access_specs = tuple([viewscope.lookup(name) access_specs = tuple([viewscope.lookup(name)
......
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