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

Issue with pypr commands #22

Closed
XenoWad01 opened this issue Nov 10, 2023 · 22 comments
Closed

Issue with pypr commands #22

XenoWad01 opened this issue Nov 10, 2023 · 22 comments
Labels
invalid This doesn't seem right

Comments

@XenoWad01
Copy link

XenoWad01 commented Nov 10, 2023

First of all I want to say that I am sorry if I am missing something obvious here.

I have pypr installed from the lazy branch as was documented here:

          Thank you very much !

For anyone else wondering I used

pipx install git+https://github.com/hyprland-community/pyprland.git@onlylazy

To install it

Originally posted by @redsteadz in #19 (comment)

Here is my .config/hypr/hyprland.conf:


# -----------------------------------------------------
# Keyboard Layout
# -----------------------------------------------------
# $keyboardlayout=de
$keyboardlayout=us

# -----------------------------------------------------
# Monitor Setup
# See https://wiki.hyprland.org/Configuring/Monitors/
# -----------------------------------------------------
monitor=HDMI-A-1,1920x1080@60,0x0,1
monitor=eDP-1,1920x1080@60,1920x0,auto
# monitor=,2560x1440@120,auto,1
# monitor=,1920x1080,auto,1
#
# -----------------------------------------------------
# Autostart & Environment
# -----------------------------------------------------
source = ~/dotfiles/hypr/conf/environment.conf
source = ~/dotfiles/hypr/conf/autostart.conf

# -----------------------------------------------------
# Load pywal color file
# -----------------------------------------------------
source = ~/.cache/wal/colors-hyprland.conf

# -----------------------------------------------------
# Load configuration files
# -----------------------------------------------------
source = ~/dotfiles/hypr/conf/keyboard.conf
source = ~/dotfiles/hypr/conf/window.conf
source = ~/dotfiles/hypr/conf/decoration.conf
source = ~/dotfiles/hypr/conf/layouts.conf
source = ~/dotfiles/hypr/conf/misc.conf
source = ~/dotfiles/hypr/conf/keybindings.conf
source = ~/dotfiles/hypr/conf/windowrules.conf

# -----------------------------------------------------
# Animation
# -----------------------------------------------------
source = ~/dotfiles/hypr/conf/animations-low.conf
# source = ~/dotfiles/hypr/conf/animations-high.conf
#
#xwayland { use_nearest_neighbor = false }

exec-once = pypr
bind = SUPER,D,exec,pypr toggle discord
#windowrule = floa,^(discord)$
#windowrule = workspace special silent,^(discord)$

# <------- Here is the relevant part !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -------->
bind = SUPER,V,exec,pypr toggle volume
windowrule = float,^(pavucontrol)$
windowrule = workspace special silent,^(pavucontrol)$

here is my pyprland.json:

{
    "pyprland": {
        "plugins": [
            "scratchpads"
	]
    },
    "scratchpads": {
        "discord": {
            "command": "discord",
            "animation": "fromTop",
            "unfocus": "false"
        },
	"volume": {
	    "command": "pavucontrol",
	    "animation": "fromRight"
	}
    }
}

Through some debugging I noticed if i ran pypr inside the terminal discord and pavucontrol start up, but when i run pypr toggle volume in order to toggle pavucontrol I get an unhandled exception:

