[Git][reproducible-builds/diffoscope][master] 4 commits: Update to progressbar >= 3.0

Chris Lamb (@lamby) gitlab at salsa.debian.org
Fri Jan 19 22:16:37 UTC 2024



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
61394cc4 by Vekhir at 2024-01-19T22:04:52+00:00
Update to progressbar >= 3.0

When `progressbar` was forked and rewritten, several API changes were made. Those were only partially adapted here in diffoscope - due to lack of sufficient tooling to detect those differences at the time, as known compile errors were fixed.
Hence, this part of the code base didn't work for over 6 years - the updates introduced here are still compatible with the release of the rewrite as v3.0. Going further back likely isn't a concern anymore.
The two relevant commits in progressbar are https://github.com/wolph/python-progressbar/commit/12df6aec2b87f409bbe4dc1b09e82b048e3ff10d and https://github.com/wolph/python-progressbar/commit/a1fc83090e870d4136f93654cf54b581f0e0b882, which are included in 3.0.
One notable change is the removal of `self.bar.start()` in the setup. The change works, as the progressbar calls `start` automatically if there hasn't been one defined. Starting the progressbar within the setup, however, is problematic because the starting time is set there. At setup time, this time is in localtime - only later is it set to UTC yielding wrong time differences which can even be negative. Letting progressbar start the timer is therefore both more convenient and correct.
- - - - -
1fae3be4 by Vekhir at 2024-01-19T22:04:52+00:00
Add compatibility for progressbar 2.5 as available on Debian
- - - - -
da06c60c by Vekhir at 2024-01-19T22:04:52+00:00
Update file progress.py
- - - - -
9413d72d by Vekhir at 2024-01-19T22:04:52+00:00
fix: Make black happy
- - - - -


1 changed file:

- diffoscope/progress.py


Changes:

=====================================
diffoscope/progress.py
=====================================
@@ -207,14 +207,19 @@ class ProgressBar:
     def __init__(self):
         try:
             from progressbar.widgets import WidgetBase
+
+            compatibility_mode = False
         except ImportError:
             # Fallback to the older Debian version
             from progressbar import Widget as WidgetBase
 
+            compatibility_mode = True
+        self.compatibility_mode = compatibility_mode
+
         self.msg = ""
 
         class Message(WidgetBase):
-            def update(self, pbar, _observer=self):
+            def __call__(self, progress, data, _observer=self):
                 msg = _observer.msg
                 width = 25
 
@@ -224,6 +229,10 @@ class ProgressBar:
                 # Print the last `width` characters with an ellipsis.
                 return "…{}".format(msg[-width + 1 :])
 
+            def update(self, pbar, _observer=self):
+                """Compatibility method for progressbar 2.5"""
+                return self(pbar, None, _observer)
+
         class OurProgressBar(progressbar.ProgressBar):
             def __init__(self, *args, **kwargs):
                 # Remove after https://github.com/niltonvolpato/python-progressbar/pull/57 is fixed.
@@ -232,17 +241,24 @@ class ProgressBar:
                 # Terminal handling after parent init since that sets self.fd
                 self.erase_to_eol = line_eraser(self.fd)
 
-            def _need_update(self):
+            def _needs_update(self):
                 return True
 
+            def _need_update(self):
+                """Compatibility method for progressbar 2.5"""
+                return self._needs_update()
+
             def erase_line(self):
                 if self.erase_to_eol:
                     self.fd.buffer.write(self.erase_to_eol)
                     self.fd.flush()
 
             def finish(self):
-                self.finished = True
-                self.update(self.maxval)
+                if compatibility_mode:
+                    # setting self.finished = True makes super().finish() a noop
+                    self.finished = True
+                    self.update(self.maxval)
+                super().finish()
                 # Clear the progress bar after completion
                 self.erase_line()
                 if self.signal_set:
@@ -261,14 +277,20 @@ class ProgressBar:
                 " ",
             )
         )
-        self.bar.start()
+        if compatibility_mode:
+            self.bar.start()
 
     def notify(self, current, total, msg):
         self.msg = msg
 
-        self.bar.maxval = total
-        self.bar.value = current
-        self.bar.update()
+        if self.compatibility_mode:
+            self.bar.maxval = total
+            self.bar.value = current
+            self.bar.update()
+            return
+
+        self.bar.max_value = total
+        self.bar.update(current)
 
     def finish(self):
         self.bar.finish()



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/70d940a2101c63b275e1d910dc663ce0d2574142...9413d72de929623497f1cf2844aca385f54f67b1

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/70d940a2101c63b275e1d910dc663ce0d2574142...9413d72de929623497f1cf2844aca385f54f67b1
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/20240119/1b889e24/attachment.htm>


More information about the rb-commits mailing list