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

[Bug]: Plugins stopped working on Linux with Python 3.12 and system hunspell [solution found] #741

Closed
mihailim opened this issue Feb 28, 2024 · 0 comments · Fixed by #742
Labels

Comments

@mihailim
Copy link
Contributor

mihailim commented Feb 28, 2024

Bug Description

On Linux, when using Python 3.12 as the Sigil Python interpreter (24.04 changed to 3.12 as the default recently) while using the system hunspell, all plugins stopped working with backtrace similar to the testplugin one posted below due to a backtrace in the hunspell plugin loader.

It's trivial to reproduce on Linux, just switch the interpreter to 3.12 then run the testplugin (or any other plugin, for that matter), since the affected pluginhunspell.py code path runs for all of them.

Turns out that this is happening because of a cdll object behavior change introduced in this commit as a response to this issue: In 3.12.0a4 or newer, a key lookup when treating cdll as a dict no longer raises an OSError, but instead raises an AttributeError.

This was very badly documented in the Python changelog as "bpo-34816: hasattr(ctypes.windll, 'nonexistant') now returns False instead of raising OSError." in the Windows (!!) section of the 3.12.0 alpha 4 release notes -- not even a clairvoyant would figure out it would impact Linux in this manner...

The fix is trivial, also catch AttributeError in addition to OSError in pluginhunspell.py. Backwards compatible PR submitted at #742 .

Platform (OS)

Linux

OS Version / Specifics

Ubuntu 24.04 daily

What version of Sigil are you using?

2.0.1

Any backtraces or crash reports

Traceback (most recent call last):
  File "/usr/lib/python3.12/ctypes/__init__.py", line 450, in __getattr__

    dll = self._dlltype(name)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ctypes/__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: /usr/lib/x86_64-linux-gnu/sigil/libhunspell.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/share/sigil/plugin_launchers/python/launcher.py", line 317, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/share/sigil/plugin_launchers/python/launcher.py", line 277, in main
    bc = BookContainer(rk)
         ^^^^^^^^^^^^^^^^^
  File "/usr/share/sigil/plugin_launchers/python/bookcontainer.py", line 42, in __init__
    self.hspell = HunspellChecker(wrapper.get_hunspell_path())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/sigil/plugin_launchers/python/pluginhunspell.py", line 49, in __init__
    self.hunspell = cdll[hunspell_dllpath]
                    ~~~~^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ctypes/__init__.py", line 457, in __getitem__
    return getattr(self, name)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ctypes/__init__.py", line 452, in __getattr__
    raise AttributeError(name)
AttributeError: 
/usr/lib/x86_64-linux-gnu/sigil/libhunspell.so
@mihailim mihailim added the bug label Feb 28, 2024
@mihailim mihailim changed the title [Bug]: Plugins stopped working on Linux with Python 3.12 [solution found] [Bug]: Plugins stopped working on Linux with Python 3.12 and system hunspell [solution found] Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant