forked from openlp/openlp
Pulled natural sorting methods out from the try (no real reason for them to be in there) and moved "try_int" to outside the other method (then it is only compiled once).
This commit is contained in:
parent
14088e71bb
commit
4e03451db7
23
setup.py
23
setup.py
@ -31,15 +31,8 @@ from setuptools import setup, find_packages
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
VERSION_FILE = 'openlp/.version'
|
VERSION_FILE = 'openlp/.version'
|
||||||
|
SPLIT_ALPHA_DIGITS = re.compile(r'(\d+|\D+)')
|
||||||
|
|
||||||
try:
|
|
||||||
def natural_sort_key(s):
|
|
||||||
"""
|
|
||||||
Return a tuple by which s is sorted.
|
|
||||||
|
|
||||||
``s``
|
|
||||||
A string value from the list we want to sort.
|
|
||||||
"""
|
|
||||||
def try_int(s):
|
def try_int(s):
|
||||||
"""
|
"""
|
||||||
Convert string s to an integer if possible. Fail silently and return
|
Convert string s to an integer if possible. Fail silently and return
|
||||||
@ -50,9 +43,17 @@ try:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return int(s)
|
return int(s)
|
||||||
except:
|
except Exception:
|
||||||
return s
|
return s
|
||||||
return map(try_int, re.findall(r'(\d+|\D+)', s))
|
|
||||||
|
def natural_sort_key(s):
|
||||||
|
"""
|
||||||
|
Return a tuple by which s is sorted.
|
||||||
|
|
||||||
|
``s``
|
||||||
|
A string value from the list we want to sort.
|
||||||
|
"""
|
||||||
|
return map(try_int, SPLIT_ALPHA_DIGITS.findall(s))
|
||||||
|
|
||||||
def natural_compare(a, b):
|
def natural_compare(a, b):
|
||||||
"""
|
"""
|
||||||
@ -75,6 +76,8 @@ try:
|
|||||||
temp.sort(compare)
|
temp.sort(compare)
|
||||||
return temp
|
return temp
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Try to import Bazaar
|
||||||
from bzrlib.branch import Branch
|
from bzrlib.branch import Branch
|
||||||
b = Branch.open_containing('.')[0]
|
b = Branch.open_containing('.')[0]
|
||||||
b.lock_read()
|
b.lock_read()
|
||||||
|
Loading…
Reference in New Issue
Block a user