CustomCompilerProtocol#
- class scikitplot.cython.CustomCompilerProtocol(*args, **kwargs)[source]#
Structural protocol for custom compiler callables.
Any callable that satisfies this protocol can be registered with
CompilerRegistryand used as a drop-in replacement or supplement to the default Cython/setuptools compiler.Required interface:
name : strUnique compiler name. Must start with
custom_orCustom.__call__(source, *, build_dir, module_name, **kwargs) -> PathCompile
sourceand 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_orCustom. 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-setfrozendataclass 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())