Hello,

this patch adds a run-time import hook for PyOpenGL. Details are explained
in comments in the file, so can be read there.

This patch has been in my local tree for several months now with optimal
results. It's convoluted, but works.

Commited as r218.
-- 
Giovanni Bajo
Index: rthooks.dat
===================================================================
--- rthooks.dat (revision 217)
+++ rthooks.dat (working copy)
@@ -2,4 +2,5 @@
     'pythoncom':  ['support/rthooks/versioneddll.py'],
     'pywintypes': ['support/rthooks/versioneddll.py'],
     'win32com':   ['support/rthooks/win32comgenpy.py'],
+    'OpenGL':     ['support/rthooks/opengl.py'],
 }
Index: doc/CHANGES.txt
===================================================================
--- doc/CHANGES.txt     (revision 217)
+++ doc/CHANGES.txt     (working copy)
@@ -9,6 +9,7 @@
    the encodings are automatically found and included, so this problem should
    be gone forever.
  + Add import hook for GTK.
+ + Add import hook for PyOpenGL.
  + Add import hook for dnspython (tested with 1.3.4)
  + Add import hook for KInterbasDB  (courtesy of Eugene Prigorodov)
  + (Windows) Make single-file packages not depend on MSVCRT71.DLL anymore,
Index: support/rthooks/opengl.py
===================================================================
--- support/rthooks/opengl.py   (revision 0)
+++ support/rthooks/opengl.py   (revision 0)
@@ -0,0 +1,48 @@
+# Copyright (C) 2005, Giovanni Bajo
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# In addition to the permissions in the GNU General Public License, the
+# authors give you unlimited permission to link or embed the compiled
+# version of this file into combinations with other programs, and to
+# distribute those combinations without any restriction coming from the
+# use of this file. (The General Public License restrictions do apply in
+# other respects; for example, they cover modification of the file, and
+# distribution when not linked into a combine executable.)
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
+
+# PyOpenGL (specifically, OpenGL.__init__) reads a "version" text file
+# containing the version number to export it as OpenGL.__version__. When
+# packaging with PyInstaller, the 'version' file does not exist, and importing
+# PyOpenGL results in an IOError.
+# The (convoluted) solution is to override Python's builtin "open" with our
+# own function which detects when "version" is opened and returns some fake
+# content stream (through cStringIO).
+
+__realopen__ = open
+
+def myopen(fn, *args):
+    import os
+    lastdir = os.path.basename(os.path.dirname(fn))
+    if os.path.basename(fn) == "version" and os.path.splitext(lastdir)[1] == 
".pyz":
+        import cStringIO
+        # Restore original open, since we're almost done
+        __builtins__.__dict__["open"] = __realopen__
+        # Report a fake revision number. Anything would do since it's not
+        # used by the library, but it needs to be made of four numbers
+        # separated by dots.
+        return cStringIO.StringIO("0.0.0.0")
+    return __realopen__(fn, *args)
+
+__builtins__.__dict__["open"] = myopen

Property changes on: support\rthooks\opengl.py
___________________________________________________________________
Name: svn:eol-style
   + native

_______________________________________________
PyInstaller mailing list
[email protected]
http://lists.hpcf.upr.edu/mailman/listinfo/pyinstaller

Reply via email to