Improved build system generator for Python C/C++/Fortran/Cython extensions
npx @tessl/cli install tessl/pypi-scikit-build@0.18.0An improved build system generator for Python C/C++/Fortran/Cython extensions that serves as glue between setuptools and CMake. scikit-build provides enhanced build capabilities for projects that need to compile native code extensions, offering cross-platform compatibility and automated handling of complex build processes.
pip install scikit-buildfrom skbuild import setupBasic usage typically only requires importing the setup function:
from skbuild import setup, __version__For advanced configuration:
from skbuild import setup
from skbuild.constants import CMAKE_INSTALL_DIR, CMAKE_BUILD_DIR
from skbuild.exceptions import SKBuildErrorfrom skbuild import setup
setup(
name="my-extension",
version="1.0.0",
description="Python extension with C++ code",
author="Your Name",
# scikit-build specific options
cmake_args=["-DCMAKE_BUILD_TYPE=Release"],
cmake_source_dir="src",
cmake_install_dir="",
cmake_languages=["C", "CXX"],
# Standard setuptools options
packages=["my_extension"],
python_requires=">=3.7",
)scikit-build bridges the gap between Python's setuptools ecosystem and CMake's powerful build system capabilities through several key components:
This design enables developers to create and distribute Python packages that include compiled extensions while maintaining compatibility with modern Python packaging standards and providing robust tooling for managing dependencies, build configurations, and platform-specific compilation requirements across different operating systems and architectures.
Enhanced setup function that replaces setuptools.setup() with integrated CMake build system support. Handles CMake configuration, argument parsing, and build orchestration while maintaining full compatibility with setuptools features.
def setup(
*,
cmake_args: Sequence[str] = (),
cmake_install_dir: str = "",
cmake_source_dir: str = "",
cmake_with_sdist: bool = False,
cmake_languages: Sequence[str] = ("C", "CXX"),
cmake_minimum_required_version: str | None = None,
cmake_process_manifest_hook: Callable[[list[str]], list[str]] | None = None,
cmake_install_target: str = "install",
**kw: Any,
) -> upstream_DistributionDirect interface to CMake executable for project configuration, building, and installation. Provides programmatic access to CMake operations with Python integration for version detection, cache management, and platform-specific build handling.
class CMaker:
def __init__(self, cmake_executable: str = CMAKE_DEFAULT_EXECUTABLE) -> None: ...
def configure(self, clargs: Sequence[str] = (), generator_name: str | None = None, skip_generator_test: bool = False, cmake_source_dir: str = ".", cmake_install_dir: str = "", languages: Sequence[str] = ("C", "CXX"), cleanup: bool = True) -> dict[str, str]: ...
def make(self, clargs: Sequence[str] = (), config: str = "Release", source_dir: str = ".", install_target: str = "install", env: Mapping[str, str] | None = None) -> None: ...
def install(self) -> list[str]: ...Configuration constants, directory path functions, and utility functions for build management. Includes platform detection, directory creation, path manipulation, and build artifact management.
# Directory functions
def SKBUILD_DIR() -> str: ...
def CMAKE_BUILD_DIR() -> str: ...
def CMAKE_INSTALL_DIR() -> str: ...
# Platform functions
def skbuild_plat_name() -> str: ...
def set_skbuild_plat_name(plat_name: str) -> None: ...
# Utility functions
def mkdir_p(path: str) -> None: ...
def to_platform_path(path: OptStr) -> OptStr: ...
def to_unix_path(path: OptStr) -> OptStr: ...Exception classes for error handling during CMake configuration, building, and installation processes. Provides specific error types for different failure scenarios.
class SKBuildError(RuntimeError): ...
class SKBuildInvalidFileInstallationError(SKBuildError): ...
class SKBuildGeneratorNotFoundError(SKBuildError): ...Custom setuptools command classes that extend standard distutils/setuptools commands with CMake integration. These commands handle the build process orchestration between Python packaging and CMake.
class build: ...
class build_py: ...
class build_ext: ...
class install: ...
class clean: ...
class sdist: ...
class bdist_wheel: ...Platform-specific functionality for CMake generator detection, selection, and cross-platform build configuration. Provides automatic platform detection and generator compatibility testing.
def get_platform(): ...
class CMakeGenerator: ...
class CMakePlatform: ...# Type aliases from _compat.typing
Protocol: type
TypedDict: type
Final: type
Literal: type
NamedTuple: type
# External types from dependencies
upstream_Distribution = setuptools.dist.Distribution
Version = packaging.version.Version
# Optional string type
OptStr = str | None
# Version information types
version: str
__version__: str
version_tuple: tuple[int, int, int, str, str] | tuple[int, int, int]
__version_tuple__: tuple[int, int, int, str, str] | tuple[int, int, int]