[Reproducible-commits] [diffoscope] 03/04: Use an iterator in Container.compare

Jérémy Bobbio lunar at moszumanska.debian.org
Thu Sep 17 11:25:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to annotated tag 34
in repository diffoscope.

commit 690933ecb27ac7bd90004ed0b73242183969b594
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sat Sep 5 14:21:05 2015 +0000

    Use an iterator in Container.compare
    
    Now that we produce the list of comparisons using an iterator, it feels
    pretty logic to implement Container.compare as a transformation over
    the value. itertools.starmap() to the rescue!
    
    We still need to evaluate the iterator right away (using list) because
    container code currently assumes that the content of the underlying
    source is available. This could probably be avoided using proper
    refactoring but that will be for later.
    
    In any cases this change should make implementation of parallel processing
    pretty straightforward.
---
 diffoscope/comparators/__init__.py |  8 ++++++++
 diffoscope/comparators/utils.py    | 11 ++---------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 118ad3e..8fe3da5 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -95,6 +95,14 @@ def compare_files(file1, file2, source=None):
             return file1.compare_bytes(file2, source)
         return file1.compare(file2, source)
 
+def compare_commented_files(file1, file2, comment=None, source=None):
+    difference = compare_files(file1, file2, source=source)
+    if comment:
+        if difference is None:
+            difference = Difference(None, my_file.name, other_file.name)
+        difference.add_comment(comment)
+    return difference
+
 
 # The order matters! They will be tried in turns.
 FILE_CLASSES = (
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 6ff1162..3b912cd 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -19,6 +19,7 @@
 
 from abc import ABCMeta, abstractmethod
 from contextlib import contextmanager
+from itertools import starmap
 # The following would be shutil.which in Python 3.3
 import os
 import shutil
@@ -192,15 +193,7 @@ class Container(object):
                 yield NonExistingFile('/dev/null', other_file), other_file, NO_COMMENT
 
     def compare(self, other, source=None):
-        differences = []
-        for my_file, other_file, comment in self.comparisons(other):
-            difference = diffoscope.comparators.compare_files(my_file, other_file)
-            if comment:
-                if difference is None:
-                    difference = Difference(None, my_file.name, other_file.name)
-                difference.add_comment(comment)
-            differences.append(difference)
-        return differences
+        return list(starmap(diffoscope.comparators.compare_commented_files, self.comparisons(other)))
 
 
 class ArchiveMember(File):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git



More information about the Reproducible-commits mailing list