CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-scikit-build

Improved build system generator for Python C/C++/Fortran/Cython extensions

Pending
Overview
Eval results
Files

setup-configuration.mddocs/

Setup and Configuration

Enhanced setup function and argument parsing utilities that replace setuptools.setup() with integrated CMake build system support. Handles CMake configuration, argument parsing, and build orchestration while maintaining full compatibility with setuptools features.

Capabilities

Enhanced Setup Function

The main entry point for scikit-build that replaces setuptools.setup() with CMake integration capabilities. Configures and builds C/C++/Fortran extensions using CMake while preserving all standard setuptools functionality.

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_Distribution:
    """
    Enhanced setuptools.setup() with CMake integration.
    
    Parameters:
    - cmake_args: Arguments passed to CMake configuration command
    - cmake_install_dir: Installation directory for CMake (relative to build directory)
    - cmake_source_dir: Source directory containing CMakeLists.txt (relative to setup.py directory)
    - cmake_with_sdist: Include CMake files in source distribution
    - cmake_languages: Languages to enable in CMake project (C, CXX, Fortran)
    - cmake_minimum_required_version: Minimum CMake version required for the project
    - cmake_process_manifest_hook: Function to process list of installed files
    - cmake_install_target: CMake target to use for installation (default: "install")
    - **kw: All standard setuptools.setup() arguments
    
    Returns:
    setuptools Distribution object
    """

Argument Parser Creation

Creates argument parser for scikit-build specific command-line options that can be used in setup scripts or command-line tools.

def create_skbuild_argparser() -> argparse.ArgumentParser:
    """
    Create and return a scikit-build argument parser.
    
    Includes options for:
    - --build-type: CMake build type (Debug/Release)
    - -G/--generator: CMake build system generator
    - -j: Number of parallel build jobs
    - --cmake-executable: Path to cmake executable
    - --install-target: CMake installation target
    - --skip-generator-test: Skip generator compatibility test
    
    Returns:
    ArgumentParser configured with scikit-build options
    """

Argument Parsing Functions

Parses scikit-build arguments and separates them from other command-line arguments for proper handling by the build system.

def parse_skbuild_args(
    args: Sequence[str], 
    cmake_args: Sequence[str], 
    build_tool_args: Sequence[str]
) -> tuple[list[str], str | None, bool, list[str], list[str]]:
    """
    Parse arguments in the scikit-build argument set.
    
    Converts specified arguments to proper format and appends to cmake_args 
    and build_tool_args.
    
    Parameters:
    - args: Input arguments to parse
    - cmake_args: Existing CMake arguments to extend
    - build_tool_args: Existing build tool arguments to extend
    
    Returns:
    Tuple of (remaining_args, cmake_executable, skip_generator_test, 
             updated_cmake_args, updated_build_tool_args)
    """

def parse_args() -> tuple[list[str], str | None, bool, list[str], list[str]]:
    """
    Parse command-line arguments sys.argv and return argument sets.
    
    Automatically parses sys.argv and separates scikit-build arguments
    from other arguments.
    
    Returns:
    Tuple of (remaining_args, cmake_executable, skip_generator_test,
             cmake_args, build_tool_args)
    """

Package Data Configuration

Determines default behavior for including package data files based on project configuration.

def get_default_include_package_data() -> bool:
    """
    Include package data if pyproject.toml contains project or tool.setuptools table.
    
    Checks pyproject.toml for modern Python packaging configuration and returns
    appropriate default for include_package_data parameter.
    
    Returns:
    True if package data should be included by default, False otherwise
    """

Utility Functions

Helper functions for processing package paths and file organization during the build process.

def strip_package(package_parts: Sequence[str], module_file: str) -> str:
    """
    Strip package prefix from module file paths.
    
    Removes package directory components from file paths to get relative
    module paths for installation.
    
    Parameters:
    - package_parts: List of package directory components
    - module_file: Full path to module file
    
    Returns:
    Relative module file path with package prefix removed
    """

Usage Examples

Basic Extension Setup

from skbuild import setup

setup(
    name="my_extension",
    version="1.0.0",
    description="C++ extension for Python",
    cmake_source_dir="src",
    cmake_args=[
        "-DCMAKE_BUILD_TYPE=Release",
        "-DPYTHON_EXECUTABLE=" + sys.executable,
    ],
    packages=["my_extension"],
    python_requires=">=3.7",
)

Advanced Configuration

from skbuild import setup
import sys

def process_manifest(files):
    # Custom processing of installed files
    return [f for f in files if not f.endswith('.debug')]

setup(
    name="complex_extension", 
    version="2.0.0",
    cmake_source_dir="native",
    cmake_install_dir="lib",
    cmake_languages=["C", "CXX", "Fortran"],
    cmake_minimum_required_version="3.15",
    cmake_process_manifest_hook=process_manifest,
    cmake_args=[
        "-DCMAKE_BUILD_TYPE=Release",
        "-DENABLE_OPTIMIZATIONS=ON",
        f"-DPYTHON_EXECUTABLE={sys.executable}",
    ],
    cmake_with_sdist=True,
    packages=["complex_extension"],
    package_data={"complex_extension": ["*.so", "*.dll", "*.dylib"]},
)

Command-Line Argument Handling

from skbuild import parse_args, setup

# Parse command-line arguments
remaining_args, cmake_exe, skip_test, cmake_args, build_args = parse_args()

setup(
    name="my_package",
    cmake_args=cmake_args,
    # ... other setup arguments
)

Install with Tessl CLI

npx tessl i tessl/pypi-scikit-build

docs

build-commands.md

cmake-interface.md

constants-utilities.md

exception-handling.md

index.md

platform-integration.md

setup-configuration.md

tile.json