rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.44k stars 205 forks source link

ValueError: Invalid config value: spinner=... when bundling script with PyInstaller #280

Open mmatous opened 1 week ago

mmatous commented 1 week ago

I encountered the same problem as described in #123 and applied the solution only to get a different error. I tried the CLI, specfile, and downgrade but the result is the same.

The error:

Traceback (most recent call last):
  File "ap.py", line 7, in <module>
    with alive_bar(n_tasks, spinner=spinner) as bar:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "alive_progress/core/progress.py", line 120, in alive_bar
ValueError: Invalid config value: spinner=<function spinner_controller.<locals>.inner_controller.<locals>.spinner_compiler_dispatcher_factory at 0x7f73bc554cc0>
Expected a custom factory or one of: ('classic', 'stars', 'twirl', 'twirls', 'horizontal', 'vertical', 'waves', 'waves2', 'waves3', 'dots', 'dots_waves', 'dots_waves2', 'it', 'ball_belt', 'balls_belt', 'triangles', 'brackets', 'bubbles', 'circles', 'squares', 'flowers', 'elements', 'loving', 'notes', 'notes2', 'arrow', 'arrows', 'arrows2', 'arrows_in', 'arrows_out', 'radioactive', 'boat', 'fish', 'fish2', 'fishes', 'crab', 'alive', 'wait', 'wait2', 'wait3', 'wait4', 'pulse')
[PYI-58196:ERROR] Failed to execute script 'ap' due to unhandled exception!

Example ap.py:

from alive_progress import alive_bar
from alive_progress.animations.spinners import bouncing_spinner_factory
import time

spinner = bouncing_spinner_factory(('A', 'B'), length=1)
n_tasks = 5
with alive_bar(n_tasks, spinner=spinner) as bar:
    for i in range(n_tasks):
        time.sleep(1)
        bar()

SW: Gentoo Linux Python 3.12.6 PyInstaller 6.10.0 alive-progress 3.1.5 (tried 1.6.2)

rsalmei commented 6 days ago

Humm, I think it is the way I validate the spinner function: https://github.com/rsalmei/alive-progress/blob/aa73aa78ae467139828512969b296b788f44975d/alive_progress/core/configuration.py#L49-L51

I'm not sure what this pyinstaller makes with the Python source files, but I'm sure this second condition, which ensures the function came from one of my sources, failed.

Can you debug it? Just put in your file something like this, between spinner = and with alive_bar(:

    from ..animations import spinner_compiler
    print(spinner_compiler.__file__)
    print(spinner.__code__.co_name)
    print(spinner.__code__.co_filename)
mmatous commented 6 days ago

plain script:

/home/mmatous/playground/aptest/venv/lib/python3.12/site-packages/alive_progress/animations/spinner_compiler.py spinner_compiler_dispatcher_factory /home/mmatous/playground/aptest/venv/lib/python3.12/site-packages/alive_progress/animations/spinner_compiler.py

bundled version:

/tmp/_MEIVE8Zos/alive_progress/animations/spinner_compiler.pyc spinner_compiler_dispatcher_factory alive_progress/animations/spinner_compiler.py

Getting rid of the second condition in ap's venv sources before bundling works. I'm OK with that workaround. Feel free to close the issue if you don't want to come up with a more permanent fix in AP.