comparison setup.py @ 38721:dbbe45ae5ad1

setup: allow to run setup.py with python 3 without a mercurial checkout Some people may want to test mercurial in a python 3 environment through e.g. pip, in which case setup.py doesn't run in a mercurial checkout, so the hack in setup.py to allow python 3 cannot be overcome. This change allows a manual override with the HGPYTHON3 environment variable. Additionally, when for some reason the version is unknown (for crazy people like me, who have a git checkout of the mercurial repo), the version variable ends up being an unicode string, which fails the `isinstance(version, bytes)` assertion. So fix that at the same time. Differential Revision: https://phab.mercurial-scm.org/D3958
author Mike Hommey <mh@glandium.org>
date Mon, 16 Jul 2018 17:47:58 -0700
parents db9d1dd01bf0
children 1ddb296e0dee
comparison
equal deleted inserted replaced
38720:d12415b8f833 38721:dbbe45ae5ad1
72 # backdoor to enable working on Python 3. 72 # backdoor to enable working on Python 3.
73 if sys.version_info[0] != 2: 73 if sys.version_info[0] != 2:
74 badpython = True 74 badpython = True
75 75
76 # Allow Python 3 from source checkouts. 76 # Allow Python 3 from source checkouts.
77 if os.path.isdir('.hg'): 77 if os.path.isdir('.hg') or 'HGPYTHON3' in os.environ:
78 badpython = False 78 badpython = False
79 79
80 if badpython: 80 if badpython:
81 error = """ 81 error = """
82 Mercurial only supports Python 2.7. 82 Mercurial only supports Python 2.7.
367 oldpolicy = os.environ.get('HGMODULEPOLICY', None) 367 oldpolicy = os.environ.get('HGMODULEPOLICY', None)
368 os.environ['HGMODULEPOLICY'] = 'py' 368 os.environ['HGMODULEPOLICY'] = 'py'
369 from mercurial import __version__ 369 from mercurial import __version__
370 version = __version__.version 370 version = __version__.version
371 except ImportError: 371 except ImportError:
372 version = 'unknown' 372 version = b'unknown'
373 finally: 373 finally:
374 if oldpolicy is None: 374 if oldpolicy is None:
375 del os.environ['HGMODULEPOLICY'] 375 del os.environ['HGMODULEPOLICY']
376 else: 376 else:
377 os.environ['HGMODULEPOLICY'] = oldpolicy 377 os.environ['HGMODULEPOLICY'] = oldpolicy