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

fix python3 compatibility #211

Merged
merged 2 commits into from
Nov 22, 2015
Merged

fix python3 compatibility #211

merged 2 commits into from
Nov 22, 2015

Conversation

b-ryan
Copy link
Owner

@b-ryan b-ryan commented Nov 20, 2015

closes #66, #118, #137, #140, #192, #206

^ This seems to be the most pressing issue to resolve. I'm hoping to fix python3 compatibility once and for all in this branch. Looking for feedback from anyone who knows more about this stuff.

Notes on the changes in here:

  • os.getenv and related functions return strings, not unicode (in python 2). This will cause an issue in the draw function if you do not decode the string into utf-8 and there are non-ascii characters in the string, because concatenating a unicode object and a string causes Python to try to implicitly convert the ASCII to unicode, but can't convert the non-ascii character. Here is some that demos this:
>>> x = "powerline-shell-\xe2\x9c\x8e" # bytes to make the pencil utf-8 character
>>> x + u""
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 16: ordinal not in range(128)
  • In Python 3, everything is unicode. There is also no str.decode function.
  • However, in Python 3, the subprocess functions return bytes instead of unicode. Thus we must always decode the bytes into unicode. This works just fine though since in Python 2, subprocess returns strings which must also be decoded into unicode.

Tests:

  • cd into directory with non-ascii character in its name (py2)
  • cd into directory with non-ascii character in its name (py3)
  • git branch has unicode char (py2)
  • git branch has unicode char (py3)
  • hg basic test (py2)
  • hg basic test (py3)
  • basic jobs test
  • basic ruby/node version tests

@b-ryan
Copy link
Owner Author

b-ryan commented Nov 22, 2015

Did some pretty extensive testing. Only thing I left out was testing the SVN changes. That I'm just hoping I'm not missing something.

@b-ryan
Copy link
Owner Author

b-ryan commented Nov 22, 2015

Just gave SVN a quick run and found no issues. I think this change is ready to go.

b-ryan added a commit that referenced this pull request Nov 22, 2015
@b-ryan b-ryan merged commit 0122d0f into b-ryan:master Nov 22, 2015
@b-ryan b-ryan deleted the fix/python3-compat branch November 22, 2015 00:41
@LeonardoGentile
Copy link

Hello, this seems not to work for me with pyenv.
pyenv global 3.4.3 shows no prompt at all, all the segments disappear but no error is showed.
If I pyenv global 2.7.6 then things go back to normal

amtrivedi91 added a commit to amtrivedi91/powerline-shell that referenced this pull request Aug 31, 2016
amtrivedi91 added a commit to amtrivedi91/powerline-shell that referenced this pull request Aug 31, 2016
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