prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Can't create package for windows with kivy 1.9 portable
  I'm looking to port an existing kivy 1.8 project to kivy 1.9. I've just downloaded the portable version and have the application working.
  
  However when packaging the app using pyinstaller and the instructions on http://kivy.org/docs/guide/packaging-windows.html the app packages, but on execution immediately fails with error:
  
  ```
  Traceback (most recent call last):
    File "<string>", line 34, in <module>
  ImportError: No module named pygame.pkgdata
  ```
  
  I've tried using my old .spec file and generating a new one with exactly the same results.
  
  I'm a bit mystified where this is coming from as pygame isn't imported anywhere in my application and I thought it had been replaced with sdl2 in kivy 1.9. I'm also confused that the application works when run directly.
  
  Anyone come across this issue or can point me in the right direction?
  
  
  </issue>
  <code>
  [start of kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py]
  1 from os.path import join, dirname
  2 from os import environ, chdir, putenv
  3 import sys
  4 
  5 root = 'kivy_install'
  6 if hasattr(sys, '_MEIPASS'):
  7     # PyInstaller >= 1.6
  8     chdir(sys._MEIPASS)
  9     root = join(sys._MEIPASS, root)
  10 elif '_MEIPASS2' in environ:
  11     # PyInstaller < 1.6 (tested on 1.5 only)
  12     chdir(environ['_MEIPASS2'])
  13     root = join(environ['_MEIPASS2'], root)
  14 else:
  15     chdir(dirname(sys.argv[0]))
  16     root = join(dirname(sys.argv[0]), root)
  17 
  18 
  19 sys.path += [join(root, '_libs')]
  20 
  21 if sys.platform == 'darwin':
  22     sitepackages = join(root, '..', 'sitepackages')
  23     sys.path += [sitepackages, join(sitepackages, 'gst-0.10')]
  24     putenv('GST_REGISTRY_FORK', 'no')
  25 
  26 environ['GST_PLUGIN_PATH'] = join(root, '..', 'gst-plugins')
  27 environ['KIVY_DATA_DIR'] = join(root, 'data')
  28 environ['KIVY_EXTS_DIR'] = join(root, 'extensions')
  29 environ['KIVY_MODULES_DIR'] = join(root, 'modules')
  30 environ['KIVY_EMBED'] = '1'
  31 
  32 # Monkey-patch pygame to get around an issue with Pygame window icon and
  33 # PyInstaller 2.1. See kivy issue #1638
  34 # Uncomment the following to package pygame
  35 #import pygame.pkgdata
  36 #_original_getResource = pygame.pkgdata.getResource
  37 #
  38 #
  39 #def getResource(identifier, *args, **kwargs):
  40 #    if identifier == 'pygame_icon.tiff':
  41 #        raise IOError()
  42 #    return _original_getResource(identifier, *args, **kwargs)
  43 #pygame.pkgdata.getResource = getResource
  44
  [end of kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.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/kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py b/kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py
  --- a/kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py
  +++ b/kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py
  @@ -29,15 +29,17 @@
   environ['KIVY_MODULES_DIR'] = join(root, 'modules')
   environ['KIVY_EMBED'] = '1'
   
  +
   # Monkey-patch pygame to get around an issue with Pygame window icon and
   # PyInstaller 2.1. See kivy issue #1638
  -# Uncomment the following to package pygame
  -#import pygame.pkgdata
  -#_original_getResource = pygame.pkgdata.getResource
  -#
  -#
  -#def getResource(identifier, *args, **kwargs):
  -#    if identifier == 'pygame_icon.tiff':
  -#        raise IOError()
  -#    return _original_getResource(identifier, *args, **kwargs)
  -#pygame.pkgdata.getResource = getResource
  +def getResource(identifier, *args, **kwargs):
  +    if identifier == 'pygame_icon.tiff':
  +        raise IOError()
  +    return _original_getResource(identifier, *args, **kwargs)
  +
  +try:
  +    import pygame.pkgdata
  +    _original_getResource = pygame.pkgdata.getResource
  +    pygame.pkgdata.getResource = getResource
  +except ImportError:
  +    pass
  
verification_info: {"golden_diff": "diff --git a/kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py b/kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py\n--- a/kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py\n+++ b/kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py\n@@ -29,15 +29,17 @@\n environ['KIVY_MODULES_DIR'] = join(root, 'modules')\n environ['KIVY_EMBED'] = '1'\n \n+\n # Monkey-patch pygame to get around an issue with Pygame window icon and\n # PyInstaller 2.1. See kivy issue #1638\n-# Uncomment the following to package pygame\n-#import pygame.pkgdata\n-#_original_getResource = pygame.pkgdata.getResource\n-#\n-#\n-#def getResource(identifier, *args, **kwargs):\n-#    if identifier == 'pygame_icon.tiff':\n-#        raise IOError()\n-#    return _original_getResource(identifier, *args, **kwargs)\n-#pygame.pkgdata.getResource = getResource\n+def getResource(identifier, *args, **kwargs):\n+    if identifier == 'pygame_icon.tiff':\n+        raise IOError()\n+    return _original_getResource(identifier, *args, **kwargs)\n+\n+try:\n+    import pygame.pkgdata\n+    _original_getResource = pygame.pkgdata.getResource\n+    pygame.pkgdata.getResource = getResource\n+except ImportError:\n+    pass\n", "issue": "Can't create package for windows with kivy 1.9 portable\nI'm looking to port an existing kivy 1.8 project to kivy 1.9. I've just downloaded the portable version and have the application working.\n\nHowever when packaging the app using pyinstaller and the instructions on http://kivy.org/docs/guide/packaging-windows.html the app packages, but on execution immediately fails with error:\n\n```\nTraceback (most recent call last):\n  File \"<string>\", line 34, in <module>\nImportError: No module named pygame.pkgdata\n```\n\nI've tried using my old .spec file and generating a new one with exactly the same results.\n\nI'm a bit mystified where this is coming from as pygame isn't imported anywhere in my application and I thought it had been replaced with sdl2 in kivy 1.9. I'm also confused that the application works when run directly.\n\nAnyone come across this issue or can point me in the right direction?\n\n", "before_files": [{"content": "from os.path import join, dirname\nfrom os import environ, chdir, putenv\nimport sys\n\nroot = 'kivy_install'\nif hasattr(sys, '_MEIPASS'):\n    # PyInstaller >= 1.6\n    chdir(sys._MEIPASS)\n    root = join(sys._MEIPASS, root)\nelif '_MEIPASS2' in environ:\n    # PyInstaller < 1.6 (tested on 1.5 only)\n    chdir(environ['_MEIPASS2'])\n    root = join(environ['_MEIPASS2'], root)\nelse:\n    chdir(dirname(sys.argv[0]))\n    root = join(dirname(sys.argv[0]), root)\n\n\nsys.path += [join(root, '_libs')]\n\nif sys.platform == 'darwin':\n    sitepackages = join(root, '..', 'sitepackages')\n    sys.path += [sitepackages, join(sitepackages, 'gst-0.10')]\n    putenv('GST_REGISTRY_FORK', 'no')\n\nenviron['GST_PLUGIN_PATH'] = join(root, '..', 'gst-plugins')\nenviron['KIVY_DATA_DIR'] = join(root, 'data')\nenviron['KIVY_EXTS_DIR'] = join(root, 'extensions')\nenviron['KIVY_MODULES_DIR'] = join(root, 'modules')\nenviron['KIVY_EMBED'] = '1'\n\n# Monkey-patch pygame to get around an issue with Pygame window icon and\n# PyInstaller 2.1. See kivy issue #1638\n# Uncomment the following to package pygame\n#import pygame.pkgdata\n#_original_getResource = pygame.pkgdata.getResource\n#\n#\n#def getResource(identifier, *args, **kwargs):\n#    if identifier == 'pygame_icon.tiff':\n#        raise IOError()\n#    return _original_getResource(identifier, *args, **kwargs)\n#pygame.pkgdata.getResource = getResource\n", "path": "kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py"}]}