diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2017-04-03 15:57:27 +0100 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2017-04-03 17:02:43 +0100 |
commit | e0c5e4082689e6e49d80c574f35b9e401b7fc83a (patch) | |
tree | 3bc11ebe179ed98886cdb8020955394f521fd014 | |
parent | f5b7cfdbf0888fb99956cf2dc661c519aa08a9a4 (diff) | |
download | meson-e0c5e4082689e6e49d80c574f35b9e401b7fc83a.zip meson-e0c5e4082689e6e49d80c574f35b9e401b7fc83a.tar.gz meson-e0c5e4082689e6e49d80c574f35b9e401b7fc83a.tar.bz2 |
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: https://code.activestate.com/recipes/576694/
-rw-r--r-- | mesonbuild/mesonlib.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index c7368d5..f0bf9ee 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -16,6 +16,7 @@ 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 |