hyprland-community / pyprland

Scratchpads & many goodies for Hyprland [maintainer=@fdev31]
MIT License
345 stars 15 forks source link

[BUG] `coroutine` object does not support the asynchronous context manager protocol #111

Closed shinobiultra closed 3 months ago

shinobiultra commented 3 months ago

Pyprland version 2.3.7-2

Describe the bug After recent update, upon running pypr toggle <target>, I get error saying "coroutine object does not support the asynchronous context manager protocol" instead of the target window appearing. For terminal, it doesn't work at all for example, for file manager, it still outputs the error but the file manager at least appears, but without the ability to then hide it again (instead, new one is spawned and I have to close them manually).

To Reproduce Steps to reproduce the behavior:

  1. run pypr toggle files (given the config below)
  2. See the error message appear in the upper right corner of the screen

Expected behavior It should spawn the window from the set direction on the screen and upon toggling it again, it should move the window away.

Configuration (provide following files/samples when relevant):

exec-once = pypr

dropterm

bind = SUPER, T, exec, pypr toggle term $dropterm = ^(kitty-dropterm)$ windowrule = float,$dropterm windowrule = workspace special silent,$dropterm windowrule = size 75% 60%,$dropterm

file explorer

bind = SUPER, F, exec, pypr toggle files

windowrule = float, ^(dolphin)$

windowrule = workspace special silent,^(dolphin)$

windowrule = size 75% 60%,^(dolphin)$

cava

bind = SUPER, C, exec, pypr toggle cava windowrule = float, ^(kitty-cava)$ windowrule = workspace special silent, ^(kitty-cava)$ windowrule = size 40% 45%, ^(kitty-cava)$

music

bind = SUPER, M, exec, pypr toggle music windowrule = float,^(rhythmbox)$ windowrule = workspace special,^(rhythmbox)$ windowrule = size 50% 50%,^(rhythmbox)$

volume

bind = SUPER, V, exec, pypr toggle volume windowrule = float,^(pavucontrol)$ windowrule = workspace special silent,^(pavucontrol)$ windowrule = size 25% 25%,^(pavucontrol)$

network manager

bind = SUPER, N, exec, pypr toggle network windowrule = float, ^(XDG_CURRENT_DESKTOP='gnome' gnome-control-center)$ windowrulev2 = workspace special silent, class:^(XDG_CURRENT_DESKTOP='gnome' gnome-control-center)$, title:^(Network Connections)$ windowrule = size 18% 40%,^(XDG_CURRENT_DESKTOP='gnome' gnome-control-center)$

bluetooth

bind = SUPER, B, exec, pypr toggle bluetooth windowrule = float, ^(blueman-manager) windowrule = workspace special silent, ^(blueman-manager)$ windowrule = size 18% 40%,^(blueman-manager)$

bind = SUPER, E, exec, pypr toggle_minimized bind = SUPER, Z, exec, pypr zoom



**Additional context**
`hyprland-git` version 0.40.0.r183.1423707d-1.
fdev31 commented 3 months ago

Can you please provide the pyprland logs too? And can you confirm/deny that the problem didn't happen using version 2.3.5 ?

shinobiultra commented 3 months ago

Can you please provide the pyprland logs too?

