Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build the wrapper lazily #19

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/pytest_codspeed/_wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from cffi import FFI # type: ignore
from filelock import FileLock

from .. import __version__

if TYPE_CHECKING:
from .wrapper import lib as LibType

Expand All @@ -24,13 +26,19 @@ def _get_ffi():

def get_lib() -> "LibType":
try:
ffi = _get_ffi()
build_lock = FileLock(f"{_wrapper_dir}/build.lock")
with build_lock:
ffi.compile(
target="dist_callgrind_wrapper.*",
tmpdir=_wrapper_dir,
is_target_already_built = any(
target.startswith(f"dist_callgrind_wrapper.{__version__}.")
for target in os.listdir(_wrapper_dir)
)
if not is_target_already_built:
ffi = _get_ffi()
ffi.compile(
target=f"dist_callgrind_wrapper.{__version__}.*",
tmpdir=_wrapper_dir,
)

from .dist_callgrind_wrapper import lib # type: ignore

return lib
Expand Down