From 56f35c53b0ef038031a66649e3dd1caa8cfc8d0e Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Sun, 1 Dec 2024 09:56:45 +0100 Subject: [PATCH] Fix `tests/run.py` handling of existing build directory --- tests/run.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tests/run.py b/tests/run.py index 6193f315..e1d58e5a 100644 --- a/tests/run.py +++ b/tests/run.py @@ -121,24 +121,29 @@ def create_test_workdir( test_workdir: Path, custom_gdextension_api: Optional[Path], ) -> None: - if test_workdir.exists(): + try: + # Check the directory exists and is not empty + next(test_workdir.iterdir()) print( f"{YELLOW}{test_dir.name}: workdir {test_workdir} already populated, leaving it as is{NO_COLOR}", flush=True, ) + return + except (FileNotFoundError, StopIteration): + pass + + print( + f"{YELLOW}{test_dir.name}: Create&populate test workdir in {test_workdir}{NO_COLOR}", + flush=True, + ) + shutil.copytree(test_dir, test_workdir, dirs_exist_ok=True, symlinks=True) + symlink(distrib_workdir / "addons", test_workdir / "addons") + shutil.copy(distrib_workdir / "pythonscript.gdextension", test_workdir) + # GDExtension headers are needed to compile Cython modules + if custom_gdextension_api: + shutil.copytree(custom_gdextension_api, test_workdir / "gdextension_api", symlinks=True) else: - print( - f"{YELLOW}{test_dir.name}: Create&populate test workdir in {test_workdir}{NO_COLOR}", - flush=True, - ) - shutil.copytree(test_dir, test_workdir, dirs_exist_ok=True, symlinks=True) - symlink(distrib_workdir / "addons", test_workdir / "addons") - shutil.copy(distrib_workdir / "pythonscript.gdextension", test_workdir) - # GDExtension headers are needed to compile Cython modules - if custom_gdextension_api: - shutil.copytree(custom_gdextension_api, test_workdir / "gdextension_api", symlinks=True) - else: - symlink(build_dir / "gdextension_api", test_workdir / "gdextension_api") + symlink(build_dir / "gdextension_api", test_workdir / "gdextension_api") build_script = test_workdir / "build.py" if build_script.exists():