From 18d2ee2f22e06936cf282c63a660233670d2457f Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Tue, 6 Oct 2015 16:09:09 -0500 Subject: [PATCH] Fix our algorithm to do version comparisons Fixes #2612 --- spyderlib/utils/programs.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/spyderlib/utils/programs.py b/spyderlib/utils/programs.py index f3336d8b69f..bf0f9c8f529 100644 --- a/spyderlib/utils/programs.py +++ b/spyderlib/utils/programs.py @@ -212,10 +212,9 @@ def is_stable_version(version): version = version.split('.') last_part = version[-1] - try: - int(last_part) + if not re.search('[a-zA-Z]', last_part): return True - except ValueError: + else: return False @@ -235,11 +234,14 @@ def check_version(actver, version, cmp_op): if isinstance(actver, tuple): actver = '.'.join([str(i) for i in actver]) - # A small hack is needed so that LooseVersion understands that for example + # Hacks needed so that LooseVersion understands that (for example) # version = '3.0.0' is in fact bigger than actver = '3.0.0rc1' - if is_stable_version(version) and actver.startswith(version) and\ - version != actver: - version = version + 'z' + if is_stable_version(version) and not is_stable_version(actver) and \ + actver.startswith(version) and version != actver: + version = version + 'zz' + elif is_stable_version(actver) and not is_stable_version(version) and \ + version.startswith(actver) and version != actver: + actver = actver + 'zz' try: if cmp_op == '>': @@ -345,9 +347,13 @@ def is_module_installed(module_name, version=None, installed_version=None, if __name__ == '__main__': - print(find_program('hg')) - print(shell_split('-q -o -a')) - print(shell_split('-q "d:\\Python de xxxx\\t.txt" -o -a')) - print(is_module_installed('IPython', '>=0.12')) - print(is_module_installed('IPython', '>=0.13;<1.0')) - print(is_module_installed('jedi', '>=0.7.0')) + assert(find_program('git')) + assert(shell_split('-q -o -a') == ['-q', '-o', '-a']) + assert(shell_split('-q "d:\\Python de xxxx\\t.txt" -o -a') == \ + ['-q', 'd:\\Python de xxxx\\t.txt', '-o', '-a']) + assert(check_version('0.9.4-1', '0.9.4', '>=')) + assert(check_version('3.0.0rc1', '3.0.0', '<')) + assert(check_version('1.0', '1.0b2', '>')) + assert(is_module_installed('IPython', '>=3.0')) + assert(not is_module_installed('IPython', '>=1.0;<3.0')) + assert(is_module_installed('jedi', '>=0.7.0'))