wojtryb / Shortcut-Composer

Krita plugin for creating complex keyboard shortcuts
GNU General Public License v3.0
261 stars 9 forks source link

EnumGroup crashes in Python 3.11+ due to change in _EnumDict implementation #67

Closed hrstwn closed 10 months ago

hrstwn commented 10 months ago

General info

Bug description I can't activate any shortcuts, the settings also greyed out in the Plugin Settings. image

I haven't tried the development branch.

wojtryb commented 10 months ago

When the plugin is grayed out it means it crashed while loading. You need to hover over its name to get the error message. It's needed to make any fixes.

It does work on krita 5.2.0 on Ubuntu 20.04. Are you using krita .appimage? Other krita versions can have different dependencies which tend not to work.

hrstwn commented 10 months ago

I'm using Flatpak via Flathub. Other plug-ins seem to work fine. I've tried falling back to Krita 5.1.5 and it worked fine there.

Maybe it's related to my settings? Here's the output of running it through Terminal:

krita.lib.pigment: Replacing color space factory "LABA" "L*a*b* (16-bit integer/channel, unmanaged)" with "LABA" "L*a*b*/Alpha (16-bit integer/channel)"
krita.lib.pigment: Replacing color space factory "RGBA" "RGB (8-bit integer/channel, unmanaged)" with "RGBA" "RGB/Alpha (8-bit integer/channel)"
krita.lib.pigment: Replacing color space factory "RGBA16" "RGB (16-bit integer/channel, unmanaged)" with "RGBA16" "RGB/Alpha (16-bit integer/channel)"
QObject::startTimer: Timers cannot have negative intervals
/app/lib/krita-python-libs/krita added to PYTHONPATH
krita.scripting: "Traceback (most recent call last):"
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/__init__.py\", line 17, in <module>"
krita.scripting: "    from .shortcut_composer import ShortcutComposer  # noqa"
krita.scripting: "    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/shortcut_composer.py\", line 8, in <module>"
krita.scripting: "    from api_krita import Krita, Extension  # type: ignore"
krita.scripting: "    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/api_krita/__init__.py\", line 16, in <module>"
krita.scripting: "    from .core_api import KritaInstance"
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/api_krita/core_api.py\", line 15, in <module>"
krita.scripting: "    from .wrappers import ("
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/api_krita/wrappers/__init__.py\", line 10, in <module>"
krita.scripting: "    from .tool_descriptor import ToolDescriptor"
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/api_krita/wrappers/tool_descriptor.py\", line 7, in <module>"
krita.scripting: "    from ..enums import Tool"
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/api_krita/enums/__init__.py\", line 7, in <module>"
krita.scripting: "    from .blending_mode import BlendingMode"
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/api_krita/enums/blending_mode.py\", line 8, in <module>"
krita.scripting: "    class BlendingMode(EnumGroup):"
krita.scripting: "  File \"/home/hrstwn/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/api_krita/enums/helpers/enum_group.py\", line 39, in __new__"
krita.scripting: "    attrs._member_names.remove(group_variable_name)"
krita.scripting: "    ^^^^^^^^^^^^^^^^^^^^^^^^^^"
krita.scripting: "AttributeError: 'dict' object has no attribute 'remove'"
krita.scripting: "Could not import shortcut_composer"
krita.scripting: Error loading plugin "shortcut_composer"
wojtryb commented 10 months ago

Appimage is the only installation method on linux supported by Krita Foundation. That is why I also only support this format.

There is a reasoning behind it - appimage comes with all dependencies in proper versions, while the developer does not have this control with other methods.

My assumption is that your system already have Python 3.12 which, it seems, changed the implementation of Enum. Krita 5.2.0 is shipped with Python 3.10. Krita from Flathub will be using your system Python instead of the one shipped with appimage.

If it is true - I am definitely going to fix that as it will become a problem when Krita moves to 3.12 in a few years - but it is not such an urgent issue.

5310 commented 10 months ago

On that note: My system (SteamOS 3.4) has Python 3.10.8 installed. I'm also getting this same error with the Flathub release of Krita since it updated to 5.2.0

Turns out the Python inside the Flatpak image is 3.11.5, different from the system one. I don't have any Python Flatpak runtimes installed, so some runtime this package depends on must have updated it. I've been trying figure out how to override it, but Flatpak is pretty complex :sweat_smile:

For the time being I've also just switched to the Appimage version as I really need the new audio syncing fixes for animation. If I find anything I'll post it under this issue, since I'd also really like to keep my packages automatically updated.

