CustomCompilerProtocol#

class scikitplot.cython.CustomCompilerProtocol(*args, **kwargs)[source]#

Structural protocol for custom compiler callables.

Any callable that satisfies this protocol can be registered with CompilerRegistry and used as a drop-in replacement or supplement to the default Cython/setuptools compiler.

Required interface:

name : str

Unique compiler name. Must start with custom_ or Custom.

__call__(source, *, build_dir, module_name, **kwargs) -> Path

Compile source and return the path to the built artifact.

Parameters:
sourcestr

Source code to compile (pyx, C, C++, or backend-specific).

build_dirpathlib.Path

Directory where intermediate and output files should be placed.

module_namestr

Desired Python module name for the compiled extension.

**kwargsAny

Additional keyword arguments forwarded from the build pipeline (e.g., include_dirs, extra_compile_args).

Returns:
pathlib.Path

Absolute path to the compiled artifact (.so / .pyd).

Raises:
RuntimeError

On compilation failure.

Notes

Naming rule: register your compiler with a name that starts with custom_ or Custom. The registry enforces this.

Stateless is preferred: make __call__ a pure function of its arguments. If state is needed (e.g., caching an include path), store it in constructor-set frozen dataclass fields.

Examples

Minimal custom compiler:

from pathlib import Path
from scikitplot.cython._custom_compiler import register_compiler

class custom_nvcc:
    name = "custom_nvcc"

    def __call__(
        self, source: str, *, build_dir: Path, module_name: str, **kwargs
    ) -> Path:
        # ... invoke nvcc here ...
        return build_dir / f"{module_name}.so"

register_compiler(custom_nvcc())
__call__(source, *, build_dir, module_name, **kwargs)[source]#

Compile source and return the artifact path.

Parameters:
Return type:

Path

name: str#