From 5fe0df9857993ca7f0fd011fa1fe935039a2f881 Mon Sep 17 00:00:00 2001 From: roger Date: Mon, 5 Oct 2020 12:01:06 +0800 Subject: [PATCH 1/5] Adds support for supplying a list of filenames to load from --- DataProcessingTools/objects.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/DataProcessingTools/objects.py b/DataProcessingTools/objects.py index 04a3526..cd9d32c 100644 --- a/DataProcessingTools/objects.py +++ b/DataProcessingTools/objects.py @@ -49,6 +49,13 @@ 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) + for fn in fname: + if fn.find(bn) > -1: + fname = fn + break _dirs = kwargs.get("dirs") if fname is not None: self.load(fname=fname) From 50aa945ec1939cbd8ef11e2a6168536b6951a837 Mon Sep 17 00:00:00 2001 From: roger Date: Mon, 5 Oct 2020 12:01:19 +0800 Subject: [PATCH 2/5] Adds test for list of filenames --- tests/test_objects.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_objects.py b/tests/test_objects.py index da632ea..f628364 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -122,6 +122,9 @@ 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(): From 72dc1f46010799978450b57afff44d6e426e221e Mon Sep 17 00:00:00 2001 From: roger Date: Mon, 5 Oct 2020 12:28:15 +0800 Subject: [PATCH 3/5] Adds code to set fname to None if not foudn in loadFrom --- DataProcessingTools/objects.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DataProcessingTools/objects.py b/DataProcessingTools/objects.py index cd9d32c..028389f 100644 --- a/DataProcessingTools/objects.py +++ b/DataProcessingTools/objects.py @@ -51,11 +51,15 @@ 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) + 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) From 1e9b82fdeaf18fefc0fd7f4351f7e6b2b69abccd Mon Sep 17 00:00:00 2001 From: roger Date: Mon, 5 Oct 2020 12:36:29 +0800 Subject: [PATCH 4/5] Adds more test for loadFrom --- tests/test_objects.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_objects.py b/tests/test_objects.py index f628364..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,7 +126,9 @@ def test_append(): assert obj7.args["bins"] == obj.args["bins"] assert obj7.dirs == obj.dirs - obj8 = MyObj(loadFrom=["myobj_c872.hkl","something_else.hkl"]) + obj8 = MyObj(loadFrom=["myobj_c872.hkl", + "something_else.hkl"]) + assert obj8.dirs == obj.dirs os.remove(obj.get_filename()) From 996b7a81b6837cf256e6e21c3b4c1d8033f3febb Mon Sep 17 00:00:00 2001 From: roger Date: Mon, 5 Oct 2020 12:36:46 +0800 Subject: [PATCH 5/5] Bumps version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",