comparison tests/hghave.py @ 51373:7d313b259169

hghave: use strings instead of floats for version numbers passed to checkvers I think it’s a really bad idea to use floats for version numbers. One problem is that 3.10 is the same as 3.1.
author Manuel Jacob <me@manueljacob.de>
date Fri, 02 Feb 2024 04:23:07 +0100
parents 0d414fb8336f
children 54a75576287a
comparison
equal deleted inserted replaced
51372:617af10994fb 51373:7d313b259169
65 return func(v) 65 return func(v)
66 66
67 return f 67 return f
68 68
69 for v in vers: 69 for v in vers:
70 v = str(v) 70 assert isinstance(v, str)
71 f = funcv(v) 71 f = funcv(v)
72 checks['%s%s' % (name, v.replace('.', ''))] = (f, desc % v) 72 checks['%s%s' % (name, v.replace('.', ''))] = (f, desc % v)
73 return func 73 return func
74 74
75 return decorator 75 return decorator
353 if _hgversion is None: 353 if _hgversion is None:
354 _hgversion = _gethgversion() 354 _hgversion = _gethgversion()
355 return _hgversion 355 return _hgversion
356 356
357 357
358 @checkvers("hg", "Mercurial >= %s", [(1.0 * x) / 10 for x in range(9, 99)]) 358 @checkvers(
359 "hg", "Mercurial >= %s", ['%d.%d' % divmod(x, 10) for x in range(9, 99)]
360 )
359 def has_hg_range(v): 361 def has_hg_range(v):
360 major, minor = v.split('.')[0:2] 362 major, minor = v.split('.')[0:2]
361 return gethgversion() >= (int(major), int(minor)) 363 return gethgversion() >= (int(major), int(minor))
362 364
363 365
431 os.access(os.path.join(path, exe), os.X_OK) 433 os.access(os.path.join(path, exe), os.X_OK)
432 for path in os.environ["PATH"].split(os.pathsep) 434 for path in os.environ["PATH"].split(os.pathsep)
433 ) 435 )
434 436
435 437
436 @checkvers("git", "git client (with ext::sh support) version >= %s", (1.9,)) 438 @checkvers("git", "git client (with ext::sh support) version >= %s", ('1.9',))
437 def has_git_range(v): 439 def has_git_range(v):
438 major, minor = v.split('.')[0:2] 440 major, minor = v.split('.')[0:2]
439 return getgitversion() >= (int(major), int(minor)) 441 return getgitversion() >= (int(major), int(minor))
440 442
441 443
455 if not m: 457 if not m:
456 return (0, 0) 458 return (0, 0)
457 return (int(m.group(1)), int(m.group(2))) 459 return (int(m.group(1)), int(m.group(2)))
458 460
459 461
460 @checkvers("svn", "subversion client and admin tools >= %s", (1.3, 1.5)) 462 @checkvers("svn", "subversion client and admin tools >= %s", ('1.3', '1.5'))
461 def has_svn_range(v): 463 def has_svn_range(v):
462 major, minor = v.split('.')[0:2] 464 major, minor = v.split('.')[0:2]
463 return getsvnversion() >= (int(major), int(minor)) 465 return getsvnversion() >= (int(major), int(minor))
464 466
465 467
658 return (int(parts[0]), int(parts[1])) 660 return (int(parts[0]), int(parts[1]))
659 except ImportError: 661 except ImportError:
660 return (0, 0) 662 return (0, 0)
661 663
662 664
663 @checkvers("pygments", "Pygments version >= %s", (2.5, 2.11, 2.14)) 665 @checkvers("pygments", "Pygments version >= %s", ('2.5', '2.11', '2.14'))
664 def has_pygments_range(v): 666 def has_pygments_range(v):
665 major, minor = v.split('.')[0:2] 667 major, minor = v.split('.')[0:2]
666 return getpygmentsversion() >= (int(major), int(minor)) 668 return getpygmentsversion() >= (int(major), int(minor))
667 669
668 670
864 return (not has_chg()) and os.environ.get('HGDEMANDIMPORT') != 'disable' 866 return (not has_chg()) and os.environ.get('HGDEMANDIMPORT') != 'disable'
865 867
866 868
867 # Add "py36", "py37", ... as possible feature checks. Note that there's no 869 # Add "py36", "py37", ... as possible feature checks. Note that there's no
868 # punctuation here. 870 # punctuation here.
869 @checkvers("py", "Python >= %s", (3.6, 3.7, 3.8, 3.9, 3.10, 3.11)) 871 @checkvers("py", "Python >= %s", ('3.6', '3.7', '3.8', '3.9', '3.10', '3.11'))
870 def has_python_range(v): 872 def has_python_range(v):
871 major, minor = v.split('.')[0:2] 873 major, minor = v.split('.')[0:2]
872 py_major, py_minor = sys.version_info.major, sys.version_info.minor 874 py_major, py_minor = sys.version_info.major, sys.version_info.minor
873 875
874 return (py_major, py_minor) >= (int(major), int(minor)) 876 return (py_major, py_minor) >= (int(major), int(minor))