Here you go (I've tried running pypr toggle term and pypr toggle files):

2024-06-10 22:56:19,662 [INFO] ipc :: Logger "ipc" initialized :: common.py:205
2024-06-10 22:56:19,662 [INFO] startup :: Logger "startup" initialized :: common.py:205
2024-06-10 22:56:19,662 [DEBUG] ipc :: notify 3 10000 rgb(ff1010)  Trying to run pypr more than once ? :: ipc.py:144
2024-06-10 22:56:19,675 [CRITICAL] startup :: /run/user/1000/hypr/811429bfd4a46f33c7788580f72038b0c3c1c2b1_1718052860_1875784680/.pyprland.sock exists,
is pypr already running ?
If that's not the case, delete this file and run again. :: command.py:476
2024-06-10 22:56:43,121 [INFO] ipc :: Logger "ipc" initialized :: common.py:205
2024-06-10 22:56:43,121 [INFO] startup :: Logger "startup" initialized :: common.py:205
2024-06-10 22:56:43,122 [DEBUG] ipc :: notify 3 10000 rgb(ff1010)  Trying to run pypr more than once ? :: ipc.py:144
2024-06-10 22:56:43,125 [CRITICAL] startup :: /run/user/1000/hypr/811429bfd4a46f33c7788580f72038b0c3c1c2b1_1718052860_1875784680/.pyprland.sock exists,
is pypr already running ?
If that's not the case, delete this file and run again. :: command.py:476
2024-06-10 22:56:49,724 [INFO] ipc :: Logger "ipc" initialized :: common.py:205
2024-06-10 22:56:49,724 [INFO] startup :: Logger "startup" initialized :: common.py:205
2024-06-10 22:56:49,725 [DEBUG] ipc :: notify 3 10000 rgb(ff1010)  Trying to run pypr more than once ? :: ipc.py:144
2024-06-10 22:56:49,754 [CRITICAL] startup :: /run/user/1000/hypr/811429bfd4a46f33c7788580f72038b0c3c1c2b1_1718052860_1875784680/.pyprland.sock exists,
is pypr already running ?
If that's not the case, delete this file and run again. :: command.py:476
2024-06-10 22:57:07,211 [INFO] ipc :: Logger "ipc" initialized :: common.py:205
2024-06-10 22:57:07,211 [INFO] startup :: Logger "startup" initialized :: common.py:205
2024-06-10 22:57:07,211 [INFO] pypr :: Logger "pypr" initialized :: common.py:205
2024-06-10 22:57:07,211 [INFO] pypr :: Loading ~/.config/hypr/pyprland.json :: command.py:97
2024-06-10 22:57:07,211 [INFO] pyprland :: Logger "pyprland" initialized :: common.py:205
2024-06-10 22:57:07,211 [DEBUG] pyprland :: version :: ipc.py:101
2024-06-10 22:57:07,214 [DEBUG] pyprland :: activeworkspace :: ipc.py:101
2024-06-10 22:57:07,214 [DEBUG] pyprland :: monitors :: ipc.py:101
2024-06-10 22:57:07,214 [INFO] pyprland :: configured :: command.py:154
2024-06-10 22:57:07,219 [INFO] scratchpads :: Logger "scratchpads" initialized :: common.py:205
2024-06-10 22:57:07,219 [INFO] scratchpads :: configured :: command.py:154
2024-06-10 22:57:07,219 [INFO] expose :: Logger "expose" initialized :: common.py:205
2024-06-10 22:57:07,219 [INFO] expose :: configured :: command.py:154
2024-06-10 22:57:07,220 [INFO] magnify :: Logger "magnify" initialized :: common.py:205
2024-06-10 22:57:07,220 [INFO] magnify :: configured :: command.py:154
2024-06-10 22:57:07,220 [DEBUG] pypr :: ================================[ initialized ]================================= :: command.py:355
2024-06-10 22:57:09,266 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:09,266 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:09,266 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:09,266 [DEBUG] scratchpads :: event_openwindow('5dca850b1460,2,kitty,kitty',) :: command.py:177
2024-06-10 22:57:09,293 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:09,293 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:09,293 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:09,451 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:09,451 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:09,451 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:09,451 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:09,451 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:09,451 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:17,980 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:17,980 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:17,981 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:18,011 [DEBUG] scratchpads :: run_toggle('term',) :: command.py:177
2024-06-10 22:57:18,011 [DEBUG] scratchpads :: visibility_check: ('', '') == ('2', 'DP-2') :: __init__.py:421
2024-06-10 22:57:18,011 [DEBUG] scratchpads :: term visibility: False and False :: __init__.py:447
2024-06-10 22:57:18,011 [INFO] scratchpads :: Showing term :: __init__.py:524
2024-06-10 22:57:18,011 [INFO] scratchpads :: term is not running, starting... :: __init__.py:232
2024-06-10 22:57:18,012 [INFO] scratchpads :: scratch term (kitty --class kitty-dropterm) has pid 23461 :: __init__.py:253
2024-06-10 22:57:18,012 [INFO] scratchpads :: starting term :: __init__.py:207
2024-06-10 22:57:18,012 [INFO] scratchpads :: ==> Wait for term spawning :: __init__.py:161
2024-06-10 22:57:18,026 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:18,026 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:18,044 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:18,044 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:18,114 [ERROR] pypr :: scratchpads::run_toggle(('term',)) failed: :: command.py:188
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/pyprland/command.py", line 183, in _run_plugin_handler
    await getattr(plugin, full_name)(*params)
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 452, in run_toggle
    await asyncio.gather(*(asyncio.create_task(t()) for t in tasks))
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 526, in run_show
    if not await self.ensure_alive(uid):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 233, in ensure_alive
    if not await self._start_scratch(item):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 208, in _start_scratch
    if not await self.__wait_for_client(scratch):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 165, in __wait_for_client
    is_alive = await scratch.is_alive()
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/objects.py", line 96, in is_alive
    async with aiopen(os.path.join(path, "status"), mode="r", encoding="utf-8") as f:
TypeError: 'coroutine' object does not support the asynchronous context manager protocol
2024-06-10 22:57:18,115 [DEBUG] ipc :: notify 0 5000 rgb(ff1010)  Pypr error scratchpads::run_toggle: 'coroutine' object does not support the asynchronous context manager protocol :: ipc.py:144
2024-06-10 22:57:18,115 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:18,115 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:18,140 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:18,140 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:18,140 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:18,140 [DEBUG] scratchpads :: event_openwindow('5dca84f68b00,special silent,kitty-dropterm,kitty',) :: command.py:177
2024-06-10 22:57:18,140 [INFO] scratchpads :: Updating Scratch info :: __init__.py:370
2024-06-10 22:57:18,140 [DEBUG] scratchpads :: clients :: ipc.py:101
2024-06-10 22:57:21,775 [DEBUG] pyprland :: event_activewindowv2('5dca83f19c10',) :: command.py:177
2024-06-10 22:57:21,775 [DEBUG] pyprland :: active_window = 0x5dca83f19c10 :: pyprland.py:76
2024-06-10 22:57:21,775 [DEBUG] scratchpads :: event_activewindowv2('5dca83f19c10',) :: command.py:177
2024-06-10 22:57:27,369 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:27,369 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:27,369 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:29,332 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:29,332 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:29,333 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:29,375 [DEBUG] scratchpads :: run_toggle('files',) :: command.py:177
2024-06-10 22:57:29,375 [DEBUG] scratchpads :: visibility_check: ('', '') == ('2', 'DP-2') :: __init__.py:421
2024-06-10 22:57:29,375 [DEBUG] scratchpads :: files visibility: False and False :: __init__.py:447
2024-06-10 22:57:29,375 [INFO] scratchpads :: Showing files :: __init__.py:524
2024-06-10 22:57:29,375 [INFO] scratchpads :: files is not running, starting... :: __init__.py:232
2024-06-10 22:57:29,376 [INFO] scratchpads :: scratch files (nemo) has pid 23700 :: __init__.py:253
2024-06-10 22:57:29,376 [INFO] scratchpads :: starting files :: __init__.py:207
2024-06-10 22:57:29,376 [INFO] scratchpads :: ==> Wait for files spawning :: __init__.py:161
2024-06-10 22:57:29,389 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:29,389 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:29,393 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:29,393 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:29,477 [ERROR] pypr :: scratchpads::run_toggle(('files',)) failed: :: command.py:188
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/pyprland/command.py", line 183, in _run_plugin_handler
    await getattr(plugin, full_name)(*params)
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 452, in run_toggle
    await asyncio.gather(*(asyncio.create_task(t()) for t in tasks))
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 526, in run_show
    if not await self.ensure_alive(uid):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 233, in ensure_alive
    if not await self._start_scratch(item):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 208, in _start_scratch
    if not await self.__wait_for_client(scratch):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 165, in __wait_for_client
    is_alive = await scratch.is_alive()
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/objects.py", line 96, in is_alive
    async with aiopen(os.path.join(path, "status"), mode="r", encoding="utf-8") as f:
TypeError: 'coroutine' object does not support the asynchronous context manager protocol
2024-06-10 22:57:29,477 [DEBUG] ipc :: notify 0 5000 rgb(ff1010)  Pypr error scratchpads::run_toggle: 'coroutine' object does not support the asynchronous context manager protocol :: ipc.py:144
2024-06-10 22:57:29,478 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:29,478 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:29,562 [DEBUG] pyprland :: event_activewindowv2('5dca84f77a50',) :: command.py:177
2024-06-10 22:57:29,562 [DEBUG] pyprland :: active_window = 0x5dca84f77a50 :: pyprland.py:76
2024-06-10 22:57:29,562 [DEBUG] scratchpads :: event_activewindowv2('5dca84f77a50',) :: command.py:177
2024-06-10 22:57:29,562 [DEBUG] scratchpads :: event_openwindow('5dca84f77a50,2,nemo,Home',) :: command.py:177
2024-06-10 22:57:29,562 [INFO] scratchpads :: Updating Scratch info :: __init__.py:370
2024-06-10 22:57:29,562 [DEBUG] scratchpads :: clients :: ipc.py:101
2024-06-10 22:57:30,359 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:30,359 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:30,359 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:30,489 [DEBUG] pyprland :: event_activewindowv2('5dca84f77a50',) :: command.py:177
2024-06-10 22:57:30,489 [DEBUG] pyprland :: active_window = 0x5dca84f77a50 :: pyprland.py:76
2024-06-10 22:57:30,489 [DEBUG] scratchpads :: event_activewindowv2('5dca84f77a50',) :: command.py:177
2024-06-10 22:57:31,835 [DEBUG] scratchpads :: event_closewindow('5dca84f77a50',) :: command.py:177
2024-06-10 22:57:31,836 [DEBUG] pyprland :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:31,836 [DEBUG] pyprland :: active_window = 0x5dca850b1460 :: pyprland.py:76
2024-06-10 22:57:31,836 [DEBUG] scratchpads :: event_activewindowv2('5dca850b1460',) :: command.py:177
2024-06-10 22:57:33,802 [DEBUG] pyprland :: event_activewindowv2('5dca83f19c10',) :: command.py:177
2024-06-10 22:57:33,803 [DEBUG] pyprland :: active_window = 0x5dca83f19c10 :: pyprland.py:76
2024-06-10 22:57:33,803 [DEBUG] scratchpads :: event_activewindowv2('5dca83f19c10',) :: command.py:177
2024-06-10 22:57:34,256 [CRITICAL] pypr :: cancelled :: command.py:362

And can you confirm/deny that the problem didn't happen using version 2.3.5 ?

Not really much time rich atm :/

ikkihou commented 3 months ago

same situation as me

fdev31 commented 3 months ago

Ok, I'll try to figure what's wrong, but I suspect some compatibility I added recently to be involved... Do you have "aiofiles" python package installed?

shinobiultra commented 3 months ago

Ok, I'll try to figure what's wrong, but I suspect some compatibility I added recently to be involved... Do you have "aiofiles" python package installed?

Yes, I have python-aiofiles 23.2.1-2 package installed. I also have Python version python 3.12.3-1.

fdev31 commented 3 months ago

Sorry guys, I had made a big mistake previously & for some reason didn't see the tests failing.

Do one of you have a chance to test the git version & confirm this problem is gone?

shinobiultra commented 3 months ago

Sorry guys, I had made a big mistake previously & for some reason didn't see the tests failing.

Do one of you have a chance to test the git version & confirm this problem is gone?

IT WORKS NOW! Nice, thanks a lot:-) What was the issue (I'll read the commits if it's too lengthy, it's just I'm unfamiliar with pyprland's codebase so any clarification would help my curiosity :D)

fdev31 commented 3 months ago

Sorry guys, I had made a big mistake previously & for some reason didn't see the tests failing. Do one of you have a chance to test the git version & confirm this problem is gone?

IT WORKS NOW! Nice, thanks a lot:-) What was the issue (I'll read the commits if it's too lengthy, it's just I'm unfamiliar with pyprland's codebase so any clarification would help my curiosity :D)

This wasn't really "pyprland" architecture related but my own "rushed some code before traveling":

=> I made it quite broken, and while rushing I didn't even pay attention to the tests which were breaking....

ikkihou commented 3 months ago

Sorry guys, I had made a big mistake previously & for some reason didn't see the tests failing.

Do one of you have a chance to test the git version & confirm this problem is gone?

its ok now, thanks for you work!

shinobiultra commented 3 months ago

Sorry guys, I had made a big mistake previously & for some reason didn't see the tests failing. Do one of you have a chance to test the git version & confirm this problem is gone?

IT WORKS NOW! Nice, thanks a lot:-) What was the issue (I'll read the commits if it's too lengthy, it's just I'm unfamiliar with pyprland's codebase so any clarification would help my curiosity :D)

This wasn't really "pyprland" architecture related but my own "rushed some code before traveling":

* I wanted to make aiofiles dependency optional, by "mocking" async methods to sync ones in case aiofiles isn't available (mostly for the `get-pypr` use case)

=> I made it quite broken, and while rushing I didn't even pay attention to the tests which were breaking....

Happens to the best of us. Thanks for quick fixing and responses:-) Cheers