Giovanni Bajo wrote:
> On lun, 2008-12-22 at 18:20 +0100, Lorenzo Mancini wrote:
>> Lorenzo Mancini wrote:
>>> I'm attaching a pyinstaller hook for PyOpenGL which builds and improves 
>>> on the one posted by Oscar a few days ago.  Namely:
>> ...and thinking a little more about it, it doesn't make really sense to 
>> RuntimeError when PyOpenGL version doesn't match; if it's a <=3.0.0b6 
>> PyOpenGL it's not going to work anyway, and if it's an older 2.x 
>> version, those used to work as-is under pyinstaller.
>>
>> I'm attaching the updated version.
> 
> The version check is useless as well: if you have an older version (eg:
> v2) those modules will not exist and this does not do any harm (except
> false positives among missing modules). 

Sounds reasonable.  I've removed the version check, see 
add-opengl-hook.patch .


> But you should never import a module within its hook, so this is a
> non-starter.

Could pyinstaller issue a warning if such a thing happens?  See 
print-warning-if-importing-hook-module.patch .


> If you look at hook-xml, you will see that it executes a
> subprocess to check the pyxml version: that's the way to do it.

I extracted that trick in a separate helper function exec_statement 
(extract-external-interpreter-spawning.patch), so that it can be used by 
other hooks.

Existing hook-sqlalchemy.py used to import sqlalchemy, so I rewrote it 
using exec_statement (use-exec_statement-for-sqlalchemy-hook.patch).


-- 
Lorenzo Mancini

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/PyInstaller?hl=en
-~----------~----~----~----~------~----~------~--~---

Index: hooks/hook-OpenGL.py
===================================================================
--- hooks/hook-OpenGL.py        (revision 0)
+++ hooks/hook-OpenGL.py        (revision 0)
@@ -0,0 +1,39 @@
+## Hook for PyOpenGL 3.x versions from 3.0.0b6 up. Previous versions have a
+## plugin system based on pkg_resources which is problematic to handle 
correctly
+## under pyinstaller; 2.x versions used to run fine without hooks, so this one
+## shouldn't hurt.
+
+import os
+import sys
+
+## PlatformPlugin performs a conditional import based on os.name and
+## sys.platform. pyinstaller misses this so let's add it ourselves...
+
+if os.name == 'nt':
+    hiddenimports = ['OpenGL.platform.win32']
+else:
+    if sys.platform == 'linux2':
+        hiddenimports = ['OpenGL.platform.glx']
+    elif sys.platform == 'darwin':
+        hiddenimports = ['OpenGL.platform.darwin']
+    else:
+        print 'ERROR: hook-OpenGL: Unrecognised combo (os.name: %s, 
sys.platform: %s)' % (os.name, sys.platform)
+
+
+## arrays modules are needed too
+
+hiddenimports += ['OpenGL.arrays.ctypesparameters',
+                  'OpenGL.arrays.numarrays',
+                  'OpenGL.arrays._numeric',
+                  'OpenGL.arrays._strings',
+                  'OpenGL.arrays.ctypespointers',
+                  'OpenGL.arrays.lists',
+                  'OpenGL.arrays.numbers',
+                  'OpenGL.arrays.numeric',
+                  'OpenGL.arrays.strings',
+                  'OpenGL.arrays.ctypesarrays',
+                  'OpenGL.arrays.nones',
+                  'OpenGL.arrays.numericnames',
+                  'OpenGL.arrays.numpymodule',
+                  'OpenGL.arrays.vbo',
+                  ]
Index: mf.py
===================================================================
--- mf.py       (revision 585)
+++ mf.py       (working copy)
@@ -78,7 +78,7 @@
 
     def _getsuffixes(self):
         return suffixes.get_suffixes(self.target_platform)
-        
+
     def getmod(self, nm, getsuffixes=None, loadco=marshal.loads):
         if getsuffixes is None:
             getsuffixes = self._getsuffixes
@@ -544,7 +544,8 @@
                 hookmodnm = 'hook-'+fqname
                 hooks = __import__('hooks', globals(), locals(), [hookmodnm])
                 hook = getattr(hooks, hookmodnm)
-                #print `hook`
+                if fqname in dir(hook):
+                    print "W: importing module", fqname, "from", hookmodnm
             except (ImportError, AttributeError):
                 pass
             else:
Index: hooks/hookutils.py
===================================================================
--- hooks/hookutils.py  (revision 0)
+++ hooks/hookutils.py  (revision 0)
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+def exec_statement(stat):
+    """Executes a Python statement in an externally spawned interpreter, and
+    returns anything that was emitted in the standard output as a single 
string.
+    """
+
+    import os, tempfile, sys
+
+    fnm = tempfile.mktemp()
+    exe = sys.executable
+
+    # Using "echo on" as a workaround for a bug in NT4 shell
+    if os.name == "nt":
+        cmd = '"echo on && "%s" -c "%s" > "%s""' % (exe, stat, fnm)
+    else:
+        cmd = '"%s" -c "%s" > "%s"' % (exe, stat, fnm)
+    os.system(cmd)
+
+    txt = open(fnm, 'r').read()[:-1]
+    os.remove(fnm)
+    return txt
Index: hooks/hook-xml.py
===================================================================
--- hooks/hook-xml.py   (revision 585)
+++ hooks/hook-xml.py   (working copy)
@@ -20,20 +20,12 @@
 def hook(mod):
     # This hook checks for the infamous _xmlcore hack
     # http://www.amk.ca/diary/2003/03/pythons__xmlplus_hack.html
-    import os, tempfile, sys, string, marshal
-    fnm = tempfile.mktemp()
 
-    exe = sys.executable
+    from hookutils import exec_statement
+    import string, marshal
 
-    # Using "echo on" as a workaround for a bug in NT4 shell
-    if os.name == "nt":
-        cmd = '"echo on && "%s" -c "import xml;print xml.__file__" > "%s""' % 
(exe, fnm)
-    else:
-        cmd = '"%s" -c "import xml;print xml.__file__" > "%s"' % (exe, fnm)
-    os.system(cmd)
+    txt = exec_statement("import xml;print xml.__file__")
 
-    txt = open(fnm, 'r').read()[:-1]
-    os.remove(fnm)
     if string.find(txt, '_xmlplus') > -1:
         if txt[:-3] == ".py":
             txt = txt + 'c'
Index: hooks/hook-sqlalchemy.py
===================================================================
--- hooks/hook-sqlalchemy.py    (revision 585)
+++ hooks/hook-sqlalchemy.py    (working copy)
@@ -16,8 +16,11 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
 # Contributed by Greg Copeland
-import sqlalchemy.databases
+
+from hookutils import exec_statement
+databases = exec_statement("import sqlalchemy.databases;print 
sqlalchemy.databases.__all__")
+databases = eval(databases)
+
 hiddenimports = []
-
-for n in sqlalchemy.databases.__all__:
+for n in databases:
     hiddenimports.append("sqlalchemy.databases." + n)

Reply via email to