From 5ba2bb4e2f71cbdb1fa459ae17c53e7f16036411 Mon Sep 17 00:00:00 2001 From: IceArmy Date: Sat, 11 Jun 2011 01:27:23 -0700 Subject: [PATCH] Implement cross platform way of finding the Qt4 plugins directory --- python/pyphantomjs/tools/build_binary.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/python/pyphantomjs/tools/build_binary.py b/python/pyphantomjs/tools/build_binary.py index cf847e27..9fee1d7d 100644 --- a/python/pyphantomjs/tools/build_binary.py +++ b/python/pyphantomjs/tools/build_binary.py @@ -24,8 +24,6 @@ import sys parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path = sys.path + [parent_dir] -from distutils.sysconfig import get_python_lib - from utils import version try: @@ -44,6 +42,23 @@ if sys.platform.startswith('win'): sleep(2) +def qt4_plugins_dir(): + from PyQt4.QtCore import QCoreApplication + app = QCoreApplication([]) + + qt4_plugin_dirs = map(unicode, app.libraryPaths()) + if not qt4_plugin_dirs: + return + for d in qt4_plugin_dirs: + if os.path.isdir(d): + return str(d) # must be 8-bit chars for one-file builds + return + +qt4_plugin_dir = qt4_plugins_dir() +if not qt4_plugin_dir: + sys.exit('Cannot find PyQt4 plugins directory') + + # modules to include includes = [ # to make sure images are supported; jpeg, gif, svg, etc. @@ -54,7 +69,7 @@ includes = [ # files/directories to include include_files = [ # to make sure images are supported; jpeg, gif, svg, etc. - (os.path.join(get_python_lib(), 'PyQt4/plugins/imageformats'), 'imageformats'), + (os.path.join(qt4_plugin_dir, 'imageformats'), 'imageformats'), (os.path.join(parent_dir, 'plugins'), 'plugins'), (os.path.join(parent_dir, '../examples' if os.path.exists('../examples') else '../../examples'), 'examples'), (os.path.join(parent_dir, '../LICENSE'), 'LICENSE.txt'),