> The doc especially needs help from anyone who has actual
> experience with:
> * writing a run-time hook
This is related to section 'Changing Runtime Behavior' with the option
--runtime-hook= path/to/somescript.py
Some notes:
- 'support/rthooks.dat' is now './PyInstaller/
- option --runtime-hook= path/to/somescript.py
- code specified with this option will be executed before any run-time
hooks from pyinstaller.
- it can be used multiple times
- this option is order dependend. If you specify this option multiple
times:
--runtime-hook=file1.py --runtime-hook-file2.py
then the execution order of the app at run-time will be:
1. code from file1.py
2. code from file2.py
3. code from pyinstaller run-time hooks.
4. code from your main script.
- one reason why to write a run-time hook is that you will need to
override some functions or variables from some modules. A good example
of this is the django runtime
hook ./PyInstaller/loader/rthooks/pyi_rth_django.py:
- django is importing some modules dynamically and it is looking
for .py some files.
- However, with the .exe file .py files are not available
- in this case we need to override the function
django.core.management.find_commands that will just return a list of
values:
import django.core.management
def _find_commands(_):
return """cleanup shell runfcgi runserver""".split()
django.core.management.find_commands = _find_commands
How to write a new run-time hook that can be included with pyinstaller:
- runtime hooks are just ordinary python files with some code
- pyinstaller includes some run-time hooks for some modules in
./PyInstaller/loader/rthooks/
-
- you could use these files as examples.
- How a new run-time hook should look like:
1. create file with name like pyi_rth_MYNAME.py
2. add there some code and put it to ./PyInstaller/loader/rthooks/
3. add to ./PyInstaller/loader/rthooks.dat line like
'module_name': ['pyi_rth_MYNAME.py', 'pyi_rth_MYNAME2.py']
- This line tells pyinstaller:
- when module 'module_name' is found as a dependency, bundle
'pyi_rth_MYNAME.py' and 'pyi_rth_MYNAME2.py' with your app.
--
You received this message because you are subscribed to the Google Groups
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyinstaller?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.