|
| 1 | +# SPDX-FileCopyrightText: 2021 The meson-python developers |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import os |
| 6 | +import shutil |
| 7 | + |
| 8 | +import mesonpy |
| 9 | + |
| 10 | + |
| 11 | +def test_editable( |
| 12 | + package_imports_itself_during_build, |
| 13 | + editable_imports_itself_during_build, |
| 14 | + venv, |
| 15 | +): |
| 16 | + venv.pip('install', os.fspath(editable_imports_itself_during_build)) |
| 17 | + |
| 18 | + assert venv.python('-c', 'import plat; print(plat.foo())').strip() == 'bar' |
| 19 | + |
| 20 | + plat = package_imports_itself_during_build / 'plat.c' |
| 21 | + plat_text = plat.read_text() |
| 22 | + try: |
| 23 | + plat.write_text(plat_text.replace('bar', 'something else')) |
| 24 | + |
| 25 | + assert venv.python('-c', 'import plat; print(plat.foo())').strip() == 'something else' |
| 26 | + finally: |
| 27 | + plat.write_text(plat_text) |
| 28 | + |
| 29 | + |
| 30 | +def test_editable_broken_non_existent_build_dir( |
| 31 | + package_imports_itself_during_build, |
| 32 | + editable_imports_itself_during_build, |
| 33 | + venv, |
| 34 | + tmp_path, |
| 35 | +): |
| 36 | + # Start from a clean slate, copy the package to temp path |
| 37 | + # Ensure there is no .mesonpy directory (could be generated by test_editable) |
| 38 | + shutil.rmtree(tmp_path) # copytree requires dest not to exist |
| 39 | + shutil.copytree(package_imports_itself_during_build, tmp_path) |
| 40 | + mesonpy_dir = os.path.join(package_imports_itself_during_build, '.mesonpy') |
| 41 | + if os.path.isdir(mesonpy_dir): |
| 42 | + venv.pip('uninstall', '-y', 'imports-itself-during-build') |
| 43 | + shutil.rmtree(mesonpy_dir) |
| 44 | + |
| 45 | + venv.pip('install', os.path.join(tmp_path, mesonpy.build_editable(tmp_path))) |
| 46 | + |
| 47 | + # Try corrupting the build dir, |
| 48 | + # removing the build dir after an install will trigger it |
| 49 | + if os.path.isdir(mesonpy_dir): |
| 50 | + venv.pip('uninstall', '-y', 'imports-itself-during-build') |
| 51 | + shutil.rmtree(mesonpy_dir) |
| 52 | + |
| 53 | + venv.pip('install', os.path.join(tmp_path, mesonpy.build_editable(tmp_path))) |
| 54 | + |
| 55 | + assert venv.python('-c', 'import plat; print(plat.foo())').strip() == 'bar' |
0 commit comments