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

Py3 fixes to lib/color_compliment.py #220

Merged
merged 4 commits into from
Dec 26, 2015
Merged

Py3 fixes to lib/color_compliment.py #220

merged 4 commits into from
Dec 26, 2015

Conversation

ceholden
Copy link
Contributor

PR fixes three bugs identified when using --colorized-hostname with Python3. I don't have confirmation yet, but this likely addresses issue #216. I used try/except blocks and version checks to be conservative and ensure this doesn't break for anyone on a very old Python 2 version, but this was probably excessive and isn't something I would have done on my own project. I'd be happy to remove them if there are concerns about the overhead.

With these changes made, I've had no problems on Python 2.6.6, 2.7.10, and 3.5.1.

Issue 1 fixed in ceholden/powerline-shell@1f1acb81cba48e35820c4a88b4c39ab5ff40db42:

Traceback (most recent call last):
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/powerline-shell.py", line 272, in <module>
    add_hostname_segment()
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/powerline-shell.py", line 251, in add_hostname_segment
    from lib.color_compliment import stringToHashToColorAndOpposite
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/lib/color_compliment.py", line 3, in <module>
    from colortrans import *
ImportError: No module named 'colortrans'

Issue 2 fixed in ceholden/powerline-shell@c07c4be6b4e410a56bc95284bb553f5b1baaa7f7:

$HOME/.homesick/repos/dotfiles/powerline-shell/powerline-shell.py --cwd-only --colorize-hostname
Traceback (most recent call last):
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/powerline-shell.py", line 272, in <module>
    add_hostname_segment()
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/powerline-shell.py", line 255, in add_hostname_segment
    FG, BG = stringToHashToColorAndOpposite(hostname)
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/lib/color_compliment.py", line 35, in stringToHashToColorAndOpposite
    string = md5(string).hexdigest()[:6] # get a random color
TypeError: Unicode-objects must be encoded before hashing

Issue 3, previously mentioned but not merged in #82, fixed in ceholden/powerline-shell@6bef8fab1dc86739f6073d8dfbacc1fb20dc1edc:

Traceback (most recent call last):
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/powerline-shell.py", line 272, in <module>
    add_hostname_segment()
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/powerline-shell.py", line 251, in add_hostname_segment
    from lib.color_compliment import stringToHashToColorAndOpposite
  File "/home/ceholden/.homesick/repos/dotfiles/powerline-shell/lib/color_compliment.py", line 5, in <module>
    from md5 import md5
ImportError: No module named 'md5

Encoding works on Py2.7, but will only encode if Py3 in case
it breaks earlier Py2.x
sys.version_info doesn't have named tuple components prior
to Python 2.7
https://docs.python.org/2/library/sys.html#sys.version_info
@b-ryan
Copy link
Owner

b-ryan commented Dec 26, 2015

Thanks @ceholden! I would share your preference to not support older versions of Python. I haven't seen any issues where people have complained about issues in older versions.

I'm gonna merge this anyway though. The backwards compatibility isn't hurting anything.

b-ryan added a commit that referenced this pull request Dec 26, 2015
Py3 fixes to lib/color_compliment.py
@b-ryan b-ryan merged commit 713194d into b-ryan:master Dec 26, 2015
amtrivedi91 added a commit to amtrivedi91/powerline-shell that referenced this pull request Aug 31, 2016
Py3 fixes to lib/color_compliment.py
amtrivedi91 added a commit to amtrivedi91/powerline-shell that referenced this pull request Aug 31, 2016
Py3 fixes to lib/color_compliment.py
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