|
| 1 | +# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 2 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 3 | +# |
| 4 | +# The Universal Permissive License (UPL), Version 1.0 |
| 5 | +# |
| 6 | +# Subject to the condition set forth below, permission is hereby granted to any |
| 7 | +# person obtaining a copy of this software, associated documentation and/or |
| 8 | +# data (collectively the "Software"), free of charge and under any and all |
| 9 | +# copyright rights in the Software, and any and all patent rights owned or |
| 10 | +# freely licensable by each licensor hereunder covering either (i) the |
| 11 | +# unmodified Software as contributed to or provided by such licensor, or (ii) |
| 12 | +# the Larger Works (as defined below), to deal in both |
| 13 | +# |
| 14 | +# (a) the Software, and |
| 15 | +# |
| 16 | +# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if |
| 17 | +# one is included with the Software each a "Larger Work" to which the Software |
| 18 | +# is contributed by such licensors), |
| 19 | +# |
| 20 | +# without restriction, including without limitation the rights to copy, create |
| 21 | +# derivative works of, display, perform, and distribute the Software and make, |
| 22 | +# use, sell, offer for sale, import, export, have made, and have sold the |
| 23 | +# Software and the Larger Work(s), and to sublicense the foregoing rights on |
| 24 | +# either these or other terms. |
| 25 | +# |
| 26 | +# This license is subject to the following condition: |
| 27 | +# |
| 28 | +# The above copyright notice and either this complete permission notice or at a |
| 29 | +# minimum a reference to the UPL must be included in all copies or substantial |
| 30 | +# portions of the Software. |
| 31 | +# |
| 32 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 33 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 34 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 35 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 36 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 37 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 38 | +# SOFTWARE. |
| 39 | + |
| 40 | +import argparse |
| 41 | +import os |
| 42 | +import shlex |
| 43 | +import shutil |
| 44 | +import subprocess |
| 45 | +from pathlib import Path |
| 46 | + |
| 47 | +DIR = Path(__file__).parent.parent |
| 48 | +DOWNSTREAM_TESTS = {} |
| 49 | + |
| 50 | + |
| 51 | +def run(*args, check=True, **kwargs): |
| 52 | + return subprocess.run(*args, check=check, **kwargs) |
| 53 | + |
| 54 | + |
| 55 | +def run_in_venv(venv, cmd, **kwargs): |
| 56 | + return run(['sh', '-c', f". {venv}/bin/activate && {shlex.join(cmd)}"], **kwargs) |
| 57 | + |
| 58 | + |
| 59 | +def downstream_test(name): |
| 60 | + def decorator(fn): |
| 61 | + DOWNSTREAM_TESTS[name] = fn |
| 62 | + return fn |
| 63 | + |
| 64 | + return decorator |
| 65 | + |
| 66 | + |
| 67 | +@downstream_test('hpy') |
| 68 | +def downstream_test_hpy(graalpy, args=None, env=None, check=True, timeout=None): |
| 69 | + testdir = Path('upstream-tests').absolute() |
| 70 | + shutil.rmtree(testdir, ignore_errors=True) |
| 71 | + testdir.mkdir(exist_ok=True) |
| 72 | + hpy_root = DIR / "graalpython" / "hpy" |
| 73 | + shutil.copytree(hpy_root, testdir / "hpy") |
| 74 | + hpy_root = testdir / "hpy" |
| 75 | + hpy_test_root = hpy_root / "test" |
| 76 | + venv = testdir / 'hpy_venv' |
| 77 | + run([graalpy, "-m", "venv", str(venv)]) |
| 78 | + run_in_venv(venv, ["pip", "install", "pytest", "pytest-xdist", "pytest-rerunfailures", "filelock"]) |
| 79 | + env = env or os.environ.copy() |
| 80 | + env["SETUPTOOLS_SCM_PRETEND_VERSION"] = "0.9.0" |
| 81 | + run_in_venv(venv, ["pip", "install", "-e", "."], cwd=str(hpy_root), env=env) |
| 82 | + parallelism = str(min(os.cpu_count(), int(os.cpu_count() / 4))) |
| 83 | + args = args or [] |
| 84 | + args = [ |
| 85 | + "python", |
| 86 | + "--vm.ea", |
| 87 | + "--experimental-options=true", |
| 88 | + "--python.EnableDebuggingBuiltins", |
| 89 | + *args, |
| 90 | + "-m", "pytest", |
| 91 | + "-v", |
| 92 | + # for those cases where testing invalid handles corrupts the process so |
| 93 | + # much that we crash - we don't recover gracefully in some cases :( |
| 94 | + "--reruns", "3", |
| 95 | + "-n", parallelism, |
| 96 | + str(hpy_test_root), |
| 97 | + # test_distutils is just slow and testing the build infrastructure |
| 98 | + "-k", "not test_distutils" |
| 99 | + ] |
| 100 | + return run_in_venv(venv, args, env=env, cwd=str(hpy_root), check=check, timeout=timeout) |
| 101 | + |
| 102 | + |
| 103 | +@downstream_test('pybind11') |
| 104 | +def downstream_test_pybind11(graalpy): |
| 105 | + testdir = Path('upstream-tests').absolute() |
| 106 | + shutil.rmtree(testdir, ignore_errors=True) |
| 107 | + testdir.mkdir(exist_ok=True) |
| 108 | + run(['git', 'clone', 'https://github.com/pybind/pybind11.git'], cwd=testdir) |
| 109 | + src = testdir / 'pybind11' |
| 110 | + venv = src / 'venv' |
| 111 | + run([graalpy, '-m', 'venv', str(venv)]) |
| 112 | + run_in_venv(venv, ['pip', 'install', 'pytest']) |
| 113 | + run_in_venv(venv, ['cmake', '-S', '.', '-B', 'build', '-DPYBIND11_WERROR=ON'], cwd=src) |
| 114 | + run_in_venv(venv, ['cmake', '--build', 'build', '--parallel'], cwd=src) |
| 115 | + env = os.environ.copy() |
| 116 | + env['PYTHONPATH'] = 'build/tests' |
| 117 | + run_in_venv(venv, ['pytest', '-v', '--tb=short', 'tests'], cwd=src, env=env) |
| 118 | + |
| 119 | + |
| 120 | +@downstream_test('virtualenv') |
| 121 | +def downstream_test_virtualenv(graalpy): |
| 122 | + testdir = Path('upstream-tests').absolute() |
| 123 | + shutil.rmtree(testdir, ignore_errors=True) |
| 124 | + testdir.mkdir(exist_ok=True) |
| 125 | + run(['git', 'clone', 'https://github.com/pypa/virtualenv.git', '-b', 'main'], cwd=testdir) |
| 126 | + src = testdir / 'virtualenv' |
| 127 | + venv = src / 'venv' |
| 128 | + run([graalpy, '-m', 'venv', str(venv)]) |
| 129 | + env = os.environ.copy() |
| 130 | + env.pop('VIRTUAL_ENV_DISABLE_PROMPT', None) |
| 131 | + env['CI_RUN'] = '1' |
| 132 | + # Need to avoid pulling in graalpy seeder |
| 133 | + env['PIP_GRAALPY_DISABLE_PATCHING'] = '1' |
| 134 | + run_in_venv(venv, ['pip', 'install', f'{src}[test]'], env=env) |
| 135 | + # Don't activate the venv, it interferes with the test |
| 136 | + run([ |
| 137 | + str(venv / 'bin' / 'pytest'), '-v', '--tb=short', 'tests', |
| 138 | + '-k', 'not fish and not csh and not nushell and not powershell', |
| 139 | + ], cwd=src, env=env) |
| 140 | + |
| 141 | + |
| 142 | +def run_downstream_test(python, project): |
| 143 | + DOWNSTREAM_TESTS[project](python) |
| 144 | + |
| 145 | + |
| 146 | +def main(): |
| 147 | + parser = argparse.ArgumentParser("Runs important upstream packages tests using their main branch") |
| 148 | + parser.add_argument("python") |
| 149 | + parser.add_argument("project", choices=sorted(DOWNSTREAM_TESTS)) |
| 150 | + args = parser.parse_args() |
| 151 | + run_downstream_test(args.python, args.project) |
| 152 | + |
| 153 | + |
| 154 | +if __name__ == '__main__': |
| 155 | + main() |
0 commit comments