prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  `hook-pkg_resources.py` is including hidden imports that are not available
  https://github.com/pyinstaller/pyinstaller/blob/3b5d233d02472ad9d589a798d19ad3d3df645223/PyInstaller/hooks/hook-pkg_resources.py#L20
  
  and
  
  https://github.com/pyinstaller/pyinstaller/blob/3b5d233d02472ad9d589a798d19ad3d3df645223/PyInstaller/hooks/hook-pkg_resources.py#L30
  
  Refer to https://github.com/pypa/setuptools/issues/1963 for the past need for including `py2_warn` and [the subsequent removal of py2_warn from setuptools](https://github.com/pypa/setuptools/pull/2238).
  
  The `pkg_resources.py2_warn` submodule was introduced in v45.0.0 and removed in v49.1.1. Therefore, an check for those versions would look like this:
  ```python
  if is_module_satisfies("setuptools >= 45.0.0, < 49.1.1"):
      hiddenimports.append('pkg_resources.py2_warn')
  ```
  
  As for `pkg_resources.markers`, I haven't found any references to any `pkg_resources.markers` packages through Google searches. I'm not convinced that it ever existed at any point. Perhaps it was being confused for (or just a typo of) `packaging.markers`, which does exist. Since `hook-pkg_resources.py` already collects the submodules of `packaging`, there doesn't need to be an extra hidden import added for `packaging.markers`. Therefore, I think that the `pkg_resources.markers` hidden import line can be removed completely.
  
  Another module that it is trying to include is `pkg_resources._vendor.pyparsing.diagrams`. This module can only be used when the `railroad` module is available. Therefore, a check should be added to make sure that the `railroad` module is available, and filter out the diagrams module when it isn't.
  
  For example:
  ```python
  from PyInstaller.utils.hooks import (
      collect_submodules,
      is_module_satisfies,
      can_import_module,
      is_module_or_submodule
  )
  
  hiddenimports = []
  
  # pkg_resources keeps vendored modules in its _vendor subpackage and does sys.meta_path based import magic to expose
  # them as pkg_resources.extern.*
  if not can_import_module('railroad'):
      # The `railroad` package is an optional requirement for `pyparsing`. `pyparsing.diagrams` depends on `railroad`, so
      # filter it out when `railroad` is not available.
      hiddenimports += collect_submodules(
          'pkg_resources._vendor',
          lambda name: is_module_or_submodule(name, 'pkg_resources._vendor.pyparsing.diagrams'))
  else:
      hiddenimports += collect_submodules('pkg_resources._vendor')
  ```
  
  PyInstaller: v5.1
  
  </issue>
  <code>
  [start of PyInstaller/hooks/hook-pkg_resources.py]
  1 #-----------------------------------------------------------------------------
  2 # Copyright (c) 2005-2022, PyInstaller Development Team.
  3 #
  4 # Distributed under the terms of the GNU General Public License (version 2
  5 # or later) with exception for distributing the bootloader.
  6 #
  7 # The full license is in the file COPYING.txt, distributed with this software.
  8 #
  9 # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10 #-----------------------------------------------------------------------------
  11 
  12 from PyInstaller.utils.hooks import collect_submodules, is_module_satisfies
  13 
  14 # pkg_resources keeps vendored modules in its _vendor subpackage, and does sys.meta_path based import magic to expose
  15 # them as pkg_resources.extern.*
  16 hiddenimports = collect_submodules('pkg_resources._vendor')
  17 
  18 # pkg_resources v45.0 dropped support for Python 2 and added this module printing a warning. We could save some bytes if
  19 # we would replace this by a fake module.
  20 hiddenimports.append('pkg_resources.py2_warn')
  21 
  22 excludedimports = ['__main__']
  23 
  24 # Some more hidden imports. See:
  25 # https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/15#issuecomment-663699288 `packaging` can either be
  26 # its own package, or embedded in `pkg_resources._vendor.packaging`, or both. Assume the worst and include both if
  27 # present.
  28 hiddenimports += collect_submodules('packaging')
  29 
  30 hiddenimports += ['pkg_resources.markers']
  31 
  32 # As of v60.7, setuptools vendored jaraco and has pkg_resources use it. Currently, the pkg_resources._vendor.jaraco
  33 # namespace package cannot be automatically scanned due to limited support for pure namespace packages in our hook
  34 # utilities.
  35 #
  36 # In setuptools 60.7.0, the vendored jaraco.text package included "Lorem Ipsum.txt" data file, which also has to be
  37 # collected. However, the presence of the data file (and the resulting directory hierarchy) confuses the importer's
  38 # redirection logic; instead of trying to work-around that, tell user to upgrade or downgrade their setuptools.
  39 if is_module_satisfies("setuptools == 60.7.0"):
  40     raise SystemExit(
  41         "ERROR: Setuptools 60.7.0 is incompatible with PyInstaller. "
  42         "Downgrade to an earlier version or upgrade to a later version."
  43     )
  44 # In setuptools 60.7.1, the "Lorem Ipsum.txt" data file was dropped from the vendored jaraco.text package, so we can
  45 # accommodate it with couple of hidden imports.
  46 elif is_module_satisfies("setuptools >= 60.7.1"):
  47     hiddenimports += [
  48         'pkg_resources._vendor.jaraco.functools',
  49         'pkg_resources._vendor.jaraco.context',
  50         'pkg_resources._vendor.jaraco.text',
  51     ]
  52
  [end of PyInstaller/hooks/hook-pkg_resources.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/PyInstaller/hooks/hook-pkg_resources.py b/PyInstaller/hooks/hook-pkg_resources.py
  --- a/PyInstaller/hooks/hook-pkg_resources.py
  +++ b/PyInstaller/hooks/hook-pkg_resources.py
  @@ -9,26 +9,32 @@
   # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
   #-----------------------------------------------------------------------------
   
  -from PyInstaller.utils.hooks import collect_submodules, is_module_satisfies
  +from PyInstaller.utils.hooks import collect_submodules, is_module_satisfies, can_import_module
   
   # pkg_resources keeps vendored modules in its _vendor subpackage, and does sys.meta_path based import magic to expose
   # them as pkg_resources.extern.*
  -hiddenimports = collect_submodules('pkg_resources._vendor')
  +
  +# The `railroad` package is an optional requirement for `pyparsing`. `pyparsing.diagrams` depends on `railroad`, so
  +# filter it out when `railroad` is not available.
  +if can_import_module('railroad'):
  +    hiddenimports = collect_submodules('pkg_resources._vendor')
  +else:
  +    hiddenimports = collect_submodules(
  +        'pkg_resources._vendor', filter=lambda name: 'pkg_resources._vendor.pyparsing.diagram' not in name
  +    )
   
   # pkg_resources v45.0 dropped support for Python 2 and added this module printing a warning. We could save some bytes if
   # we would replace this by a fake module.
  -hiddenimports.append('pkg_resources.py2_warn')
  +if is_module_satisfies('setuptools >= 45.0.0, < 49.1.1'):
  +    hiddenimports.append('pkg_resources.py2_warn')
   
   excludedimports = ['__main__']
   
   # Some more hidden imports. See:
   # https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/15#issuecomment-663699288 `packaging` can either be
  -# its own package, or embedded in `pkg_resources._vendor.packaging`, or both. Assume the worst and include both if
  -# present.
  +# its own package, or embedded in `pkg_resources._vendor.packaging`, or both.
   hiddenimports += collect_submodules('packaging')
   
  -hiddenimports += ['pkg_resources.markers']
  -
   # As of v60.7, setuptools vendored jaraco and has pkg_resources use it. Currently, the pkg_resources._vendor.jaraco
   # namespace package cannot be automatically scanned due to limited support for pure namespace packages in our hook
   # utilities.
  
verification_info: {"golden_diff": "diff --git a/PyInstaller/hooks/hook-pkg_resources.py b/PyInstaller/hooks/hook-pkg_resources.py\n--- a/PyInstaller/hooks/hook-pkg_resources.py\n+++ b/PyInstaller/hooks/hook-pkg_resources.py\n@@ -9,26 +9,32 @@\n # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)\n #-----------------------------------------------------------------------------\n \n-from PyInstaller.utils.hooks import collect_submodules, is_module_satisfies\n+from PyInstaller.utils.hooks import collect_submodules, is_module_satisfies, can_import_module\n \n # pkg_resources keeps vendored modules in its _vendor subpackage, and does sys.meta_path based import magic to expose\n # them as pkg_resources.extern.*\n-hiddenimports = collect_submodules('pkg_resources._vendor')\n+\n+# The `railroad` package is an optional requirement for `pyparsing`. `pyparsing.diagrams` depends on `railroad`, so\n+# filter it out when `railroad` is not available.\n+if can_import_module('railroad'):\n+    hiddenimports = collect_submodules('pkg_resources._vendor')\n+else:\n+    hiddenimports = collect_submodules(\n+        'pkg_resources._vendor', filter=lambda name: 'pkg_resources._vendor.pyparsing.diagram' not in name\n+    )\n \n # pkg_resources v45.0 dropped support for Python 2 and added this module printing a warning. We could save some bytes if\n # we would replace this by a fake module.\n-hiddenimports.append('pkg_resources.py2_warn')\n+if is_module_satisfies('setuptools >= 45.0.0, < 49.1.1'):\n+    hiddenimports.append('pkg_resources.py2_warn')\n \n excludedimports = ['__main__']\n \n # Some more hidden imports. See:\n # https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/15#issuecomment-663699288 `packaging` can either be\n-# its own package, or embedded in `pkg_resources._vendor.packaging`, or both. Assume the worst and include both if\n-# present.\n+# its own package, or embedded in `pkg_resources._vendor.packaging`, or both.\n hiddenimports += collect_submodules('packaging')\n \n-hiddenimports += ['pkg_resources.markers']\n-\n # As of v60.7, setuptools vendored jaraco and has pkg_resources use it. Currently, the pkg_resources._vendor.jaraco\n # namespace package cannot be automatically scanned due to limited support for pure namespace packages in our hook\n # utilities.\n", "issue": "`hook-pkg_resources.py` is including hidden imports that are not available\nhttps://github.com/pyinstaller/pyinstaller/blob/3b5d233d02472ad9d589a798d19ad3d3df645223/PyInstaller/hooks/hook-pkg_resources.py#L20\r\n\r\nand\r\n\r\nhttps://github.com/pyinstaller/pyinstaller/blob/3b5d233d02472ad9d589a798d19ad3d3df645223/PyInstaller/hooks/hook-pkg_resources.py#L30\r\n\r\nRefer to https://github.com/pypa/setuptools/issues/1963 for the past need for including `py2_warn` and [the subsequent removal of py2_warn from setuptools](https://github.com/pypa/setuptools/pull/2238).\r\n\r\nThe `pkg_resources.py2_warn` submodule was introduced in v45.0.0 and removed in v49.1.1. Therefore, an check for those versions would look like this:\r\n```python\r\nif is_module_satisfies(\"setuptools >= 45.0.0, < 49.1.1\"):\r\n    hiddenimports.append('pkg_resources.py2_warn')\r\n```\r\n\r\nAs for `pkg_resources.markers`, I haven't found any references to any `pkg_resources.markers` packages through Google searches. I'm not convinced that it ever existed at any point. Perhaps it was being confused for (or just a typo of) `packaging.markers`, which does exist. Since `hook-pkg_resources.py` already collects the submodules of `packaging`, there doesn't need to be an extra hidden import added for `packaging.markers`. Therefore, I think that the `pkg_resources.markers` hidden import line can be removed completely.\r\n\r\nAnother module that it is trying to include is `pkg_resources._vendor.pyparsing.diagrams`. This module can only be used when the `railroad` module is available. Therefore, a check should be added to make sure that the `railroad` module is available, and filter out the diagrams module when it isn't.\r\n\r\nFor example:\r\n```python\r\nfrom PyInstaller.utils.hooks import (\r\n    collect_submodules,\r\n    is_module_satisfies,\r\n    can_import_module,\r\n    is_module_or_submodule\r\n)\r\n\r\nhiddenimports = []\r\n\r\n# pkg_resources keeps vendored modules in its _vendor subpackage and does sys.meta_path based import magic to expose\r\n# them as pkg_resources.extern.*\r\nif not can_import_module('railroad'):\r\n    # The `railroad` package is an optional requirement for `pyparsing`. `pyparsing.diagrams` depends on `railroad`, so\r\n    # filter it out when `railroad` is not available.\r\n    hiddenimports += collect_submodules(\r\n        'pkg_resources._vendor',\r\n        lambda name: is_module_or_submodule(name, 'pkg_resources._vendor.pyparsing.diagrams'))\r\nelse:\r\n    hiddenimports += collect_submodules('pkg_resources._vendor')\r\n```\r\n\r\nPyInstaller: v5.1\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2005-2022, PyInstaller Development Team.\n#\n# Distributed under the terms of the GNU General Public License (version 2\n# or later) with exception for distributing the bootloader.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#\n# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)\n#-----------------------------------------------------------------------------\n\nfrom PyInstaller.utils.hooks import collect_submodules, is_module_satisfies\n\n# pkg_resources keeps vendored modules in its _vendor subpackage, and does sys.meta_path based import magic to expose\n# them as pkg_resources.extern.*\nhiddenimports = collect_submodules('pkg_resources._vendor')\n\n# pkg_resources v45.0 dropped support for Python 2 and added this module printing a warning. We could save some bytes if\n# we would replace this by a fake module.\nhiddenimports.append('pkg_resources.py2_warn')\n\nexcludedimports = ['__main__']\n\n# Some more hidden imports. See:\n# https://github.com/pyinstaller/pyinstaller-hooks-contrib/issues/15#issuecomment-663699288 `packaging` can either be\n# its own package, or embedded in `pkg_resources._vendor.packaging`, or both. Assume the worst and include both if\n# present.\nhiddenimports += collect_submodules('packaging')\n\nhiddenimports += ['pkg_resources.markers']\n\n# As of v60.7, setuptools vendored jaraco and has pkg_resources use it. Currently, the pkg_resources._vendor.jaraco\n# namespace package cannot be automatically scanned due to limited support for pure namespace packages in our hook\n# utilities.\n#\n# In setuptools 60.7.0, the vendored jaraco.text package included \"Lorem Ipsum.txt\" data file, which also has to be\n# collected. However, the presence of the data file (and the resulting directory hierarchy) confuses the importer's\n# redirection logic; instead of trying to work-around that, tell user to upgrade or downgrade their setuptools.\nif is_module_satisfies(\"setuptools == 60.7.0\"):\n    raise SystemExit(\n        \"ERROR: Setuptools 60.7.0 is incompatible with PyInstaller. \"\n        \"Downgrade to an earlier version or upgrade to a later version.\"\n    )\n# In setuptools 60.7.1, the \"Lorem Ipsum.txt\" data file was dropped from the vendored jaraco.text package, so we can\n# accommodate it with couple of hidden imports.\nelif is_module_satisfies(\"setuptools >= 60.7.1\"):\n    hiddenimports += [\n        'pkg_resources._vendor.jaraco.functools',\n        'pkg_resources._vendor.jaraco.context',\n        'pkg_resources._vendor.jaraco.text',\n    ]\n", "path": "PyInstaller/hooks/hook-pkg_resources.py"}]}