diff --git a/DataProcessingTools/objects.py b/DataProcessingTools/objects.py index 04a3526..028389f 100644 --- a/DataProcessingTools/objects.py +++ b/DataProcessingTools/objects.py @@ -49,6 +49,17 @@ class DPObject(): def __init__(self, *args, **kwargs): fname = kwargs.get("loadFrom", None) + if isinstance(fname, list): + # go through the list of filenames and check if one matches for this object + bn, ext = os.path.splitext(self.filename) + found = False + for fn in fname: + if fn.find(bn) > -1: + fname = fn + found = True + break + if not found: + fname = None _dirs = kwargs.get("dirs") if fname is not None: self.load(fname=fname) diff --git a/setup.py b/setup.py index 3c4c90c..3a1a625 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from distutils.core import setup setup(name="DataProcessingTools", - version="0.20.0", + version="0.21.0", description="""Tools for processing data with hierarchical organization""", url="https://github.com/grero/DataProcessingTools.git", author="Roger Herikstad", diff --git a/tests/test_objects.py b/tests/test_objects.py index da632ea..e4ba4c3 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -68,6 +68,10 @@ def test_append(): obj1 = MyObj([0.1, 0.2, 0.3]) h = obj1.hash() assert h == "c872" + # test that we can ignore files + obj2 = MyObj([0.1, 0.2, 0.3], loadFrom=["fake_file.hkl"]) + h2 = obj2.hash() + assert h2 == h for d in dirs[1:]: with DPT.misc.CWD(d): @@ -122,6 +126,11 @@ def test_append(): assert obj7.args["bins"] == obj.args["bins"] assert obj7.dirs == obj.dirs + obj8 = MyObj(loadFrom=["myobj_c872.hkl", + "something_else.hkl"]) + + assert obj8.dirs == obj.dirs + os.remove(obj.get_filename()) def test_object():