timofurrer / colorful

Terminal string styling done right, in Python :snake: :tada:
MIT License
525 stars 23 forks source link

Support freezing with PyInstaller #52

Closed simaoafonso-pwt closed 1 year ago

simaoafonso-pwt commented 1 year ago

Is your Feature Request related to a problem? Please describe. If you try to package an application that depends on colorful (for example in a transitive dependency, like prettyprinter), the PyInstaller process will succeed, but if fails at runtime because it cannot find the data files.

Describe the solution you'd like

This package should include metadata to include those files in the build process.

Additional context

There's upstream support for marking this data. Here's the upstream documentation about this:

https://pyinstaller.org/en/stable/hooks.html#providing-pyinstaller-hooks-with-your-package

https://github.com/pyinstaller/hooksample

fliiiix commented 1 year ago

Sounds like a pyinstaller issue to me because the data files are part of the package see https://github.com/timofurrer/colorful/blob/master/MANIFEST.in and https://github.com/timofurrer/colorful/blob/master/setup.py#L83

It is part of the source dist:

tar tf colorful-0.5.5.tar.gz 
colorful-0.5.5/
....
colorful-0.5.5/colorful/data/
colorful-0.5.5/colorful/data/colornames.json
colorful-0.5.5/colorful/data/rgb.txt
....

as it is part of the wheel

unzip -l dist/colorful-0.5.5-py2.py3-none-any.whl
Archive:  dist/colorful-0.5.5-py2.py3-none-any.whl
  Length      Date    Time    Name
---------  ---------- -----   ----
....
   694864  12-04-2022 10:44   colorful/data/colornames.json
    17394  12-04-2022 10:44   colorful/data/rgb.txt
....
---------                     -------
   763415                     14 files

So please make a good case why this is a bug in colorful and not a bug in pyinstaller otherwise i will close this.

simaoafonso-pwt commented 1 year ago

Yeah, that sounds like an issue to be open on PyInstaller.

I checked, and this was discussed before: https://github.com/pyinstaller/pyinstaller/issues/2065 It seems some packages are badly behaved and include gigantic amounts of data files, and this bloats the binaries everywhere.

Bottom line, I think using --collect-data colorful is enough to fix this, I'll double check.

simaoafonso-pwt commented 1 year ago

Bottom line, I think using --collect-data colorful is enough to fix this, I'll double check.

Almost. The extras are so-called "hidden" imports, since they are calculated at runtime.

To make sure you can release PyInstaller binaries with extras, use:

--collect-data "colorful" --hidden-import "prettyprinter.extras.dataclasses"

Add more hidden imports with other extras you require.


Sounds like this won't be changed upstream, do you want to add this to the docs somewhere, or this issue comment is enough?

fliiiix commented 1 year ago

i think this issue should be enough, but if it happens often i will consider to add it to the readme or something

thanks for figuring it out :tada: