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

i3ipc 2.x and Py2 compatibility #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

i3ipc 2.x and Py2 compatibility #22

wants to merge 2 commits into from

Conversation

dheuvels
Copy link

I had to change a few lines in i3-workspace-names-daemon to get it running in my i3 environment.

ac94f27 Fixes an issue with the 2.x versions of i3ipc.
The WorkspaceReply class is not a dict anymore, causing "TypeError: 'WorkspaceReply' object is not subscriptable". I added the getattr() function, which will work with both flavours of the WorkspaceReply class.

85a4306 adds the u'' prefix to string literals. I had a usecase with Python2 and this was required to get it running. I know that Python2 is deprecated and i3ipc only supports Py2 up to 1.7.1, but as it only takes a few prefixes to keep it functional, it's maybe worth it.

CastixGitHub added a commit to CastixGitHub/i3-workspace-names-daemon that referenced this pull request Feb 23, 2020
@CastixGitHub
Copy link
Contributor

Hi @dheuvels
I am trying to figure out how you got this working on python2:
I installed i3ipc 1.7.1 with pip2
if I run this script with python2, it gets closed (the main returns) whenever i open/close/etc a window and the names remain the same
Thanks

@dheuvels
Copy link
Author

dheuvels commented Mar 18, 2020

Hi @CastixGitHub,

I am trying to figure out how you got this working on python2

There seems to be a bug in i3ipc 1.7.1 that eats up the stack traces of exceptions. When I use 1.6.0, I see the trace:

% git clone https://github.com/cboddy/i3-workspace-names-daemon.git && cd i3-workspace-names-daemon
% python2 -m virtualenv i3ipc_venv
% . i3ipc_venv/bin/activate
% pip install i3ipc==1.6.0
% python2 ./i3_workspace_names_daemon.py
Traceback (most recent call last): (..)
  File "./i3_workspace_names_daemon.py", line 95, in rename
    workspace.name.replace('"', '\\"'), newname.replace('"', '\\"')))
UnicodeEncodeError: 'ascii' codec can't encode character u'\uf120' in position 3: ordinal not in range(128)

So Python is complaining about this (new) replace statement in line 95, which uses an ASCII string:

commands.append('rename workspace "{}" to "{}"'.format(workspace.name.replace('"', '\\"'), newname.replace('"', '\\"')))

If you use a unicode string, it is working:

 commands.append(u'rename workspace "{}" to "{}"'.format(workspace.name.replace('"', '\\"'), newname.replace('"', '\\"')))

(note the u'rename).

I haven't figured out what is causing the problem with the missing traces in 1.7.1. But if you change the replace call, then it will also run with 1.7.1.

Regards,
Dirk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants