prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Failing to load sqlalchemy-plugin in pyinstaller'ed exe
  This line of code works perfectly fine while running as a file from spyder.
  
  engine =  sqlalchemy.create_engine('teradata://uid:pwd@DBinstance?driver=Teradata')
  However, after making an exe file using pyinstaller, I get the following error while running the exe:
  
  sqlalchemy.exc.NoSuchModuleError: Can't load plugin:sqlalchemy.dialects:teradata
  
  This looks to be an exe-creation-issue in loading libraries. Has anyone encountered a similar issue and was able to resolve? Any pointers would be appreciated.
  
  </issue>
  <code>
  [start of PyInstaller/hooks/hook-sqlalchemy.py]
  1 #-----------------------------------------------------------------------------
  2 # Copyright (c) 2005-2023, 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 import re
  13 import importlib.util
  14 
  15 from PyInstaller import isolated
  16 from PyInstaller.lib.modulegraph.modulegraph import SourceModule
  17 from PyInstaller.utils.hooks import check_requirement, logger
  18 
  19 # 'sqlalchemy.testing' causes bundling a lot of unnecessary modules.
  20 excludedimports = ['sqlalchemy.testing']
  21 
  22 # Include most common database bindings some database bindings are detected and include some are not. We should
  23 # explicitly include database backends.
  24 hiddenimports = ['pysqlite2', 'MySQLdb', 'psycopg2', 'sqlalchemy.ext.baked']
  25 
  26 if check_requirement('sqlalchemy >= 1.4'):
  27     hiddenimports.append("sqlalchemy.sql.default_comparator")
  28 
  29 
  30 @isolated.decorate
  31 def _get_dialect_modules(module_name):
  32     import importlib
  33     module = importlib.import_module(module_name)
  34     return [f"{module_name}.{submodule_name}" for submodule_name in module.__all__]
  35 
  36 
  37 # In SQLAlchemy >= 0.6, the "sqlalchemy.dialects" package provides dialects.
  38 # In SQLAlchemy <= 0.5, the "sqlalchemy.databases" package provides dialects.
  39 if check_requirement('sqlalchemy >= 0.6'):
  40     hiddenimports += _get_dialect_modules("sqlalchemy.dialects")
  41 else:
  42     hiddenimports += _get_dialect_modules("sqlalchemy.databases")
  43 
  44 
  45 def hook(hook_api):
  46     """
  47     SQLAlchemy 0.9 introduced the decorator 'util.dependencies'.  This decorator does imports. E.g.:
  48 
  49             @util.dependencies("sqlalchemy.sql.schema")
  50 
  51     This hook scans for included SQLAlchemy modules and then scans those modules for any util.dependencies and marks
  52     those modules as hidden imports.
  53     """
  54 
  55     if not check_requirement('sqlalchemy >= 0.9'):
  56         return
  57 
  58     # this parser is very simplistic but seems to catch all cases as of V1.1
  59     depend_regex = re.compile(r'@util.dependencies\([\'"](.*?)[\'"]\)')
  60 
  61     hidden_imports_set = set()
  62     known_imports = set()
  63     for node in hook_api.module_graph.iter_graph(start=hook_api.module):
  64         if isinstance(node, SourceModule) and node.identifier.startswith('sqlalchemy.'):
  65             known_imports.add(node.identifier)
  66 
  67             # Read the source...
  68             with open(node.filename, 'rb') as f:
  69                 source_code = f.read()
  70             source_code = importlib.util.decode_source(source_code)
  71 
  72             # ... and scan it
  73             for match in depend_regex.findall(source_code):
  74                 hidden_imports_set.add(match)
  75 
  76     hidden_imports_set -= known_imports
  77     if len(hidden_imports_set):
  78         logger.info("  Found %d sqlalchemy hidden imports", len(hidden_imports_set))
  79         hook_api.add_imports(*list(hidden_imports_set))
  80
  [end of PyInstaller/hooks/hook-sqlalchemy.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-sqlalchemy.py b/PyInstaller/hooks/hook-sqlalchemy.py
  --- a/PyInstaller/hooks/hook-sqlalchemy.py
  +++ b/PyInstaller/hooks/hook-sqlalchemy.py
  @@ -14,7 +14,9 @@
   
   from PyInstaller import isolated
   from PyInstaller.lib.modulegraph.modulegraph import SourceModule
  -from PyInstaller.utils.hooks import check_requirement, logger
  +from PyInstaller.utils.hooks import check_requirement, collect_entry_point, logger
  +
  +datas = []
   
   # 'sqlalchemy.testing' causes bundling a lot of unnecessary modules.
   excludedimports = ['sqlalchemy.testing']
  @@ -41,6 +43,13 @@
   else:
       hiddenimports += _get_dialect_modules("sqlalchemy.databases")
   
  +# Collect additional dialects and plugins that are registered via entry-points, under assumption that they are available
  +# in the build environment for a reason (i.e., they are used).
  +for entry_point_name in ('sqlalchemy.dialects', 'sqlalchemy.plugins'):
  +    ep_datas, ep_hiddenimports = collect_entry_point(entry_point_name)
  +    datas += ep_datas
  +    hiddenimports += ep_hiddenimports
  +
   
   def hook(hook_api):
       """
  
verification_info: {"golden_diff": "diff --git a/PyInstaller/hooks/hook-sqlalchemy.py b/PyInstaller/hooks/hook-sqlalchemy.py\n--- a/PyInstaller/hooks/hook-sqlalchemy.py\n+++ b/PyInstaller/hooks/hook-sqlalchemy.py\n@@ -14,7 +14,9 @@\n \n from PyInstaller import isolated\n from PyInstaller.lib.modulegraph.modulegraph import SourceModule\n-from PyInstaller.utils.hooks import check_requirement, logger\n+from PyInstaller.utils.hooks import check_requirement, collect_entry_point, logger\n+\n+datas = []\n \n # 'sqlalchemy.testing' causes bundling a lot of unnecessary modules.\n excludedimports = ['sqlalchemy.testing']\n@@ -41,6 +43,13 @@\n else:\n     hiddenimports += _get_dialect_modules(\"sqlalchemy.databases\")\n \n+# Collect additional dialects and plugins that are registered via entry-points, under assumption that they are available\n+# in the build environment for a reason (i.e., they are used).\n+for entry_point_name in ('sqlalchemy.dialects', 'sqlalchemy.plugins'):\n+    ep_datas, ep_hiddenimports = collect_entry_point(entry_point_name)\n+    datas += ep_datas\n+    hiddenimports += ep_hiddenimports\n+\n \n def hook(hook_api):\n     \"\"\"\n", "issue": "Failing to load sqlalchemy-plugin in pyinstaller'ed exe\nThis line of code works perfectly fine while running as a file from spyder.\r\n\r\nengine =  sqlalchemy.create_engine('teradata://uid:pwd@DBinstance?driver=Teradata')\r\nHowever, after making an exe file using pyinstaller, I get the following error while running the exe:\r\n\r\nsqlalchemy.exc.NoSuchModuleError: Can't load plugin:sqlalchemy.dialects:teradata\r\n\r\nThis looks to be an exe-creation-issue in loading libraries. Has anyone encountered a similar issue and was able to resolve? Any pointers would be appreciated.\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2005-2023, 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\nimport re\nimport importlib.util\n\nfrom PyInstaller import isolated\nfrom PyInstaller.lib.modulegraph.modulegraph import SourceModule\nfrom PyInstaller.utils.hooks import check_requirement, logger\n\n# 'sqlalchemy.testing' causes bundling a lot of unnecessary modules.\nexcludedimports = ['sqlalchemy.testing']\n\n# Include most common database bindings some database bindings are detected and include some are not. We should\n# explicitly include database backends.\nhiddenimports = ['pysqlite2', 'MySQLdb', 'psycopg2', 'sqlalchemy.ext.baked']\n\nif check_requirement('sqlalchemy >= 1.4'):\n    hiddenimports.append(\"sqlalchemy.sql.default_comparator\")\n\n\n@isolated.decorate\ndef _get_dialect_modules(module_name):\n    import importlib\n    module = importlib.import_module(module_name)\n    return [f\"{module_name}.{submodule_name}\" for submodule_name in module.__all__]\n\n\n# In SQLAlchemy >= 0.6, the \"sqlalchemy.dialects\" package provides dialects.\n# In SQLAlchemy <= 0.5, the \"sqlalchemy.databases\" package provides dialects.\nif check_requirement('sqlalchemy >= 0.6'):\n    hiddenimports += _get_dialect_modules(\"sqlalchemy.dialects\")\nelse:\n    hiddenimports += _get_dialect_modules(\"sqlalchemy.databases\")\n\n\ndef hook(hook_api):\n    \"\"\"\n    SQLAlchemy 0.9 introduced the decorator 'util.dependencies'.  This decorator does imports. E.g.:\n\n            @util.dependencies(\"sqlalchemy.sql.schema\")\n\n    This hook scans for included SQLAlchemy modules and then scans those modules for any util.dependencies and marks\n    those modules as hidden imports.\n    \"\"\"\n\n    if not check_requirement('sqlalchemy >= 0.9'):\n        return\n\n    # this parser is very simplistic but seems to catch all cases as of V1.1\n    depend_regex = re.compile(r'@util.dependencies\\([\\'\"](.*?)[\\'\"]\\)')\n\n    hidden_imports_set = set()\n    known_imports = set()\n    for node in hook_api.module_graph.iter_graph(start=hook_api.module):\n        if isinstance(node, SourceModule) and node.identifier.startswith('sqlalchemy.'):\n            known_imports.add(node.identifier)\n\n            # Read the source...\n            with open(node.filename, 'rb') as f:\n                source_code = f.read()\n            source_code = importlib.util.decode_source(source_code)\n\n            # ... and scan it\n            for match in depend_regex.findall(source_code):\n                hidden_imports_set.add(match)\n\n    hidden_imports_set -= known_imports\n    if len(hidden_imports_set):\n        logger.info(\"  Found %d sqlalchemy hidden imports\", len(hidden_imports_set))\n        hook_api.add_imports(*list(hidden_imports_set))\n", "path": "PyInstaller/hooks/hook-sqlalchemy.py"}]}