prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.1k stars 717 forks source link

3.0.42 depends on `ctypes.pythonapi` that doesn't exist on PyPy3 #1831

Closed mgorny closed 5 months ago

mgorny commented 6 months ago

The new release started using ctypes.pythonapi that doesn't exist on PyPy3. As a result, it is no longer possible to import prompt_toolkit on PyPy3, e.g.:

___________________________________________ ERROR collecting tests/test_async_generator.py ____________________________________________
ImportError while importing test module '/tmp/portage/dev-python/prompt-toolkit-3.0.42/work/prompt_toolkit-3.0.42/tests/test_async_generator.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/pypy3.10/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
/usr/lib/pypy3.10/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/usr/lib/pypy3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
/usr/lib/pypy3.10/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
tests/test_async_generator.py:5: in <module>
    from prompt_toolkit.eventloop import generator_to_async_generator
src/prompt_toolkit/__init__.py:25: in <module>
    from .application import Application
src/prompt_toolkit/application/__init__.py:3: in <module>
    from .application import Application
src/prompt_toolkit/application/application.py:20: in <module>
    from ctypes import c_int, c_void_p, pythonapi
E   ImportError: cannot import name 'pythonapi' from 'ctypes' (/usr/lib/pypy3.10/ctypes/__init__.py)

It is impossible to use PyPy's API via ctypes, as it relies on header-level C preprocessor definitions, and therefore it is only usable within C extensions. See https://doc.pypy.org/en/latest/discussion/ctypes-implementation.html#discussion-and-limitations

jonathanslenders commented 6 months ago

Hi @mgorny,

Thanks for reporting the issue. This was broken in https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1822 I'm looking for a fix.

cc: @tornaria

jonathanslenders commented 6 months ago

Can you check whether this fix is working: https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1833 ?

jonathanslenders commented 5 months ago

Closing this. The fix was merged.

mgorny commented 5 months ago

Thanks again!