[Git][reproducible-builds/diffoscope][master] 2 commits: Tidy some control flow.

Chris Lamb (@lamby) gitlab at salsa.debian.org
Tue Jan 25 18:54:22 UTC 2022



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
7b86483c by Chris Lamb at 2022-01-25T10:47:30-08:00
Tidy some control flow.

- - - - -
e99851bf by Chris Lamb at 2022-01-25T10:51:20-08:00
First attempt at incremental output support with a timeout. Passing, for example, --timeout=60 will mean that diffoscope will not recurse into any sub-archives after 60 seconds total execution time has elapsed. (It is not a fixed/strict timeout due to implementation issues.) (Closes: reproducible-builds/diffoscope#301)

- - - - -


3 changed files:

- diffoscope/comparators/utils/file.py
- diffoscope/config.py
- diffoscope/main.py


Changes:

=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -1,7 +1,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2016-2021 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2022 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -434,6 +434,12 @@ class File(metaclass=abc.ABCMeta):
                 msg = "Reached max container depth ({})".format(depth)
                 logger.debug(msg)
                 difference.add_comment(msg)
+            elif Config().timeout_exceeded():
+                msg = "Timeout exceeded; details may be incomplete."
+                logger.debug(msg)
+                difference.add_comment(msg)
+                no_recurse = True
+
             details.extend(
                 self.as_container.compare(
                     other.as_container, no_recurse=no_recurse


=====================================
diffoscope/config.py
=====================================
@@ -2,7 +2,7 @@
 # diffoscope: in-depth comparison of files, archives, and directories
 #
 # Copyright © 2015 Reiner Herrmann <reiner at reiner-h.de>
-# Copyright © 2016-2017, 2019-2021 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2017, 2019-2022 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 
 
 import logging
+import time
 
 
 logger = logging.getLogger(__name__)
@@ -69,6 +70,9 @@ class Config:
         self.use_dbgsym = "auto"
         self.force_details = False
 
+        self.started = time.time()
+        self.timeout = float("inf")
+
     def __setattr__(self, k, v):
         super(Config, self).__setattr__(k, v)
 
@@ -76,23 +80,26 @@ class Config:
         va = getattr(self, a)
         vb = getattr(self, b)
         if va < vb:
-            if isinstance(vb, defaultint):
-                logger.warning(
-                    "%s (%s) < default value of %s (%s), setting latter to %s",
-                    a,
-                    va,
-                    b,
-                    vb,
-                    va,
-                )
-                setattr(self, b, va)
-            else:
+            if not isinstance(vb, defaultint):
                 raise ValueError(
                     "{0} ({1}) cannot be smaller than {2} ({3})".format(
                         a, va, b, vb
                     )
                 )
 
+            logger.warning(
+                "%s (%s) < default value of %s (%s), setting latter to %s",
+                a,
+                va,
+                b,
+                vb,
+                va,
+            )
+            setattr(self, b, va)
+
     def check_constraints(self):
         self.check_ge("max_diff_block_lines", "max_page_diff_block_lines")
         self.check_ge("max_report_size", "max_page_size")
+
+    def timeout_exceeded(self):
+        return (self.started + self.timeout) < time.time()


=====================================
diffoscope/main.py
=====================================
@@ -4,7 +4,7 @@
 # diffoscope: in-depth comparison of files, archives, and directories
 #
 # Copyright © 2014-2015 Jérémy Bobbio <lunar at debian.org>
-# Copyright © 2016-2021 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2022 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -366,6 +366,13 @@ def create_parser():
         "%(default)s)",
         default=Config().max_container_depth,
     )
+    group3.add_argument(
+        "--timeout",
+        metavar="SECONDS",
+        type=int,
+        help="Best-effort attempt at a timeout in seconds. (default: no timeout) [experimental]",
+        default=float("inf"),
+    )
     group3.add_argument(
         "--max-diff-block-lines-saved",
         metavar="LINES",
@@ -628,6 +635,7 @@ def configure(parsed_args):
     Config().use_dbgsym = parsed_args.use_dbgsym
     Config().force_details = parsed_args.force_details
     Config().fuzzy_threshold = parsed_args.fuzzy_threshold
+    Config().timeout = parsed_args.timeout
     Config().max_container_depth = parsed_args.max_container_depth
 
     Config().excludes = parsed_args.excludes



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/ec223f64a745c85ba361a412ec2e402833981f5b...e99851bfd2b4966ccf860d7ea6660a905162034c

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/ec223f64a745c85ba361a412ec2e402833981f5b...e99851bfd2b4966ccf860d7ea6660a905162034c
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20220125/5db56a4f/attachment.htm>


More information about the rb-commits mailing list