Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hook to ease integration with pyinstaller #193

Open
enlivn opened this issue Jul 23, 2024 · 2 comments
Open

Add a hook to ease integration with pyinstaller #193

enlivn opened this issue Jul 23, 2024 · 2 comments

Comments

@enlivn
Copy link
Contributor

enlivn commented Jul 23, 2024

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.

@hugovk
Copy link
Member

hugovk commented Jul 23, 2024

Perhaps add the example as a new page to the docs at https://humanize.readthedocs.io?

@enlivn
Copy link
Contributor Author

enlivn commented Jul 23, 2024

Perhaps add the example as a new page to the docs at https://humanize.readthedocs.io?

@hugovk sure, I can put up a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants