Skip to content

Commit

Permalink
Merge pull request #3652 from matham/pyinstaller3
Browse files Browse the repository at this point in the history
Update pyinstaller hooks to use proper api. Fixes #3622.
  • Loading branch information
akshayaurora committed Sep 25, 2015
2 parents 75aa581 + 775c9b3 commit 9881188
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
32 changes: 20 additions & 12 deletions doc/sources/guide/packaging-windows.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ package of Kivy.
The package will be either 32 or 64 bits depending on which version of Python The package will be either 32 or 64 bits depending on which version of Python
you ran it with. you ran it with.


+-----------------------------------------------------------------------------+
| NOTE: Currently, packages for Windows can be generated with Python 2.7 and | .. note::
| Python 3.3+. However, Python 3.3+ support is still experimental | Currently, packages for Windows can be generated with Python 2.7 and
+-----------------------------------------------------------------------------+ Python 3.3+. However, Python 3.3+ support is still experimental, so check
this page for updates in case of issues.


.. _packaging-windows-requirements: .. _packaging-windows-requirements:


Expand Down Expand Up @@ -60,12 +61,20 @@ the main file is named `main.py`.
Open the spec file with your favorite editor and add theses lines at the Open the spec file with your favorite editor and add theses lines at the
beginning of the spec:: beginning of the spec::


from kivy.tools.packaging.pyinstaller_hooks import install_hooks from kivy.tools.packaging.pyinstaller_hooks import get_hooks
import os import os
install_hooks(globals())


In the `Analysis()` function, remove the `hookspath=None` parameter. In the `Analysis()` function, remove the `hookspath=None` parameter and
If you don't do this, the kivy package hook will not be used at all. the `runtime_hooks` parameter if present. `get_hooks` will return the required
values for both parameters, so at the end of `Analysis()` add `**get_hooks()`.
E.g.::

a = Analysis(['..\\kivy27\\examples\\demo\\touchtracer\\main.py'],
pathex=['g:\\Python\\dev2\\TouchApp'],
hiddenimports=[],
**get_hooks())

This will add the required hooks so that pyinstaller gets the required kivy files.


Then you need to change the `COLLECT()` call to add the data for touchtracer Then you need to change the `COLLECT()` call to add the data for touchtracer
(`touchtracer.kv`, `particle.png`, ...). Change the line to add a `Tree()` (`touchtracer.kv`, `particle.png`, ...). Change the line to add a `Tree()`
Expand Down Expand Up @@ -125,7 +134,7 @@ If you wish to use Gstreamer, you'll need to further modify the spec file.
correct gstreamer modules, you have to import core.video in the spec file correct gstreamer modules, you have to import core.video in the spec file
before doing anything:: before doing anything::


from kivy.tools.packaging.pyinstaller_hooks import install_hooks from kivy.tools.packaging.pyinstaller_hooks import get_hooks
import kivy.core.video import kivy.core.video


#. You'll need to include the gstreamer directory, found in the kivy distribution, #. You'll need to include the gstreamer directory, found in the kivy distribution,
Expand All @@ -151,13 +160,12 @@ From kivy-2.7.bat. Create the VideoPlayer directory alongside kivy-2.7.bat::
Now edit the spec file. At the top of the file add:: Now edit the spec file. At the top of the file add::


import os import os
from kivy.tools.packaging.pyinstaller_hooks import install_hooks from kivy.tools.packaging.pyinstaller_hooks import get_hooks
import kivy.core.video import kivy.core.video


install_hooks(globals())
gst_plugin_path = os.environ.get('GST_PLUGIN_PATH').split('lib')[0] gst_plugin_path = os.environ.get('GST_PLUGIN_PATH').split('lib')[0]


Remove the `hookspath=None` parameter, and change:: Add `get_hooks` to `Analysis()`, and change::


coll = COLLECT(exe, coll = COLLECT(exe,
a.binaries, a.binaries,
Expand Down
15 changes: 8 additions & 7 deletions kivy/tools/packaging/pyinstaller_hooks/__init__.py
Original file line number Original file line Diff line number Diff line change
@@ -1,14 +1,15 @@
from os.path import dirname, join from os.path import dirname, join
from functools import partial


curdir = dirname(__file__) curdir = dirname(__file__)




def install_hooks(sym, hookspath=None): def runtime_hooks():
return [join(curdir, 'rt-hook-kivy.py')]


_hookspath = [curdir]
if hookspath is not None:
_hookspath += hookspath


sym['rthooks']['kivy'] = [join(curdir, 'rt-hook-kivy.py')] def hookspath():
sym['Analysis'] = partial(sym['Analysis'], hookspath=_hookspath) return [curdir]


def get_hooks():
return {'hookspath': hookspath(), 'runtime_hooks': runtime_hooks()}
28 changes: 23 additions & 5 deletions kivy/tools/packaging/pyinstaller_hooks/hook-kivy.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,19 +11,37 @@
Check kivy documentation about how to use these hook for packaging application. Check kivy documentation about how to use these hook for packaging application.
''' '''


from os.path import join, basename
from distutils.version import LooseVersion
import PyInstaller

import kivy import kivy
from kivy.factory import Factory from kivy.factory import Factory


try:
pyinst_ver = PyInstaller.get_version() # pyinstaller < 3.0x
except AttributeError:
pyinst_ver = PyInstaller.__version__



def get_modules(): def get_modules():
return [x.get('module', None) for x in Factory.classes.values()] return [x.get('module', None) for x in Factory.classes.values()]




datas = [ if LooseVersion(pyinst_ver) >= LooseVersion('3.0'):
(kivy.kivy_data_dir, 'kivy_install'), # in pyinstaller 3, the directory contents rather than the directory itself
(kivy.kivy_modules_dir, 'kivy_install'), # is copied. See https://github.com/pyinstaller/pyinstaller/issues/1513.
(kivy.kivy_exts_dir, 'kivy_install'), datas = [
] (kivy.kivy_data_dir,
join('kivy_install', basename(kivy.kivy_data_dir))),
(kivy.kivy_modules_dir,
join('kivy_install', basename(kivy.kivy_modules_dir))),
]
else:
datas = [
(kivy.kivy_data_dir, 'kivy_install'),
(kivy.kivy_modules_dir, 'kivy_install'),
]


# extensions # extensions
_kivy_modules = [ _kivy_modules = [
Expand Down

0 comments on commit 9881188

Please sign in to comment.