From: Robert Bradshaw Date: Sun, 12 Sep 2010 09:11:33 +0000 (-0700) Subject: Fix decorators for 2.3. X-Git-Tag: 0.14.alpha0~316 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=901903e8535f18e8e654aff626c0c2d76721e6fe;p=cython.git Fix decorators for 2.3. --- diff --git a/Cython/Compiler/Dependencies.py b/Cython/Compiler/Dependencies.py index 086dbdc4..979ef210 100644 --- a/Cython/Compiler/Dependencies.py +++ b/Cython/Compiler/Dependencies.py @@ -5,7 +5,7 @@ from distutils.extension import Extension from Cython import Utils - +# Unfortunately, Python 2.3 doesn't support decorators. def cached_method(f): cache_name = '__%s_cache' % f.__name__ def wrapper(self, *args): @@ -199,11 +199,12 @@ class DependencyTree(object): self.context = context self._transitive_cache = {} - @cached_method + #@cached_method def parse_dependencies(self, source_filename): return parse_dependencies(source_filename) + parse_dependencies = cached_method(parse_dependencies) - @cached_method + #@cached_method def cimports_and_externs(self, filename): cimports, includes, externs = self.parse_dependencies(filename)[:3] cimports = set(cimports) @@ -213,22 +214,25 @@ class DependencyTree(object): cimports.update(a) externs.update(b) return tuple(cimports), tuple(externs) + cimports_and_externs = cached_method(cimports_and_externs) def cimports(self, filename): return self.cimports_and_externs(filename)[0] - @cached_method + #@cached_method def package(self, filename): dir = os.path.dirname(filename) if os.path.exists(os.path.join(dir, '__init__.py')): return self.package(dir) + (os.path.basename(dir),) else: return () + package = cached_method(package) - @cached_method + #@cached_method def fully_qualifeid_name(self, filename): module = os.path.splitext(os.path.basename(filename))[0] return '.'.join(self.package(filename) + (module,)) + fully_qualifeid_name = cached_method(fully_qualifeid_name) def find_pxd(self, module, filename=None): if module[0] == '.': @@ -240,7 +244,7 @@ class DependencyTree(object): return pxd return self.context.find_pxd_file(module, None) - @cached_method + #@cached_method def cimported_files(self, filename): if filename[-4:] == '.pyx' and os.path.exists(filename[:-4] + '.pxd'): self_pxd = [filename[:-4] + '.pxd'] @@ -253,6 +257,7 @@ class DependencyTree(object): 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)])) + cimported_files = cached_method(cimported_files) def immediate_dependencies(self, filename): all = list(self.cimported_files(filename)) @@ -260,9 +265,10 @@ class DependencyTree(object): all.append(os.path.normpath(os.path.join(os.path.dirname(filename), extern))) return tuple(all) - @cached_method + #@cached_method def timestamp(self, filename): return os.path.getmtime(filename) + timestamp = cached_method(timestamp) def extract_timestamp(self, filename): # TODO: .h files from extern blocks