Giovanni Bajo wrote:
> On mar, 2008-12-30 at 18:47 +0100, Lorenzo Mancini wrote:
>> Giovanni Bajo wrote:
>>> 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 .
>
> Uhm... thinking of it, I don't recall right now *why* a hook module
> shouldn't import the third party module it is handling. I do remember
> that it was important for some reason (otherwise, hook-xml.py that is
> there since day #1 wouldn't go through the hoops instead of simply
> importing it), but I can't recall why.
I don't have an answer either, but maybe part of the reason could be
that an imported third party module is given a chance to mess with
imported core packages (sys comes to mind), upon which mf relies.
Because that trick was first used for hook-xml.py, I thought that
following the import process of that package would give away clues about
why a direct import couldn't work in the hook; in
/usr/lib/python2.5/xml/__init__.py sys.modules is indeed modified, but
I'm not sure that's enough to screw PyInstaller analysis process if that
import happens in a hook.
> In doubt, I would prefer if you change this warning into an internal
> error, raising an exception like ImportError.
Note that ImportError is caught in the nearby except clause. Moreover,
it came to my mind that my previous check would trigger even for local
variables in the hook that happened to have the same name of the target
module. See dont-import-hook-target-module.patch for another take on
the problem.
I committed the other three patches.
--
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: mf.py
===================================================================
--- mf.py (revision 586)
+++ 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,10 @@
hookmodnm = 'hook-'+fqname
hooks = __import__('hooks', globals(), locals(), [hookmodnm])
hook = getattr(hooks, hookmodnm)
- #print `hook`
+
+ if fqname in dir(hook) and getattr(hook, fqname).__class__.__name__ == 'module':
+ raise RuntimeError, "hook %s imported its target module %s - work around that with hookutils.exec_statement" % (hookmodnm, fqname)
+
except (ImportError, AttributeError):
pass
else: