@@ -259,6 +259,7 @@ def compare_trees(
259259 specific_args = None ,
260260 return_raw_diffs = False ,
261261 export_formatted_files = False ,
262+ ignore_patterns = None ,
262263):
263264 """Compare all files from 2 different directory trees and return the differences.
264265
@@ -306,6 +307,9 @@ def compare_trees(
306307 new directory with formatted compared data files. If a string is passed, this string is
307308 used as suffix for the new directory. If `True` is passed, the suffix is
308309 ``_FORMATTED``.
310+ ignore_patterns (list): A list of regular expression patterns. If the relative path of a
311+ file matches one of these patterns, it is ignored during the comparison. Note that
312+ this means that any specific arguments for that file will also be ignored.
309313
310314 Returns:
311315 dict: A ``dict`` in which the keys are the relative file paths and the values are the
@@ -333,6 +337,11 @@ def compare_trees(
333337 for pattern in v .pop ("patterns" , []):
334338 pattern_specific_args [re .compile (pattern )] = v
335339
340+ if ignore_patterns is None :
341+ ignore_patterns = []
342+ else :
343+ ignore_patterns = [re .compile (i ) for i in ignore_patterns ]
344+
336345 # Loop over all files and call the correct comparator
337346 different_files = {}
338347 for ref_file in ref_path .glob ("**/*" ):
@@ -342,6 +351,14 @@ def compare_trees(
342351 relative_path = ref_file .relative_to (ref_path ).as_posix ()
343352 comp_file = comp_path / relative_path
344353
354+ ignored = False
355+ for pattern in ignore_patterns :
356+ if pattern .match (relative_path ):
357+ ignored = True
358+ break
359+ if ignored :
360+ continue
361+
345362 if comp_file .exists ():
346363 specific_file_args = specific_args .get (relative_path , None )
347364 if specific_file_args is None :
0 commit comments