From 87844728ec3e65dbdbdcc659044f102e348700ac Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Wed, 18 Mar 2020 15:23:45 +0000
Subject: [PATCH] ENH: BIDSFile.match option to disable suffix match

---
 fsl/utils/bids.py | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/fsl/utils/bids.py b/fsl/utils/bids.py
index 54c22bce0..cae75cb4f 100644
--- a/fsl/utils/bids.py
+++ b/fsl/utils/bids.py
@@ -9,6 +9,7 @@
 .. autosummary::
    :nosignatures:
 
+   BIDSFile
    isBIDSDir
    inBIDSDir
    isBIDSFile
@@ -57,20 +58,34 @@ class BIDSFile(object):
         self.suffix      = suffix
 
 
-    def match(self, other):
+    def __str__(self):
+        """Return a strimg representation of this ``BIDSFile``. """
+        return 'BIDSFile({})'.format(self.filename)
+
+
+    def __repr__(self):
+        """Return a strimg representation of this ``BIDSFile``. """
+        return str(self)
+
+
+    def match(self, other, suffix=True):
         """Compare this ``BIDSFile`` to ``other``.
 
-        :arg other: ``BIDSFile`` to compare
-        :returns:   ``True`` if ``self.suffix == other.suffix`` and if
-                    all of the entities in ``other`` are present in ``self``,
-                    ``False`` otherwise.
+        :arg other:  ``BIDSFile`` to compare
+
+        :arg suffix: Defaults to ``True``. If ``False``, the comparison
+                     is made solely on the entity values.
+
+        :returns:    ``True`` if ``self.suffix == other.suffix`` (unless
+                     ``suffix`` is ``False``) and if all of the entities in
+                     ``other`` are present in ``self``, ``False`` otherwise.
         """
 
-        suffix   = self.suffix == other.suffix
+        suffix   = (not suffix) or (self.suffix == other.suffix)
         entities = True
 
         for key, value in other.entities.items():
-            entities = entities and self.entities.get(key, None) == value
+            entities = entities and (self.entities.get(key, None) == value)
 
         return suffix and entities
 
-- 
GitLab