4 This installs a hook into setuptools' pkg_resources infrastructure, so that resource
5 files can be found in files relative to the runnin executable, in addition to the
6 usual egg and source lookup mechanisms. This overrides the ZipProvider, since that
7 is the lookup mechanism triggered within pkg_resources when running code out of a
8 py2exe or py2app build's library.zip.
11 import pkg_resources, zipimport
14 'darwin': '../Resources/pkg_resources',
16 exedir = os.path.dirname(sys.executable)
17 libdir = platform_libdirs.get(sys.platform, 'pkg_resources')
19 class Provider(pkg_resources.ZipProvider):
21 def __init__(self, module):
22 self._module_name = module.__name__
23 pkg_resources.ZipProvider.__init__(self, module)
25 def get_resource_filename(self, manager, resource_name):
26 #print 'get_resource_filename(%s, %s)' % (manager, resource_name)
27 path = [exedir, libdir] + self._module_name.split('.') + [resource_name]
28 localfile = os.path.join(*path)
29 #print ' checking(%s)' % (localfile,)
30 if os.path.exists(localfile):
31 #print 'found locally'
35 ret = pkg_resources.ZipProvider.get_resource_filename(self, manager, resource_name)
36 #print 'returning %s' % (ret,)
38 except NotImplementedError:
39 #print 'get_resource_filename(%s,%s): not found' % (self._module_name, resource_name)
41 #traceback.print_exc()
44 pkg_resources.register_loader_type(zipimport.zipimporter, Provider)