hrstwn commented 10 months ago

Appimage is the only installation method on linux supported by Krita Foundation. That is why I also only support this format.

Oof, I didn’t read the Readme. Sorry. In that case, I’ll just use Krita 5.1.5 as it already has all I need. Thanks for this awesome plug-in.

Python version on my machine is 3.10.12 I believe. And I also don’t understand software packaging so I’ll leave it be.

wojtryb commented 10 months ago

I will reopen the issue, as this is in fact an issue in the plugin.

The solution to create grouped enums is too hacky as it can change between Python versions. I am not sure I can find a clear solution, but I should support newer versions of Python eventually.

wojtryb commented 10 months ago

Hi, I made a proposed bugfix. You can download it here. It should fix this single issue, making it work on both versions of Python.

If you can confirm that it works, I will merge it to development branch.

5310 commented 10 months ago

New error that replaced the old Dict.remove one: "ValueError: mutable default <class 'PyQt5.QtCore.QPoint'> for field center is not allowed: use default_factory"

krita.scripting: "Traceback (most recent call last):"
krita.scripting: "  File \"/home/deck/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/__init__.py\", line 17, in <module>"
krita.scripting: "    from .shortcut_composer import ShortcutComposer  # noqa"
krita.scripting: "    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
krita.scripting: "  File \"/home/deck/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/shortcut_composer.py\", line 10, in <module>"
krita.scripting: "    from actions import create_actions"
krita.scripting: "  File \"/home/deck/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/actions.py\", line 12, in <module>"
krita.scripting: "    import templates"
krita.scripting: "  File \"/home/deck/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/templates/__init__.py\", line 25, in <module>"
krita.scripting: "    from .pie_menu import PieMenu"
krita.scripting: "  File \"/home/deck/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/templates/pie_menu.py\", line 13, in <module>"
krita.scripting: "    from .pie_menu_utils.pie_settings_impl import dispatch_pie_settings"
krita.scripting: "  File \"/home/deck/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/templates/pie_menu_utils/__init__.py\", line 8, in <module>"
krita.scripting: "    from .label_widget import LabelWidget"
krita.scripting: "  File \"/home/deck/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/templates/pie_menu_utils/label_widget.py\", line 13, in <module>"
krita.scripting: "    from .label import Label"
krita.scripting: "  File \"/home/deck/.var/app/org.kde.krita/data/krita/pykrita/shortcut_composer/templates/pie_menu_utils/label.py\", line 17, in <module>"
krita.scripting: "    @dataclass"
krita.scripting: "     ^^^^^^^^^"
krita.scripting: "  File \"/usr/lib/python3.11/dataclasses.py\", line 1230, in dataclass"
krita.scripting: "    return wrap(cls)"
krita.scripting: "           ^^^^^^^^^"
krita.scripting: "  File \"/usr/lib/python3.11/dataclasses.py\", line 1220, in wrap"
krita.scripting: "    return _process_class(cls, init, repr, eq, order, unsafe_hash,"
krita.scripting: "           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
krita.scripting: "  File \"/usr/lib/python3.11/dataclasses.py\", line 958, in _process_class"
krita.scripting: "    cls_fields.append(_get_field(cls, name, type, kw_only))"
krita.scripting: "                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
krita.scripting: "  File \"/usr/lib/python3.11/dataclasses.py\", line 815, in _get_field"
krita.scripting: "    raise ValueError(f'mutable default {type(f.default)} for field '"
krita.scripting: "ValueError: mutable default <class 'PyQt5.QtCore.QPoint'> for field center is not allowed: use default_factory"
krita.scripting: "Could not import shortcut_composer"
krita.scripting: Error loading plugin "shortcut_composer"
wojtryb commented 10 months ago

Ok, so it goes like this:

  1. I'm closing the issue, as the initial error is fixed and merged to development branch
  2. The new issue relates to too high version of Qt5 (which is notorious for breaking code like that). Luckily, it's trivial to fix, so you can check it out here.
  3. If you want to keep debugging it like that, we do so here on this closed issue. I don't create a new one, as your environment is simply not supported yet - you use random set of dependencies, not something you expect from usual krita install.
  4. I'm interested in fixing these because it prolongs the plugin lifetime - but keep in mind that we may run into something which will be not worth fixing yet - after all, you really should use the .appimage
5310 commented 10 months ago

Happy to report that the newest fix works as before!

Plugin loads without errors, and all my existing shortcuts are working on the flatpak again.

Thank you very much for not only making the plugin in the first place but also fixing it on non-standard configurations!