diff --git a/pyproject.toml b/pyproject.toml index 2d3c054..2411b8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ classifiers = [ dependencies = [ "cffi ~= 1.15.1", "pytest>=3.8", + "filelock ~= 3.12.2", "setuptools ~= 67.8.0; python_full_version >= '3.12.0b1'", # FIXME: remove when cffi supports directly python 3.12 ] diff --git a/src/pytest_codspeed/_wrapper/__init__.py b/src/pytest_codspeed/_wrapper/__init__.py index 382a2b4..90e3fb3 100644 --- a/src/pytest_codspeed/_wrapper/__init__.py +++ b/src/pytest_codspeed/_wrapper/__init__.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING from cffi import FFI # type: ignore +from filelock import FileLock if TYPE_CHECKING: from .wrapper import lib as LibType @@ -24,10 +25,12 @@ def _get_ffi(): def get_lib() -> "LibType": try: ffi = _get_ffi() - ffi.compile( - target="dist_callgrind_wrapper.*", - tmpdir=_wrapper_dir, - ) + build_lock = FileLock(f"{_wrapper_dir}/build.lock") + with build_lock: + ffi.compile( + target="dist_callgrind_wrapper.*", + tmpdir=_wrapper_dir, + ) from .dist_callgrind_wrapper import lib # type: ignore return lib