Skip to content

Commit

Permalink
Fix Python 3 compatibility by converting cmp-style function to key-st…
Browse files Browse the repository at this point in the history
…yle function (fixes #149)
  • Loading branch information
Pidgeot committed Oct 25, 2017
1 parent f38ee8d commit 43df850
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def read_colors():
return tuple(sorted(
[os.path.splitext(os.path.basename(p))[0] for p in
helpers.get_text_files(paths.get('colors'))],
cmp=helpers.sort_underscore_first))
key=helpers.key_from_underscore_prefixed_string))

def get_colors(colorscheme=None):
"""
Expand Down
12 changes: 4 additions & 8 deletions core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ def os_is_64bit():
"""Returns true if running on a 64-bit OS."""
return platform.machine().endswith('64')

def sort_underscore_first(a, b):
"""Special sorting function which considers _-prefixed strings to be smaller
than all other strings."""
if a.startswith('_') == b.startswith('_'):
return cmp(a, b)
if a.startswith('_'):
return -1
return 1
def key_from_underscore_prefixed_string(s):
"""Converts a string to a key such that strings prefixed with an underscore
will be sorted before other strings."""
return not s.startswith('_'), s

0 comments on commit 43df850

Please sign in to comment.