@@ -62,7 +62,10 @@ def register_comparator(ext, comparator, force=False):
6262 registered and the comparator is replaced.
6363
6464 .. note::
65- The given comparator should have the following signature:
65+ It is possible to create and register custom comparators. The easiest way to do it is to
66+ derive a class from :class:`dir_content_diff.BaseComparator`.
67+
68+ Otherwise, the given comparator should be a callable with the following signature:
6669
6770 .. code-block:: python
6871
@@ -74,7 +77,8 @@ def register_comparator(ext, comparator, force=False):
7477 **diff_kwargs: Mapping[str, Any],
7578 ) -> Union[False, str]
7679
77- The return type can be Any when used with `return_raw_diffs == True`.
80+ The return type can be Any when used with `return_raw_diffs == True`, else it should be a
81+ string object.
7882 """
7983 ext = format_ext (ext )
8084 if not force and ext in _COMPARATORS :
@@ -229,6 +233,7 @@ def compare_trees(
229233
230234 {
231235 <relative_file_path>: {
236+ comparator: ComparatorInstance,
232237 args: [arg1, arg2, ...],
233238 kwargs: {
234239 kwarg_name_1: kwarg_value_1,
@@ -237,6 +242,8 @@ def compare_trees(
237242 },
238243 <another_file_path>: {...}
239244 }
245+
246+ Note that all entries in this ``dict`` are optional.
240247 return_raw_diffs (bool): If set to ``True``, only the raw differences are returned instead
241248 of a formatted report.
242249 export_formatted_files (bool or str): If set to ``True`` or a not empty string, create a
@@ -265,6 +272,8 @@ def compare_trees(
265272
266273 if specific_args is None :
267274 specific_args = {}
275+ else :
276+ specific_args = copy .deepcopy (specific_args )
268277
269278 # Loop over all files and call the correct comparator
270279 different_files = {}
@@ -277,15 +286,21 @@ def compare_trees(
277286
278287 if comp_file .exists ():
279288 specific_file_args = specific_args .get (relative_path , {})
280- comparator = comparators .get (ref_file .suffix , _COMPARATORS .get (None ))
281- comparator_kwargs = {k : v for k , v in specific_file_args .items () if k != "args" }
289+ comparator = specific_file_args .pop (
290+ "comparator" ,
291+ comparators .get (
292+ ref_file .suffix ,
293+ _COMPARATORS .get (None ),
294+ ),
295+ )
296+ comparator_args = specific_file_args .pop ("args" , [])
282297 res = compare_files (
283298 ref_file ,
284299 comp_file ,
285300 comparator ,
286- * specific_file_args . get ( "args" , []) ,
301+ * comparator_args ,
287302 return_raw_diffs = return_raw_diffs ,
288- ** comparator_kwargs ,
303+ ** specific_file_args ,
289304 )
290305 if res is not False :
291306 different_files [relative_path ] = res
@@ -294,7 +309,7 @@ def compare_trees(
294309 comp_file ,
295310 formatted_data_path / relative_path ,
296311 comparator ,
297- ** comparator_kwargs ,
312+ ** specific_file_args ,
298313 )
299314 else :
300315 msg = f"The file '{ relative_path } ' does not exist in '{ comp_path } '."
0 commit comments