prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  widget.CheckUpdates not hidden when no updates are available
  <!--
  Please do not ask general questions here! There are [community
  contact](https://github.com/qtile/qtile#community) options for that.
  -->
  
  # Issue description
  
  <!--
  A brief discussion of what failed and how it failed. A description of
  what you tried is helpful, i.e. "When I use lazy.kill() on a window I get
  the following stack trace" instead of "Closing windows doesn't work".
  -->
  
  The documentation for [`CheckUpdates`](http://docs.qtile.org/en/latest/manual/ref/widgets.html#checkupdates) `display_format` mentions that the given format-specifier will only be used when there are updates available - giving rise to the assumption that the widget would be invisible when no updates are available (which seems very reasonable).
  
  This doesn't seem to be the case for me, though. I am permanently seeing a `0`. So either the documentation or the implementation might need a little tweak.
  
  # Qtile version
  
  <!--
  Please include the exact commit hash of the version of Qtile that failed.
  -->
  
  0.15.1
  
  </issue>
  <code>
  [start of libqtile/widget/check_updates.py]
  1 # Copyright (c) 2015 Ali Mousavi
  2 #
  3 # Permission is hereby granted, free of charge, to any person obtaining a copy
  4 # of this software and associated documentation files (the "Software"), to deal
  5 # in the Software without restriction, including without limitation the rights
  6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7 # copies of the Software, and to permit persons to whom the Software is
  8 # furnished to do so, subject to the following conditions:
  9 #
  10 # The above copyright notice and this permission notice shall be included in
  11 # all copies or substantial portions of the Software.
  12 #
  13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19 # SOFTWARE.
  20 
  21 import os
  22 from subprocess import CalledProcessError, Popen
  23 
  24 from libqtile.log_utils import logger
  25 from libqtile.widget import base
  26 
  27 
  28 class CheckUpdates(base.ThreadedPollText):
  29     """Shows number of pending updates in different unix systems"""
  30     orientations = base.ORIENTATION_HORIZONTAL
  31     defaults = [
  32         ("distro", "Arch", "Name of your distribution"),
  33         ("custom_command", None, "Custom shell command for checking updates (counts the lines of the output)"),
  34         ("update_interval", 60, "Update interval in seconds."),
  35         ('execute', None, 'Command to execute on click'),
  36         ("display_format", "Updates: {updates}", "Display format if updates available"),
  37         ("colour_no_updates", "ffffff", "Colour when there's no updates."),
  38         ("colour_have_updates", "ffffff", "Colour when there are updates."),
  39         ("restart_indicator", "", "Indicator to represent reboot is required. (Ubuntu only)")
  40     ]
  41 
  42     def __init__(self, **config):
  43         base.ThreadedPollText.__init__(self, **config)
  44         self.add_defaults(CheckUpdates.defaults)
  45 
  46         # format: "Distro": ("cmd", "number of lines to subtract from output")
  47         self.cmd_dict = {"Arch": ("pacman -Qu", 0),
  48                          "Arch_checkupdates": ("checkupdates", 0),
  49                          "Arch_Sup": ("pacman -Sup", 1),
  50                          "Arch_yay": ("yay -Qu", 0),
  51                          "Debian": ("apt-show-versions -u -b", 0),
  52                          "Ubuntu": ("aptitude search ~U", 0),
  53                          "Fedora": ("dnf list updates", 3),
  54                          "FreeBSD": ("pkg_version -I -l '<'", 0),
  55                          "Mandriva": ("urpmq --auto-select", 0)
  56                          }
  57 
  58         # Check if distro name is valid.
  59         try:
  60             self.cmd = self.cmd_dict[self.distro][0].split()
  61             self.subtr = self.cmd_dict[self.distro][1]
  62         except KeyError:
  63             distros = sorted(self.cmd_dict.keys())
  64             logger.error(self.distro + ' is not a valid distro name. ' +
  65                          'Use one of the list: ' + str(distros) + '.')
  66             self.cmd = None
  67 
  68     def _check_updates(self):
  69         # type: () -> str
  70         try:
  71             if self.custom_command is None:
  72                 updates = self.call_process(self.cmd)
  73             else:
  74                 updates = self.call_process(self.custom_command, shell=True)
  75                 self.subtr = 0
  76         except CalledProcessError:
  77             updates = ""
  78         num_updates = str(len(updates.splitlines()) - self.subtr)
  79 
  80         if self.restart_indicator and os.path.exists('/var/run/reboot-required'):
  81             num_updates += self.restart_indicator
  82 
  83         self._set_colour(num_updates)
  84         return self.display_format.format(**{"updates": num_updates})
  85 
  86     def _set_colour(self, num_updates):
  87         # type: (str) -> None
  88         if not num_updates.startswith("0"):
  89             self.layout.colour = self.colour_have_updates
  90         else:
  91             self.layout.colour = self.colour_no_updates
  92 
  93     def poll(self):
  94         # type: () -> str
  95         if not self.cmd:
  96             return "N/A"
  97         return self._check_updates()
  98 
  99     def button_press(self, x, y, button):
  100         # type: (int, int, int) -> None
  101         base.ThreadedPollText.button_press(self, x, y, button)
  102         if button == 1 and self.execute is not None:
  103             Popen(self.execute, shell=True)
  104
  [end of libqtile/widget/check_updates.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/libqtile/widget/check_updates.py b/libqtile/widget/check_updates.py
  --- a/libqtile/widget/check_updates.py
  +++ b/libqtile/widget/check_updates.py
  @@ -75,7 +75,11 @@
                   self.subtr = 0
           except CalledProcessError:
               updates = ""
  -        num_updates = str(len(updates.splitlines()) - self.subtr)
  +        num_updates = len(updates.splitlines()) - self.subtr
  +
  +        if num_updates == 0:
  +            return ""
  +        num_updates = str(num_updates)
   
           if self.restart_indicator and os.path.exists('/var/run/reboot-required'):
               num_updates += self.restart_indicator
  
verification_info: {"golden_diff": "diff --git a/libqtile/widget/check_updates.py b/libqtile/widget/check_updates.py\n--- a/libqtile/widget/check_updates.py\n+++ b/libqtile/widget/check_updates.py\n@@ -75,7 +75,11 @@\n                 self.subtr = 0\n         except CalledProcessError:\n             updates = \"\"\n-        num_updates = str(len(updates.splitlines()) - self.subtr)\n+        num_updates = len(updates.splitlines()) - self.subtr\n+\n+        if num_updates == 0:\n+            return \"\"\n+        num_updates = str(num_updates)\n \n         if self.restart_indicator and os.path.exists('/var/run/reboot-required'):\n             num_updates += self.restart_indicator\n", "issue": "widget.CheckUpdates not hidden when no updates are available\n<!--\r\nPlease do not ask general questions here! There are [community\r\ncontact](https://github.com/qtile/qtile#community) options for that.\r\n-->\r\n\r\n# Issue description\r\n\r\n<!--\r\nA brief discussion of what failed and how it failed. A description of\r\nwhat you tried is helpful, i.e. \"When I use lazy.kill() on a window I get\r\nthe following stack trace\" instead of \"Closing windows doesn't work\".\r\n-->\r\n\r\nThe documentation for [`CheckUpdates`](http://docs.qtile.org/en/latest/manual/ref/widgets.html#checkupdates) `display_format` mentions that the given format-specifier will only be used when there are updates available - giving rise to the assumption that the widget would be invisible when no updates are available (which seems very reasonable).\r\n\r\nThis doesn't seem to be the case for me, though. I am permanently seeing a `0`. So either the documentation or the implementation might need a little tweak.\r\n\r\n# Qtile version\r\n\r\n<!--\r\nPlease include the exact commit hash of the version of Qtile that failed.\r\n-->\r\n\r\n0.15.1\n", "before_files": [{"content": "# Copyright (c) 2015 Ali Mousavi\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nimport os\nfrom subprocess import CalledProcessError, Popen\n\nfrom libqtile.log_utils import logger\nfrom libqtile.widget import base\n\n\nclass CheckUpdates(base.ThreadedPollText):\n    \"\"\"Shows number of pending updates in different unix systems\"\"\"\n    orientations = base.ORIENTATION_HORIZONTAL\n    defaults = [\n        (\"distro\", \"Arch\", \"Name of your distribution\"),\n        (\"custom_command\", None, \"Custom shell command for checking updates (counts the lines of the output)\"),\n        (\"update_interval\", 60, \"Update interval in seconds.\"),\n        ('execute', None, 'Command to execute on click'),\n        (\"display_format\", \"Updates: {updates}\", \"Display format if updates available\"),\n        (\"colour_no_updates\", \"ffffff\", \"Colour when there's no updates.\"),\n        (\"colour_have_updates\", \"ffffff\", \"Colour when there are updates.\"),\n        (\"restart_indicator\", \"\", \"Indicator to represent reboot is required. (Ubuntu only)\")\n    ]\n\n    def __init__(self, **config):\n        base.ThreadedPollText.__init__(self, **config)\n        self.add_defaults(CheckUpdates.defaults)\n\n        # format: \"Distro\": (\"cmd\", \"number of lines to subtract from output\")\n        self.cmd_dict = {\"Arch\": (\"pacman -Qu\", 0),\n                         \"Arch_checkupdates\": (\"checkupdates\", 0),\n                         \"Arch_Sup\": (\"pacman -Sup\", 1),\n                         \"Arch_yay\": (\"yay -Qu\", 0),\n                         \"Debian\": (\"apt-show-versions -u -b\", 0),\n                         \"Ubuntu\": (\"aptitude search ~U\", 0),\n                         \"Fedora\": (\"dnf list updates\", 3),\n                         \"FreeBSD\": (\"pkg_version -I -l '<'\", 0),\n                         \"Mandriva\": (\"urpmq --auto-select\", 0)\n                         }\n\n        # Check if distro name is valid.\n        try:\n            self.cmd = self.cmd_dict[self.distro][0].split()\n            self.subtr = self.cmd_dict[self.distro][1]\n        except KeyError:\n            distros = sorted(self.cmd_dict.keys())\n            logger.error(self.distro + ' is not a valid distro name. ' +\n                         'Use one of the list: ' + str(distros) + '.')\n            self.cmd = None\n\n    def _check_updates(self):\n        # type: () -> str\n        try:\n            if self.custom_command is None:\n                updates = self.call_process(self.cmd)\n            else:\n                updates = self.call_process(self.custom_command, shell=True)\n                self.subtr = 0\n        except CalledProcessError:\n            updates = \"\"\n        num_updates = str(len(updates.splitlines()) - self.subtr)\n\n        if self.restart_indicator and os.path.exists('/var/run/reboot-required'):\n            num_updates += self.restart_indicator\n\n        self._set_colour(num_updates)\n        return self.display_format.format(**{\"updates\": num_updates})\n\n    def _set_colour(self, num_updates):\n        # type: (str) -> None\n        if not num_updates.startswith(\"0\"):\n            self.layout.colour = self.colour_have_updates\n        else:\n            self.layout.colour = self.colour_no_updates\n\n    def poll(self):\n        # type: () -> str\n        if not self.cmd:\n            return \"N/A\"\n        return self._check_updates()\n\n    def button_press(self, x, y, button):\n        # type: (int, int, int) -> None\n        base.ThreadedPollText.button_press(self, x, y, button)\n        if button == 1 and self.execute is not None:\n            Popen(self.execute, shell=True)\n", "path": "libqtile/widget/check_updates.py"}]}