Mercurial > hg
comparison tests/run-tests.py @ 47500:23f5ed6dbcb1
run-tests: stop writing a `python3` symlink pointing to python2
Having `python3` actually pointing to `python2` is bad. So we stop doing so.
In addition we need to re-introduce a `python` executable since some of the
script really need to be able to say "current python" in their shbang. For
example, `hghave` is one of such script.
The faulty changes where introduced by c102b704edb5.
Differential Revision: https://phab.mercurial-scm.org/D10943
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 02 Jul 2021 23:09:44 +0200 |
parents | 9d929f9cb9b4 |
children | e9c5c368be17 |
comparison
equal
deleted
inserted
replaced
47499:9b1710c50230 | 47500:23f5ed6dbcb1 |
---|---|
3528 | 3528 |
3529 def _usecorrectpython(self): | 3529 def _usecorrectpython(self): |
3530 """Configure the environment to use the appropriate Python in tests.""" | 3530 """Configure the environment to use the appropriate Python in tests.""" |
3531 # Tests must use the same interpreter as us or bad things will happen. | 3531 # Tests must use the same interpreter as us or bad things will happen. |
3532 if sys.platform == 'win32': | 3532 if sys.platform == 'win32': |
3533 pyexename = b'python.exe' | 3533 pyexe_names = [b'python', b'python.exe'] |
3534 elif sys.version_info[0] < 3: | |
3535 pyexe_names = [b'python', b'python2'] | |
3534 else: | 3536 else: |
3535 pyexename = b'python3' # XXX this is wrong with python2... | 3537 pyexe_names = [b'python', b'python3'] |
3536 | 3538 |
3537 # os.symlink() is a thing with py3 on Windows, but it requires | 3539 # os.symlink() is a thing with py3 on Windows, but it requires |
3538 # Administrator rights. | 3540 # Administrator rights. |
3539 if getattr(os, 'symlink', None) and os.name != 'nt': | 3541 if getattr(os, 'symlink', None) and os.name != 'nt': |
3540 msg = "# Making python executable in test path a symlink to '%s'" | 3542 msg = "# Making python executable in test path a symlink to '%s'" |
3541 msg %= sysexecutable | 3543 msg %= sysexecutable |
3542 vlog(msg) | 3544 vlog(msg) |
3543 for pyexename in [pyexename]: | 3545 for pyexename in pyexe_names: |
3544 mypython = os.path.join(self._tmpbindir, pyexename) | 3546 mypython = os.path.join(self._tmpbindir, pyexename) |
3545 try: | 3547 try: |
3546 if os.readlink(mypython) == sysexecutable: | 3548 if os.readlink(mypython) == sysexecutable: |
3547 continue | 3549 continue |
3548 os.unlink(mypython) | 3550 os.unlink(mypython) |
3564 # launcher so the shebang lines work. | 3566 # launcher so the shebang lines work. |
3565 if os.getenv('MSYSTEM'): | 3567 if os.getenv('MSYSTEM'): |
3566 with open(osenvironb[b'RUNTESTDIR'] + b'/python3', 'wb') as f: | 3568 with open(osenvironb[b'RUNTESTDIR'] + b'/python3', 'wb') as f: |
3567 f.write(b'#!/bin/sh\n') | 3569 f.write(b'#!/bin/sh\n') |
3568 f.write(b'py -3.%d "$@"\n' % sys.version_info[1]) | 3570 f.write(b'py -3.%d "$@"\n' % sys.version_info[1]) |
3571 if os.getenv('MSYSTEM'): | |
3572 with open(osenvironb[b'RUNTESTDIR'] + b'/python2', 'wb') as f: | |
3573 f.write(b'#!/bin/sh\n') | |
3574 f.write(b'py -2.%d "$@"\n' % sys.version_info[1]) | |
3569 | 3575 |
3570 exedir, exename = os.path.split(sysexecutable) | 3576 exedir, exename = os.path.split(sysexecutable) |
3571 msg = "# Modifying search path to find %s as %s in '%s'" | 3577 for pyexename in pyexe_names: |
3572 msg %= (exename, pyexename, exedir) | 3578 msg = "# Modifying search path to find %s as %s in '%s'" |
3573 vlog(msg) | 3579 msg %= (exename, pyexename, exedir) |
3580 vlog(msg) | |
3574 path = os.environ['PATH'].split(os.pathsep) | 3581 path = os.environ['PATH'].split(os.pathsep) |
3575 while exedir in path: | 3582 while exedir in path: |
3576 path.remove(exedir) | 3583 path.remove(exedir) |
3577 | 3584 |
3578 # Binaries installed by pip into the user area like pylint.exe may | 3585 # Binaries installed by pip into the user area like pylint.exe may |
3596 ) | 3603 ) |
3597 | 3604 |
3598 extra_paths.append(scripts_dir) | 3605 extra_paths.append(scripts_dir) |
3599 | 3606 |
3600 os.environ['PATH'] = os.pathsep.join(extra_paths + path) | 3607 os.environ['PATH'] = os.pathsep.join(extra_paths + path) |
3601 if not self._findprogram(pyexename): | 3608 for pyexename in pyexe_names: |
3602 print("WARNING: Cannot find %s in search path" % pyexename) | 3609 if not self._findprogram(pyexename): |
3610 print("WARNING: Cannot find %s in search path" % pyexename) | |
3603 | 3611 |
3604 def _installhg(self): | 3612 def _installhg(self): |
3605 """Install hg into the test environment. | 3613 """Install hg into the test environment. |
3606 | 3614 |
3607 This will also configure hg with the appropriate testing settings. | 3615 This will also configure hg with the appropriate testing settings. |