rich.pretty without ipython yields SyntaxError during source generation
See original GitHub issue$ python -m nuitka --version
1.2rc1
Commercial: None
Python: 3.9.14 (main, Sep 6 2022, 23:29:09)
Flavor: Unknown
Executable: /.../venv/bin/python
OS: Darwin
Arch: x86_64
For this issue, Nuitka was installed from source into a venv. Python 3.9 from Homebrew. Same issue is apparent on 1.1 installed using pip. Also observed on Windows and Linux.
rich==12.5.1
Nuitka’s antibloat module contains this optimization for rich.pretty
:
Unfortunately, rich.pretty
contains this block of code:
try: # pragma: no cover
ip = get_ipython() # type: ignore[name-defined]
from IPython.core.formatters import BaseFormatter
The effect of the optimization is to yield the line:
ip = raise NameError # type: ignore[name-defined]
Which in turns causes a SyntaxError
during processing.
Test script, t.py
:
from rich.pretty import Pretty
if __name__ == "__main__":
a = Pretty("hello")
Trimmed output of building:
$ python -m nuitka --standalone t.py
...
Nuitka-Inclusion:WARNING: Cannot follow import to module 'rich.pretty' because of 'SyntaxError'.
...
And, naturally, the resulting binary doesn’t work, yielding a complaint about the above syntactic problem.
$ ./t.dist/t
Traceback (most recent call last):
File "/.../t.dist/t.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "/.../t.dist/rich/pretty.py", line 1, in <module rich.pretty>
File "/.../venv/lib/python3.9/site-packages/rich/pretty.py", line 246
ip = get_ipython() # type: ignore[name-defined]
^
SyntaxError: invalid syntax
As a workaround, I can include the option --noinclude-IPython-mode=allow
so it does not optimize that line; there is no ipython in the venv and this is not an ipython interpreter, so the result is still a NameError
once that line is reached.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (8 by maintainers)
A fix is coming in 1.1.1, thanks for your report.
Thanks for your report, this is fixed on the factory branch, which is a development version under rapid development. You can try it out by going here: https://nuitka.net/doc/factory.html
Feedback if this is working is very welcome, just please do not share plans of doing it, but rather confirmations or denials of it working.
I intend to push 1.1.1 today if everything else goes fine.