humanize icon indicating copy to clipboard operation
humanize copied to clipboard

Add a hook to ease integration with pyinstaller

Open enlivn opened this issue 7 months ago • 2 comments

What did you do?

A developer that wishes to use this library with pyinstaller must explicitly tell pyinstaller to retain the translation files for the library. One way to do this if you're using pyinstaller spec files is:

import os
from PyInstaller.utils.hooks import collect_all

spec_parent_directory = f"{os.path.abspath(SPECPATH)}/.."

main_app_datas = []
main_app_binaries = []
main_app_hiddenimports = []
tmp_ret = collect_all('humanize')
main_app_datas += tmp_ret[0]
main_app_binaries += tmp_ret[1]
main_app_hiddenimports += tmp_ret[2]

main_app_analysis = Analysis(
    [f'{spec_parent_directory}/app_entry_point.py'],
    pathex=[f'{spec_parent_directory}'],
    binaries=main_app_binaries,
    datas=main_app_datas,
    hiddenimports=main_app_hiddenimports
)

To reduce this overhead, pyinstaller allows packages to provide a hook that pyinstaller can then leverage.

Here is the documentation on pyinstaller hooks. Here is a sample library that shows how to add a custom hook.

We could either update this library to provide a hook or perhaps update the README (or some other markdown file) to provide the code snippet above that any dev that encounters this in the future can use.

enlivn avatar Jul 23 '24 17:07 enlivn