tests/hghave.py
changeset 50250 57133107ab4d
parent 50249 a7cbb626ec3f
child 51372 0d414fb8336f
equal deleted inserted replaced
50249:a7cbb626ec3f 50250:57133107ab4d
    25     pass
    25     pass
    26 
    26 
    27 stdout = getattr(sys.stdout, 'buffer', sys.stdout)
    27 stdout = getattr(sys.stdout, 'buffer', sys.stdout)
    28 stderr = getattr(sys.stderr, 'buffer', sys.stderr)
    28 stderr = getattr(sys.stderr, 'buffer', sys.stderr)
    29 
    29 
    30 is_not_python2 = sys.version_info[0] >= 3
    30 
    31 if is_not_python2:
    31 def _sys2bytes(p):
    32 
    32     if p is None:
    33     def _sys2bytes(p):
       
    34         if p is None:
       
    35             return p
       
    36         return p.encode('utf-8')
       
    37 
       
    38     def _bytes2sys(p):
       
    39         if p is None:
       
    40             return p
       
    41         return p.decode('utf-8')
       
    42 
       
    43 
       
    44 else:
       
    45 
       
    46     def _sys2bytes(p):
       
    47         return p
    33         return p
    48 
    34     return p.encode('utf-8')
    49     _bytes2sys = _sys2bytes
    35 
       
    36 
       
    37 def _bytes2sys(p):
       
    38     if p is None:
       
    39         return p
       
    40     return p.decode('utf-8')
    50 
    41 
    51 
    42 
    52 def check(name, desc):
    43 def check(name, desc):
    53     """Registers a check function for a feature."""
    44     """Registers a check function for a feature."""
    54 
    45 
   166     return matchoutput('baz --version 2>&1', br'baz Bazaar version')
   157     return matchoutput('baz --version 2>&1', br'baz Bazaar version')
   167 
   158 
   168 
   159 
   169 @check("bzr", "Breezy library and executable version >= 3.1")
   160 @check("bzr", "Breezy library and executable version >= 3.1")
   170 def has_bzr():
   161 def has_bzr():
   171     if not is_not_python2:
       
   172         return False
       
   173     try:
   162     try:
   174         # Test the Breezy python lib
   163         # Test the Breezy python lib
   175         import breezy
   164         import breezy
   176         import breezy.bzr.bzrdir
   165         import breezy.bzr.bzrdir
   177         import breezy.errors
   166         import breezy.errors
   875 def has_demandimport():
   864 def has_demandimport():
   876     # chg disables demandimport intentionally for performance wins.
   865     # chg disables demandimport intentionally for performance wins.
   877     return (not has_chg()) and os.environ.get('HGDEMANDIMPORT') != 'disable'
   866     return (not has_chg()) and os.environ.get('HGDEMANDIMPORT') != 'disable'
   878 
   867 
   879 
   868 
   880 # Add "py27", "py35", ... as possible feature checks. Note that there's no
   869 # Add "py36", "py37", ... as possible feature checks. Note that there's no
   881 # punctuation here.
   870 # punctuation here.
   882 @checkvers("py", "Python >= %s", (2.7, 3.5, 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))
   883 def has_python_range(v):
   872 def has_python_range(v):
   884     major, minor = v.split('.')[0:2]
   873     major, minor = v.split('.')[0:2]
   885     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
   886 
   875 
   887     return (py_major, py_minor) >= (int(major), int(minor))
   876     return (py_major, py_minor) >= (int(major), int(minor))
   895 @check("py3exe", "a Python 3.x interpreter is available")
   884 @check("py3exe", "a Python 3.x interpreter is available")
   896 def has_python3exe():
   885 def has_python3exe():
   897     py = 'python3'
   886     py = 'python3'
   898     if os.name == 'nt':
   887     if os.name == 'nt':
   899         py = 'py -3'
   888         py = 'py -3'
   900     return matchoutput('%s -V' % py, br'^Python 3.(5|6|7|8|9|10|11)')
   889     return matchoutput('%s -V' % py, br'^Python 3.(6|7|8|9|10|11)')
   901 
   890 
   902 
   891 
   903 @check("pure", "running with pure Python code")
   892 @check("pure", "running with pure Python code")
   904 def has_pure():
   893 def has_pure():
   905     return any(
   894     return any(