Add a cheap OrderedSet implementation
This just makes an OrderedDict look more like a set class. This results
in neater code than if we use OrderedDict to hold sets directly.
There is a "real" OrderedSet implementation available here, but it lacks
a clear license:
import stat
import platform, subprocess, operator, os, shutil, re
+import collections
from glob import glob
@@ -672,3 +673,18 @@ def get_filenames_templates_dict(inputs, outputs):
if values['@OUTDIR@'] == '':
values['@OUTDIR@'] = '.'
return values
+
+class OrderedSet(collections.OrderedDict):
+ '''
+ A 'set' equivalent that preserves the order in which items are added.
+
+ This is a hack implementation that wraps OrderedDict. It may not be the
+ most efficient solution and might need fixing to override more methods.
+ '''
+ def __init__(self, iterable=None):
+ if iterable:
+ self.update(iterable)
+
+ def update(self, iterable):
+ for item in iterable:
+ self[item] = True
