tags parsing
authorRobert Bradshaw <robertwb@math.washington.edu>
Sat, 2 Apr 2011 08:55:44 +0000 (01:55 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sat, 2 Apr 2011 08:55:44 +0000 (01:55 -0700)
runtests.py

index 1a26a0c167ba1755a7f8c649bb505a277ff1882d..6f79231673dca41145360f6d3b1af790e47892c8 100644 (file)
@@ -27,6 +27,22 @@ try:
 except ImportError: # No threads, no problems
     threading = None
 
+try:
+    from collections import defaultdict
+except ImportError:
+    class defaultdict(object):
+        def __init__(self, default_factory=lambda : None):
+            self._dict = {}
+            self.default_factory = default_factory
+        def __getitem__(self, key):
+            if key not in self._dict:
+                self._dict[key] = self.default_factory()
+            return self._dict[key]
+        def __setitem__(self, key, value):
+            self._dict[key] = value
+        def __repr__(self):
+            return repr(self._dict)
+
 WITH_CYTHON = True
 CY3_DIR = None
 
@@ -103,6 +119,21 @@ COMPILER = None
 INCLUDE_DIRS = [ d for d in os.getenv('INCLUDE', '').split(os.pathsep) if d ]
 CFLAGS = os.getenv('CFLAGS', '').split()
 
+def parse_tags(filepath):
+    tags = defaultdict(list)
+    for line in open(filepath):
+        line = line.strip()
+        if not line:
+            continue
+        if line[0] != '#':
+            break
+        ix = line.find(':')
+        if ix != -1:
+            tag = line[1:ix].strip()
+            values = line[ix+1:].split(',')
+            tags[tag].extend([value.strip() for value in values])
+    return tags
+
 class build_ext(_build_ext):
     def build_extension(self, ext):
         if ext.language == 'c++':