❯ pypr toggle volume
Unhandled exception:
Traceback (most recent call last):
  File "/home/anime_protagonist/.local/pipx/venvs/pyprland/lib/python3.11/site-packages/pyprland/command.py", line 242, in main
    asyncio.run(run_daemon() if len(sys.argv) <= 1 else run_client())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/anime_protagonist/.local/pipx/venvs/pyprland/lib/python3.11/site-packages/pyprland/command.py", line 220, in run_client
    _, writer = await asyncio.open_unix_connection(CONTROL)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/streams.py", line 98, in open_unix_connection
    transport, _ = await loop.create_unix_connection(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/unix_events.py", line 259, in create_unix_connection
    await self.sock_connect(sock, path)
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 642, in _sock_connect
    sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

The output for the show command is the same:

❯ pypr show volume
Unhandled exception:
Traceback (most recent call last):
  File "/home/anime_protagonist/.local/pipx/venvs/pyprland/lib/python3.11/site-packages/pyprland/command.py", line 242, in main
    asyncio.run(run_daemon() if len(sys.argv) <= 1 else run_client())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/anime_protagonist/.local/pipx/venvs/pyprland/lib/python3.11/site-packages/pyprland/command.py", line 220, in run_client
    _, writer = await asyncio.open_unix_connection(CONTROL)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/streams.py", line 98, in open_unix_connection
    transport, _ = await loop.create_unix_connection(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/unix_events.py", line 259, in create_unix_connection
    await self.sock_connect(sock, path)
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 642, in _sock_connect
    sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

Any pypr commands will have the same problem with discord or any other scratchpad.

I also installed it with pipx install pyprland before all of this and the behaviour was the same.

@nisby
Copy link

nisby commented Nov 11, 2023

same here with AUR package

@fdev31
Copy link
Collaborator

fdev31 commented Nov 11, 2023

Two remarks here:

There is a high chance you have a problem with your python setup (maybe not using the OS packaging system 100% ?).

Check the errors by logging the output of pypr, it is likely it has a problem, replace:

exec-once = pypr

with

exec-once = pypr --debug /tmp/pypr.log > /tmp/pypr_1.log >> /tmp/pypr_2.log

And check the log files, something is going wrong here.

Also I thought I had improved the logging in such case to indicate pypr daemon didn't start, which version are you running?

Edit: try to uninstall pyprland from pipx or pip to simplify the situation

@fdev31
Copy link
Collaborator

fdev31 commented Nov 11, 2023

same here with AUR package

If you didn't install it with pip or pipx I'm very interested in the outcome of your test and the different logs for pypr & hyprland, since one fails to start the other...

@fdev31
Copy link
Collaborator

fdev31 commented Nov 11, 2023

Some exception wasn't caught, the error message you should get is:
"Failed to open control socket, is pypr daemon running ?"

@nisby
Copy link

nisby commented Nov 11, 2023

same here with AUR package

If you didn't install it with pip or pipx I'm very interested in the outcome of your test and the different logs for pypr & hyprland, since one fails to start the other...

2023-11-11 23:32:40,997 [INFO] ipc :: Logger initialized for ipc :: common.py:70 2023-11-11 23:32:40,997 [INFO] startup :: Logger initialized for startup :: common.py:70 2023-11-11 23:32:40,998 [INFO] pypr :: Logger initialized for pypr :: common.py:70 2023-11-11 23:32:40,999 [CRITICAL] pypr :: Failed to load config. :: command.py:179 Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/pyprland/command.py", line 175, in run_daemon await manager.load_config() # ensure sockets are connected first ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/pyprland/command.py", line 39, in load_config self.config = json.loads(f.read()) ^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/json/__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) ^^^^^^^^^^^^^^^^^^^^^^ json.decoder.JSONDecodeError: Expecting ',' delimiter: line 15 column 1 (char 226)

@XenoWad01
Copy link
Author

Yes, I figured out after writing this that that branch was probably merged long ago as you mentioned.
So to recap, I am currently on the version installed with pipx install pyprland. About which version this is, I would assume the latest published one if I just fresh installed it.
And I have simplified my pyprland.json to contain only the volume scratchpad because the logs were polluted with discord related logs and I figured they would be more concise this way.
I simply ran pypr --debug /tmp/pypr.log > /tmp/pypr_1.log >> /tmp/pypr_2.log and here are the results of pressing super + V - spawn volume scratchpad only once :
pypr.log:

❯ cat pypr.log
2023-11-12 04:48:49,963 [INFO] ipc :: Logger initialized for ipc :: common.py:70
2023-11-12 04:48:49,963 [INFO] startup :: Logger initialized for startup :: common.py:70
2023-11-12 04:48:49,963 [INFO] pypr :: Logger initialized for pypr :: common.py:70
2023-11-12 04:48:49,965 [INFO] scratchpads :: Logger initialized for scratchpads :: common.py:70
2023-11-12 04:48:49,965 [INFO] scratchpads :: {'volume'} :: scratchpads.py:333
2023-11-12 04:48:49,966 [INFO] scratchpads :: volume is not running, restarting... :: scratchpads.py:345
2023-11-12 04:48:49,966 [INFO] scratchpads :: starting volume :: scratchpads.py:349
2023-11-12 04:48:49,966 [INFO] scratchpads :: scratch volume has pid 28180 :: scratchpads.py:381
2023-11-12 04:48:49,967 [INFO] scratchpads :: ==> Wait for volume spawning :: scratchpads.py:351
2023-11-12 04:48:50,067 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:50,469 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:51,371 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:52,974 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:55,477 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:57,309 [DEBUG] pypr :: CMD: run_toggle(['volume']) :: command.py:129
2023-11-12 04:48:57,310 [DEBUG] pypr :: scratchpads.run_toggle('volume',) :: command.py:73
2023-11-12 04:48:57,310 [DEBUG] scratchpads :: volume is visible = False :: scratchpads.py:464
2023-11-12 04:48:57,310 [DEBUG] ipc :: activewindow :: ipc.py:25
2023-11-12 04:48:57,310 [INFO] scratchpads :: Showing volume :: scratchpads.py:506
2023-11-12 04:48:57,310 [INFO] scratchpads :: volume is not running, restarting... :: scratchpads.py:345
2023-11-12 04:48:57,310 [INFO] scratchpads :: starting volume :: scratchpads.py:349
2023-11-12 04:48:57,311 [INFO] scratchpads :: scratch volume has pid 28193 :: scratchpads.py:381
2023-11-12 04:48:57,311 [INFO] scratchpads :: ==> Wait for volume spawning :: scratchpads.py:351
2023-11-12 04:48:57,411 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:57,813 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:58,715 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:59,079 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:00,317 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:02,821 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:03,982 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:03,984 [ERROR] scratchpads :: => Failed spawning volume as proc 28193 :: scratchpads.py:361
2023-11-12 04:49:03,984 [ERROR] scratchpads :: Failure starting volume :: scratchpads.py:338
2023-11-12 04:49:06,424 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:11,327 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:11,329 [ERROR] scratchpads :: => Failed spawning volume as proc 28193 :: scratchpads.py:361
2023-11-12 04:49:11,329 [ERROR] scratchpads :: Failed to show volume, aborting. :: scratchpads.py:508
2023-11-12 04:49:20,317 [INFO] pypr :: EVT: activewindow(Brave-browser,Issue with pypr commands · Issue #22 · hyprland-community/pyprland - Brave) :: command.py:99
2023-11-12 04:49:20,318 [INFO] pypr :: EVT: activewindowv2(55ed69cb0cf0) :: command.py:99
2023-11-12 04:49:20,318 [DEBUG] pypr :: scratchpads.event_activewindowv2('55ed69cb0cf0\n',) :: command.py:73
2023-11-12 04:49:21,318 [INFO] pypr :: EVT: activewindow(Alacritty,pypr --debug /tmp/pypr.log > /tmp/pypr_1.log >> /tmp/pypr_2.log) :: command.py:99
2023-11-12 04:49:21,318 [INFO] pypr :: EVT: activewindowv2(55ed69caf820) :: command.py:99
2023-11-12 04:49:21,318 [DEBUG] pypr :: scratchpads.event_activewindowv2('55ed69caf820\n',) :: command.py:73
2023-11-12 04:49:22,856 [INFO] pypr :: EVT: activewindow(Brave-browser,Issue with pypr commands · Issue #22 · hyprland-community/pyprland - Brave) :: command.py:99
2023-11-12 04:49:22,856 [INFO] pypr :: EVT: activewindowv2(55ed69cb0cf0) :: command.py:99
2023-11-12 04:49:22,856 [DEBUG] pypr :: scratchpads.event_activewindowv2('55ed69cb0cf0\n',) :: command.py:73
2023-11-12 04:50:03,286 [INFO] pypr :: EVT: activewindow(Alacritty,pypr --debug /tmp/pypr.log > /tmp/pypr_1.log >> /tmp/pypr_2.log) :: command.py:99
2023-11-12 04:50:03,286 [INFO] pypr :: EVT: activewindowv2(55ed69caf820) :: command.py:99
2023-11-12 04:50:03,286 [DEBUG] pypr :: scratchpads.event_activewindowv2('55ed69caf820\n',) :: command.py:73
2023-11-12 04:50:22,030 [CRITICAL] pypr :: cancelled :: command.py:187

@XenoWad01
Copy link
Author

And here is the pyprland version as stated by pipx:

❯ pipx list
venvs are in /home/anime_protagonist/.local/pipx/venvs
apps are exposed on your $PATH at /home/anime_protagonist/.local/bin
   package pyprland 1.4.4, installed using Python 3.11.5
    - pypr
    

@XenoWad01
Copy link
Author

And here is my updated pyprland.json for reference. (probably not relevant)

{
    "pyprland": {
        "plugins": [
            "scratchpads"
		]
    },
    "scratchpads": {
		"volume": {
			"command": "pavucontrol",
			"animation": "fromRight"
		}
    }
}

@XenoWad01
Copy link
Author

And about the pypr daemon running, yes there is a process running with command: ~/.local/pipx/venvs/pyprland/bin/python ~/.local/bin/pypr on htop.

@fdev31
Copy link
Collaborator

fdev31 commented Nov 12, 2023

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 15 column 1 (char 226)

I'm not sure why you lost every newline, but check the line 15 of your config, there is a syntax error.

@fdev31
Copy link
Collaborator

fdev31 commented Nov 12, 2023

And about the pypr daemon running, yes there is a process running with command: ~/.local/pipx/venvs/pyprland/bin/python ~/.local/bin/pypr on htop.

The errors are completely different this time, looks like your environment is instable.
What did you do to solve pypr daemon not starting ?

Original issue is fixed I guess, now it looks like you have another problem: the volume app window isn't showing.

In the logs you see the PID of the program, in hyprctl clients you should see a window using this PID.

I don't know exactly why but the app takes more than 5s to start, which is not supported:

2023-11-12 04:48:57,311 [INFO] scratchpads :: ==> Wait for volume spawning :: scratchpads.py:351
2023-11-12 04:48:57,411 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:57,813 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:58,715 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:48:59,079 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:00,317 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:02,821 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:03,982 [DEBUG] ipc :: clients :: ipc.py:25
2023-11-12 04:49:03,984 [ERROR] scratchpads :: => Failed spawning volume as proc 28193 :: scratchpads.py:361

Do you have the issue for every app ?

@XenoWad01
Copy link
Author

XenoWad01 commented Nov 12, 2023

Okay so I did not do anything since last night, logged in today, and i tried pypr show volume again, and it just worked I'm dumbfounded to be honest. I explained exactly what I did (nothing except reinstall from pipx again to have fresh install).

@XenoWad01
Copy link
Author

Im very confused maybe it needed a good old reboot after installing?

@XenoWad01
Copy link
Author

Because I really did not alter anything other than removing discord from my scratchpad config. And I dont think that was the issue.

@XenoWad01
Copy link
Author

I could close this if you do not need any more information from me. If it works I'll leave it alone. But the system shouldn't be instable its almost a fresh install.

@XenoWad01
Copy link
Author

XenoWad01 commented Nov 12, 2023

Ok I did some digging around because I dont like leaving things like this. So basically I re-introduced discord into my pyprland.json on super + d and it worked fine together with the volume mixer. I then closed discord(as in closed not hidden with the scratchpad functionality) and now it can't restart. I'm back to that first error with the socket being closed. Im pretty sure this all was an issue with discord + the daemon dying cuz of discord for some reason, because I think it cannot re-open a scratchpad's process after the first time? Even though the first time I hit super + d it started up discord just fine for me. Im really not sure.

@XenoWad01
Copy link
Author

So after debugging I think there really is a specific issue with discord.
I had betterdiscord and I thought maybe thats the reason it fails to show it. I uninstalled betterdiscord and got left with regular discord (command is same for both). Volume scratchpad works fine, discord one shows the loading screen from discord fine. But then the real discord screen spawns, that one is unreactive to being shown or hidden.

@fdev31
Copy link
Collaborator

fdev31 commented Nov 12, 2023

I don't know pipx to be honest, but I know it's very easy to get confused with multiple "transparent" environments running in parallel.

I would recomment sticking to using the operating system packages or explicit python virtual environments.

About discord, I don't use the desktop app, but I know a couple of apps may manage the GUI separately to the daemon, making PID matching impossible.
So it could be that first time it uses the PID of the process you started, but second time after the window have been closed it will reuse the PID of the old process, not the one which has just been respawned...
There is a class matching feature you may play with to work around such issues.

I consider it closed.

@fdev31 fdev31 closed this as completed Nov 12, 2023
@XenoWad01
Copy link
Author

Last 3 -4 reboots i've been getting this in the logs with pypr daemon not starting because of this.

❯ cat pypr.log
2023-11-12 17:11:02,874 [INFO] ipc :: Logger initialized for ipc :: common.py:70
2023-11-12 17:11:02,875 [INFO] startup :: Logger initialized for startup :: common.py:70
2023-11-12 17:11:02,875 [INFO] pypr :: Logger initialized for pypr :: common.py:70
2023-11-12 17:11:02,875 [CRITICAL] pypr :: Failed to load config. :: command.py:179
Traceback (most recent call last):
  File "/home/anime_protagonist/.local/pipx/venvs/pyprland/lib/python3.11/site-packages/pyprland/command.py", line 175, in run_daemon
    await manager.load_config()  # ensure sockets are connected first
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anime_protagonist/.local/pipx/venvs/pyprland/lib/python3.11/site-packages/pyprland/command.py", line 39, in load_config
    self.config = json.loads(f.read())
                  ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 11 column 9 (char 197)

@fdev31
Copy link
Collaborator

fdev31 commented Nov 12, 2023

This error is relatively clear, and line 11 of the JSON config file you had a syntax error.
Many users report similar issues, I'll add support for TOML in the future.

@nisby
Copy link

nisby commented Nov 12, 2023

This error is relatively clear, and line 11 of the JSON config file you had a syntax error. Many users report similar issues, I'll add support for TOML in the future.

my problem were json config error, changed to toml format and all work as expected. Tank you !!!!

@XenoWad01
Copy link
Author

Yea I also ported to the TOML format and I had a stupid trailing comma in the json. Everything works fine. Thank you so much for the help!

@fdev31 fdev31 added the invalid This doesn't seem right label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants