Commit 901903e8 authored by Robert Bradshaw's avatar Robert Bradshaw

Fix decorators for 2.3.

parent 92bdeb20
...@@ -5,7 +5,7 @@ from distutils.extension import Extension ...@@ -5,7 +5,7 @@ from distutils.extension import Extension
from Cython import Utils from Cython import Utils
# Unfortunately, Python 2.3 doesn't support decorators.
def cached_method(f): def cached_method(f):
cache_name = '__%s_cache' % f.__name__ cache_name = '__%s_cache' % f.__name__
def wrapper(self, *args): def wrapper(self, *args):
...@@ -199,11 +199,12 @@ class DependencyTree(object): ...@@ -199,11 +199,12 @@ class DependencyTree(object):
self.context = context self.context = context
self._transitive_cache = {} self._transitive_cache = {}
@cached_method #@cached_method
def parse_dependencies(self, source_filename): def parse_dependencies(self, source_filename):
return parse_dependencies(source_filename) return parse_dependencies(source_filename)
parse_dependencies = cached_method(parse_dependencies)
@cached_method #@cached_method
def cimports_and_externs(self, filename): def cimports_and_externs(self, filename):
cimports, includes, externs = self.parse_dependencies(filename)[:3] cimports, includes, externs = self.parse_dependencies(filename)[:3]
cimports = set(cimports) cimports = set(cimports)
...@@ -213,22 +214,25 @@ class DependencyTree(object): ...@@ -213,22 +214,25 @@ class DependencyTree(object):
cimports.update(a) cimports.update(a)
externs.update(b) externs.update(b)
return tuple(cimports), tuple(externs) return tuple(cimports), tuple(externs)
cimports_and_externs = cached_method(cimports_and_externs)
def cimports(self, filename): def cimports(self, filename):
return self.cimports_and_externs(filename)[0] return self.cimports_and_externs(filename)[0]
@cached_method #@cached_method
def package(self, filename): def package(self, filename):
dir = os.path.dirname(filename) dir = os.path.dirname(filename)
if os.path.exists(os.path.join(dir, '__init__.py')): if os.path.exists(os.path.join(dir, '__init__.py')):
return self.package(dir) + (os.path.basename(dir),) return self.package(dir) + (os.path.basename(dir),)
else: else:
return () return ()
package = cached_method(package)
@cached_method #@cached_method
def fully_qualifeid_name(self, filename): def fully_qualifeid_name(self, filename):
module = os.path.splitext(os.path.basename(filename))[0] module = os.path.splitext(os.path.basename(filename))[0]
return '.'.join(self.package(filename) + (module,)) return '.'.join(self.package(filename) + (module,))
fully_qualifeid_name = cached_method(fully_qualifeid_name)
def find_pxd(self, module, filename=None): def find_pxd(self, module, filename=None):
if module[0] == '.': if module[0] == '.':
...@@ -240,7 +244,7 @@ class DependencyTree(object): ...@@ -240,7 +244,7 @@ class DependencyTree(object):
return pxd return pxd
return self.context.find_pxd_file(module, None) return self.context.find_pxd_file(module, None)
@cached_method #@cached_method
def cimported_files(self, filename): def cimported_files(self, filename):
if filename[-4:] == '.pyx' and os.path.exists(filename[:-4] + '.pxd'): if filename[-4:] == '.pyx' and os.path.exists(filename[:-4] + '.pxd'):
self_pxd = [filename[:-4] + '.pxd'] self_pxd = [filename[:-4] + '.pxd']
...@@ -253,6 +257,7 @@ class DependencyTree(object): ...@@ -253,6 +257,7 @@ class DependencyTree(object):
print ("\n\t".join(a)) print ("\n\t".join(a))
print ("\n\t".join(b)) print ("\n\t".join(b))
return tuple(self_pxd + filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)])) return tuple(self_pxd + filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)]))
cimported_files = cached_method(cimported_files)
def immediate_dependencies(self, filename): def immediate_dependencies(self, filename):
all = list(self.cimported_files(filename)) all = list(self.cimported_files(filename))
...@@ -260,9 +265,10 @@ class DependencyTree(object): ...@@ -260,9 +265,10 @@ class DependencyTree(object):
all.append(os.path.normpath(os.path.join(os.path.dirname(filename), extern))) all.append(os.path.normpath(os.path.join(os.path.dirname(filename), extern)))
return tuple(all) return tuple(all)
@cached_method #@cached_method
def timestamp(self, filename): def timestamp(self, filename):
return os.path.getmtime(filename) return os.path.getmtime(filename)
timestamp = cached_method(timestamp)
def extract_timestamp(self, filename): def extract_timestamp(self, filename):
# TODO: .h files from extern blocks # TODO: .h files from extern blocks
......
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