diff options
author | David Cournapeau <cournape@gmail.com> | 2009-07-26 11:09:08 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-07-26 11:09:08 +0000 |
commit | d0aa15161d4feba785c82535f8d8fceffc8763da (patch) | |
tree | 3f431cf718622c8317f2fabd4e37b038bce53a1e /numpy/distutils/npy_pkg_config.py | |
parent | 88bbeee64f541b2da242a835acbba09079e5c89c (diff) | |
download | numpy-d0aa15161d4feba785c82535f8d8fceffc8763da.tar.gz |
Implement a trivial cache mechanism for LibraryInfo instances creation.
Diffstat (limited to 'numpy/distutils/npy_pkg_config.py')
-rw-r--r-- | numpy/distutils/npy_pkg_config.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/numpy/distutils/npy_pkg_config.py b/numpy/distutils/npy_pkg_config.py index 5f1159d91..937f8c5bd 100644 --- a/numpy/distutils/npy_pkg_config.py +++ b/numpy/distutils/npy_pkg_config.py @@ -1,7 +1,7 @@ from ConfigParser import SafeConfigParser, NoOptionError import re -VAR = re.compile('\$\{([a-zA-Z0-9_-]+)\}') +_VAR = re.compile('\$\{([a-zA-Z0-9_-]+)\}') class FormatError(IOError): def __init__(self, msg): @@ -66,7 +66,7 @@ class VariableSet(object): for k in self._re.keys(): value = self._re[k].sub(self._re_sub[k], value) return value - while VAR.search(value): + while _VAR.search(value): nvalue = _interpolate(value) if nvalue == value: break @@ -174,9 +174,21 @@ def read_config(filename): version=meta["version"], sections=sections, vars=VariableSet(vars)) # TODO: -# - Caching mechanism for LibraryInfo instances # - implements version comparison (modversion + atleast) +# Trivial cache to cache LibraryInfo instances creation. To be really +# efficient, the cache should be handled in read_config, since a same file can +# be parsed many time outside LibraryInfo creation, but I doubt this will be a +# problem in practice +_CACHE = {} +def get_info(pkgname): + try: + return _CACHE[pkgname] + except KeyError: + v = read_config(pkg_to_filename(pkgname)) + _CACHE[pkgname] = v + return v + if __name__ == '__main__': import sys from optparse import OptionParser @@ -208,8 +220,7 @@ if __name__ == '__main__': print "%s\t%s - %s" % (info.name, info.name, info.description) pkg_name = args[1] - fname = pkg_to_filename(pkg_name) - info = read_config(fname) + info = get_info(pkg_name) if options.section: section = options.section |