Mercurial > hg
diff 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 |
line wrap: on
line diff
--- a/tests/run-tests.py Sun Oct 27 08:54:43 2024 +0100 +++ b/tests/run-tests.py Sun Oct 27 08:54:48 2024 +0100 @@ -61,6 +61,7 @@ import shlex import shutil import signal +import site import socket import subprocess import sys @@ -625,6 +626,13 @@ help="prefer IPv6 to IPv4 for network related tests", ) hgconf.add_argument( + "--hg-wheel", + default=None, + metavar="WHEEL_PATH", + dest="wheel", + help="install mercurial from the given wheel", + ) + hgconf.add_argument( "--pure", action="store_true", help="use pure Python code instead of C extensions", @@ -3219,7 +3227,12 @@ # detect and enforce an alternative way to specify rust extension usage if ( - not (self.options.pure or self.options.rust or self.options.no_rust) + not ( + self.options.wheel + or self.options.pure + or self.options.rust + or self.options.no_rust + ) and os.environ.get("HGWITHRUSTEXT") == "cpython" ): self.options.rust = True @@ -3257,7 +3270,12 @@ self._installdir = os.path.join(self._hgtmp, b"install") self._bindir = os.path.join(self._installdir, b"bin") self._hgcommand = b'hg' - self._pythondir = os.path.join(self._installdir, b"lib", b"python") + + if self.options.wheel: + suffix = _sys2bytes(site.USER_SITE[len(site.USER_BASE) + 1 :]) + else: + suffix = os.path.join(b"lib", b"python") + self._pythondir = os.path.join(self._installdir, suffix) # Force the use of hg.exe instead of relying on MSYS to recognize hg is # a python script and feed it to python.exe. Legacy stdio is force @@ -3782,25 +3800,55 @@ os.symlink(real_exec, target_exec) self._createdfiles.append(target_exec) - def _installhg(self): - """Install hg into the test environment. - - This will also configure hg with the appropriate testing settings. - """ - vlog("# Performing temporary installation of HG") - installerrs = os.path.join(self._hgtmp, b"install.err") - install_env = original_env.copy() + def _install_hg_cmd_wheel(self): + wheel_path = self.options.wheel + assert wheel_path + + # TODO: actually use these flag later, to double check the wheel we + # installed match our intend (in `_checkhglib`) + if self.options.pure: + assert False, b"--pure" + elif self.options.rust: + assert False, b"--rust" + elif self.options.no_rust: + assert False, b"--no-rust" + + script = _sys2bytes(os.path.realpath(sys.argv[0])) + exe = _sys2bytes(sysexecutable) + hgroot = os.path.dirname(os.path.dirname(script)) + self._hgroot = hgroot + os.chdir(hgroot) + cmd = [ + exe, + b"-m", + b"pip", + b"install", + wheel_path, + b"--force", + b"--ignore-installed", + b"--user", + b"--break-system-packages", + ] + if not WINDOWS: + # The --home="" trick works only on OS where os.sep == '/' + # because of a distutils convert_path() fast-path. Avoid it at + # least on Windows for now, deal with .pydistutils.cfg bugs + # when they happen. + # cmd.append(b"--global-option=--home=") + pass + + return cmd + + def _install_hg_cmd_setup(self): + # Run installer in hg root setup_opts = b"" if self.options.pure: setup_opts = b"--pure" - install_env.pop('HGWITHRUSTEXT', None) elif self.options.rust: setup_opts = b"--rust" elif self.options.no_rust: setup_opts = b"--no-rust" - install_env.pop('HGWITHRUSTEXT', None) - - # Run installer in hg root + script = _sys2bytes(os.path.realpath(sys.argv[0])) exe = _sys2bytes(sysexecutable) hgroot = os.path.dirname(os.path.dirname(script)) @@ -3839,6 +3887,27 @@ # when they happen. cmd.append(b"--home=") + return cmd + + def _installhg(self): + """Install hg into the test environment. + + This will also configure hg with the appropriate testing settings. + """ + vlog("# Performing temporary installation of HG") + install_env = original_env.copy() + if self.options.wheel is None: + cmd = self._install_hg_cmd_setup() + else: + cmd = self._install_hg_cmd_wheel() + install_env["PYTHONUSERBASE"] = _bytes2sys(self._installdir) + + installerrs = os.path.join(self._hgtmp, b"install.err") + if self.options.pure: + install_env.pop('HGWITHRUSTEXT', None) + elif self.options.no_rust: + install_env.pop('HGWITHRUSTEXT', None) + # setuptools requires install directories to exist. def makedirs(p): try: @@ -3850,7 +3919,6 @@ makedirs(self._bindir) vlog("# Running", cmd) - print(cmd) with open(installerrs, "wb") as logfile: r = subprocess.call( cmd,