From: SourceForge.net <no...@so...> - 2009-03-01 09:38:29
|
Bugs item #2583160, was opened at 2009-02-10 07:50 Message generated for change (Comment added) made by bhy You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=2583160&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: python Group: None >Status: Closed Resolution: None Priority: 5 Private: No Submitted By: Gaetan Lehmann (gleh) Assigned to: Nobody/Anonymous (nobody) Summary: import code breaks loading of several modules in one binary Initial Comment: Previously, it was possible to link several modules in a single binary. The modules where loaded from the main init_Module() function. This is a very useful feature for huge libraries and build systems limited to a few binary produced (msvc for exampe). Now we can't do that in python 2.6, because of the code used to import the module in the shadow classes, which explicitly search for the module file with imp.find_module() which obviously doesn't exist in that case. if version_info >= (2,6,0): def swig_import_helper(): from os.path import dirname import imp try: fp, pathname, description = imp.find_module('_itkImagePython', [dirname(__file__)]) _mod = imp.load_module('_itkImagePython', fp, pathname, description) finally: if fp is not None: fp.close() return _mod _itkImagePython = swig_import_helper() del swig_import_helper else: import _itkImagePython If I understand correctly, this code has been introduced to fix the syntax error with older python and explicit relative import. The exec statement doesn't seem to be usable, so here is how it can be implemented to preserve the ability to link several modules in one: if version_info >= (2,6,0): def swig_import_helper(): from os.path import dirname import imp fp = None try: # search for the module fp, pathname, description = imp.find_module('_itkImagePython', [dirname(__file__)]) except ImportError: # not found - try to simply import it, in case it is already loaded import _itkImagePython return _itkImagePython if fp is not None: # module has been found - lets load it try: _mod = imp.load_module('_itkImagePython', fp, pathname, description) finally: fp.close() return _mod _itkImagePython = swig_import_helper() del swig_import_helper else: import _itkImagePython ---------------------------------------------------------------------- >Comment By: Haoyu Bai (bhy) Date: 2009-03-01 17:38 Message: Thanks, this is fixed in SVN commit 11141. ---------------------------------------------------------------------- Comment By: Ken Lauer (sirkne) Date: 2009-02-24 04:09 Message: The current code also breaks py2exe support for SWIG on Python 2.6: File "mylibrary\mylibrary.pyc", line 20, in swig_import_helper: UnboundLocalError: local variable 'fp' referenced before assignment As it fails with an ImportError. The standard "import _mylibrary" works. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=2583160&group_id=1645 |