add Cython profiling option for later use (currently not working)

This commit is contained in:
Florian Förster 2025-10-23 13:55:24 +02:00
parent 26563dcfde
commit 4b42f0f03a
4 changed files with 972 additions and 60 deletions

View File

@ -53,6 +53,7 @@ log_cli = true
[tool.coverage.run]
relative_files = true
plugins = ["Cython.Coverage"]
source = [
"src/",
"tests/",

View File

@ -1,3 +1,5 @@
import os
from Cython.Build import cythonize
from Cython.Compiler import Options
from setuptools import setup
@ -13,8 +15,14 @@ ext_modules = cythonize(
"language_level": 3,
"embedsignature": False,
"annotation_typing": True,
"linetrace": True,
},
)
DEBUG = bool(os.getenv("DOPT_DEBUG", None))
if DEBUG:
ext_modules[0].define_macros.append(("CYTHON_TRACE", "1"))
setup(ext_modules=ext_modules)

File diff suppressed because it is too large Load Diff

View File

@ -74,7 +74,7 @@ def measure_length(
cnts = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
if cnts is None:
if cnts is None: # pragma: no cover
raise errors.ContourCalculationError(
"No contours were found in the provided image. Can not continue analysis."
)
@ -82,7 +82,7 @@ def measure_length(
cnts, _ = contours.sort_contours(cnts)
x_coords = [cv2.boundingRect(c)[0] for c in cnts]
is_sorted = np.all(x1 <= x2 for x1, x2 in zip(x_coords, x_coords[1:])) # type: ignore
if not is_sorted:
if not is_sorted: # pragma: no cover
raise errors.ContourCalculationError(
"Contour detection not valid: contours are not "
"properly sorted from left to right."
@ -128,13 +128,13 @@ def measure_length(
]
)
if not filtered_cnts:
if not filtered_cnts: # pragma: no cover
raise errors.ContourCalculationError(
"Contour detection not valid: no contours recognized"
)
num_contours = len(filtered_cnts)
if num_contours != const.NUM_VALID_ELECTRODES:
if num_contours != const.NUM_VALID_ELECTRODES: # pragma: no cover
raise errors.InvalidElectrodeCount(
f"Number of counted electrodes does not match the "
f"expected value: count = {num_contours}, expected = {const.NUM_VALID_ELECTRODES}"