Mercurial > hg
comparison tests/run-tests.py @ 52148:1dbbb957bbe6 stable
run-tests: add a --hg-wheel options to test a pre-built wheel
This will be useful to test the wheel we intend to publish.
A future changeset will integrate this in the CI.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 27 Oct 2024 08:54:48 +0100 |
parents | 6f7cc970bfda |
children |
comparison
equal
deleted
inserted
replaced
52147:6f7cc970bfda | 52148:1dbbb957bbe6 |
---|---|
59 import random | 59 import random |
60 import re | 60 import re |
61 import shlex | 61 import shlex |
62 import shutil | 62 import shutil |
63 import signal | 63 import signal |
64 import site | |
64 import socket | 65 import socket |
65 import subprocess | 66 import subprocess |
66 import sys | 67 import sys |
67 import sysconfig | 68 import sysconfig |
68 import tempfile | 69 import tempfile |
621 ) | 622 ) |
622 hgconf.add_argument( | 623 hgconf.add_argument( |
623 "--ipv6", | 624 "--ipv6", |
624 action="store_true", | 625 action="store_true", |
625 help="prefer IPv6 to IPv4 for network related tests", | 626 help="prefer IPv6 to IPv4 for network related tests", |
627 ) | |
628 hgconf.add_argument( | |
629 "--hg-wheel", | |
630 default=None, | |
631 metavar="WHEEL_PATH", | |
632 dest="wheel", | |
633 help="install mercurial from the given wheel", | |
626 ) | 634 ) |
627 hgconf.add_argument( | 635 hgconf.add_argument( |
628 "--pure", | 636 "--pure", |
629 action="store_true", | 637 action="store_true", |
630 help="use pure Python code instead of C extensions", | 638 help="use pure Python code instead of C extensions", |
3217 self._custom_bin_dir = os.path.join(self._hgtmp, b'custom-bin') | 3225 self._custom_bin_dir = os.path.join(self._hgtmp, b'custom-bin') |
3218 os.makedirs(self._custom_bin_dir) | 3226 os.makedirs(self._custom_bin_dir) |
3219 | 3227 |
3220 # detect and enforce an alternative way to specify rust extension usage | 3228 # detect and enforce an alternative way to specify rust extension usage |
3221 if ( | 3229 if ( |
3222 not (self.options.pure or self.options.rust or self.options.no_rust) | 3230 not ( |
3231 self.options.wheel | |
3232 or self.options.pure | |
3233 or self.options.rust | |
3234 or self.options.no_rust | |
3235 ) | |
3223 and os.environ.get("HGWITHRUSTEXT") == "cpython" | 3236 and os.environ.get("HGWITHRUSTEXT") == "cpython" |
3224 ): | 3237 ): |
3225 self.options.rust = True | 3238 self.options.rust = True |
3226 | 3239 |
3227 if self.options.with_hg: | 3240 if self.options.with_hg: |
3255 | 3268 |
3256 else: | 3269 else: |
3257 self._installdir = os.path.join(self._hgtmp, b"install") | 3270 self._installdir = os.path.join(self._hgtmp, b"install") |
3258 self._bindir = os.path.join(self._installdir, b"bin") | 3271 self._bindir = os.path.join(self._installdir, b"bin") |
3259 self._hgcommand = b'hg' | 3272 self._hgcommand = b'hg' |
3260 self._pythondir = os.path.join(self._installdir, b"lib", b"python") | 3273 |
3274 if self.options.wheel: | |
3275 suffix = _sys2bytes(site.USER_SITE[len(site.USER_BASE) + 1 :]) | |
3276 else: | |
3277 suffix = os.path.join(b"lib", b"python") | |
3278 self._pythondir = os.path.join(self._installdir, suffix) | |
3261 | 3279 |
3262 # Force the use of hg.exe instead of relying on MSYS to recognize hg is | 3280 # Force the use of hg.exe instead of relying on MSYS to recognize hg is |
3263 # a python script and feed it to python.exe. Legacy stdio is force | 3281 # a python script and feed it to python.exe. Legacy stdio is force |
3264 # enabled by hg.exe, and this is a more realistic way to launch hg | 3282 # enabled by hg.exe, and this is a more realistic way to launch hg |
3265 # anyway. | 3283 # anyway. |
3780 f.write(b'%s "$@"\n' % _sys2bytes(escaped_exec)) | 3798 f.write(b'%s "$@"\n' % _sys2bytes(escaped_exec)) |
3781 else: | 3799 else: |
3782 os.symlink(real_exec, target_exec) | 3800 os.symlink(real_exec, target_exec) |
3783 self._createdfiles.append(target_exec) | 3801 self._createdfiles.append(target_exec) |
3784 | 3802 |
3785 def _installhg(self): | 3803 def _install_hg_cmd_wheel(self): |
3786 """Install hg into the test environment. | 3804 wheel_path = self.options.wheel |
3787 | 3805 assert wheel_path |
3788 This will also configure hg with the appropriate testing settings. | 3806 |
3789 """ | 3807 # TODO: actually use these flag later, to double check the wheel we |
3790 vlog("# Performing temporary installation of HG") | 3808 # installed match our intend (in `_checkhglib`) |
3791 installerrs = os.path.join(self._hgtmp, b"install.err") | 3809 if self.options.pure: |
3792 install_env = original_env.copy() | 3810 assert False, b"--pure" |
3811 elif self.options.rust: | |
3812 assert False, b"--rust" | |
3813 elif self.options.no_rust: | |
3814 assert False, b"--no-rust" | |
3815 | |
3816 script = _sys2bytes(os.path.realpath(sys.argv[0])) | |
3817 exe = _sys2bytes(sysexecutable) | |
3818 hgroot = os.path.dirname(os.path.dirname(script)) | |
3819 self._hgroot = hgroot | |
3820 os.chdir(hgroot) | |
3821 cmd = [ | |
3822 exe, | |
3823 b"-m", | |
3824 b"pip", | |
3825 b"install", | |
3826 wheel_path, | |
3827 b"--force", | |
3828 b"--ignore-installed", | |
3829 b"--user", | |
3830 b"--break-system-packages", | |
3831 ] | |
3832 if not WINDOWS: | |
3833 # The --home="" trick works only on OS where os.sep == '/' | |
3834 # because of a distutils convert_path() fast-path. Avoid it at | |
3835 # least on Windows for now, deal with .pydistutils.cfg bugs | |
3836 # when they happen. | |
3837 # cmd.append(b"--global-option=--home=") | |
3838 pass | |
3839 | |
3840 return cmd | |
3841 | |
3842 def _install_hg_cmd_setup(self): | |
3843 # Run installer in hg root | |
3793 setup_opts = b"" | 3844 setup_opts = b"" |
3794 if self.options.pure: | 3845 if self.options.pure: |
3795 setup_opts = b"--pure" | 3846 setup_opts = b"--pure" |
3796 install_env.pop('HGWITHRUSTEXT', None) | |
3797 elif self.options.rust: | 3847 elif self.options.rust: |
3798 setup_opts = b"--rust" | 3848 setup_opts = b"--rust" |
3799 elif self.options.no_rust: | 3849 elif self.options.no_rust: |
3800 setup_opts = b"--no-rust" | 3850 setup_opts = b"--no-rust" |
3801 install_env.pop('HGWITHRUSTEXT', None) | 3851 |
3802 | |
3803 # Run installer in hg root | |
3804 script = _sys2bytes(os.path.realpath(sys.argv[0])) | 3852 script = _sys2bytes(os.path.realpath(sys.argv[0])) |
3805 exe = _sys2bytes(sysexecutable) | 3853 exe = _sys2bytes(sysexecutable) |
3806 hgroot = os.path.dirname(os.path.dirname(script)) | 3854 hgroot = os.path.dirname(os.path.dirname(script)) |
3807 self._hgroot = hgroot | 3855 self._hgroot = hgroot |
3808 os.chdir(hgroot) | 3856 os.chdir(hgroot) |
3837 # because of a distutils convert_path() fast-path. Avoid it at | 3885 # because of a distutils convert_path() fast-path. Avoid it at |
3838 # least on Windows for now, deal with .pydistutils.cfg bugs | 3886 # least on Windows for now, deal with .pydistutils.cfg bugs |
3839 # when they happen. | 3887 # when they happen. |
3840 cmd.append(b"--home=") | 3888 cmd.append(b"--home=") |
3841 | 3889 |
3890 return cmd | |
3891 | |
3892 def _installhg(self): | |
3893 """Install hg into the test environment. | |
3894 | |
3895 This will also configure hg with the appropriate testing settings. | |
3896 """ | |
3897 vlog("# Performing temporary installation of HG") | |
3898 install_env = original_env.copy() | |
3899 if self.options.wheel is None: | |
3900 cmd = self._install_hg_cmd_setup() | |
3901 else: | |
3902 cmd = self._install_hg_cmd_wheel() | |
3903 install_env["PYTHONUSERBASE"] = _bytes2sys(self._installdir) | |
3904 | |
3905 installerrs = os.path.join(self._hgtmp, b"install.err") | |
3906 if self.options.pure: | |
3907 install_env.pop('HGWITHRUSTEXT', None) | |
3908 elif self.options.no_rust: | |
3909 install_env.pop('HGWITHRUSTEXT', None) | |
3910 | |
3842 # setuptools requires install directories to exist. | 3911 # setuptools requires install directories to exist. |
3843 def makedirs(p): | 3912 def makedirs(p): |
3844 try: | 3913 try: |
3845 os.makedirs(p) | 3914 os.makedirs(p) |
3846 except FileExistsError: | 3915 except FileExistsError: |
3848 | 3917 |
3849 makedirs(self._pythondir) | 3918 makedirs(self._pythondir) |
3850 makedirs(self._bindir) | 3919 makedirs(self._bindir) |
3851 | 3920 |
3852 vlog("# Running", cmd) | 3921 vlog("# Running", cmd) |
3853 print(cmd) | |
3854 with open(installerrs, "wb") as logfile: | 3922 with open(installerrs, "wb") as logfile: |
3855 r = subprocess.call( | 3923 r = subprocess.call( |
3856 cmd, | 3924 cmd, |
3857 env=install_env, | 3925 env=install_env, |
3858 stdout=logfile, | 3926 stdout=logfile, |