CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-sip

A Python bindings generator for C and C++ libraries

Pending
Overview
Eval results
Files

build-integration.mddocs/

Build System Integration

PEP 517 build backend support and integration with modern Python packaging workflows. SIP provides seamless integration with pip, build tools, and CI/CD systems through standardized Python packaging interfaces.

Capabilities

PEP 517 Build Backend

SIP implements the PEP 517 build backend interface, enabling integration with modern Python packaging tools.

def build_sdist(sdist_directory, config_settings=None):
    """
    PEP 517 hook for building source distributions.
    
    Args:
        sdist_directory (str): Target directory for source distribution
        config_settings (dict, optional): Build configuration settings
        
    Returns:
        str: Filename of created source distribution
        
    Note:
        config_settings are currently ignored pending frontend support.
    """
    pass

def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
    """
    PEP 517 hook for building wheels.
    
    Args:
        wheel_directory (str): Target directory for wheel
        config_settings (dict, optional): Build configuration settings
        metadata_directory (str, optional): Directory containing prepared metadata
        
    Returns:
        str: Filename of created wheel
        
    Note:
        config_settings are currently ignored pending frontend support.
    """
    pass

Build System Configuration

Configure SIP as build backend in pyproject.toml:

[build-system]
requires = ["sip"]
build-backend = "sipbuild.api"

Factory Pattern Integration

SIP supports custom project and builder factories for extensibility:

class CustomProject(AbstractProject):
    """Custom project implementation."""
    pass

class CustomBuilder(AbstractBuilder):
    """Custom builder implementation."""
    pass

Configuration in pyproject.toml:

[tool.sip.project]
project-factory = "mypackage:CustomProject"
builder-factory = "mypackage:CustomBuilder"

Usage Examples

Standard Package Build

pyproject.toml:

[build-system]
requires = ["sip", "setuptools"]
build-backend = "sipbuild.api"

[project]
name = "mypackage"
version = "1.0.0"
description = "Python bindings for MyLib"
requires-python = ">=3.5"

[tool.sip.project]
build-dir = "build"

[tool.sip.bindings.mymodule]
sip-files = ["mymodule.sip"]
include-dirs = ["/usr/include/mylib"]
libraries = ["mylib"]

Build commands:

# Build wheel with pip
pip wheel .

# Build with build tool
python -m build

# Install directly
pip install .

Custom Build Process

# custom_build.py
from sipbuild import AbstractProject, AbstractBuilder

class MyProject(AbstractProject):
    def setup(self):
        # Custom setup logic
        super().setup()
        print("Setting up custom project")
    
    def build(self):
        # Custom build logic
        print("Building with custom process")
        super().build()

class MyBuilder(AbstractBuilder):
    def build(self):
        # Custom builder logic
        print("Using custom builder")
        super().build()

pyproject.toml:

[build-system]
requires = ["sip"]
build-backend = "sipbuild.api"

[tool.sip.project]
project-factory = "custom_build:MyProject"
builder-factory = "custom_build:MyBuilder"

CI/CD Integration

GitHub Actions example:

name: Build and Test
on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.9'
    
    - name: Install dependencies
      run: |
        pip install build sip
    
    - name: Build package
      run: python -m build
    
    - name: Test installation
      run: |
        pip install dist/*.whl
        python -c "import mymodule; print('Success!')"

Multi-Platform Builds

pyproject.toml with platform-specific configuration:

[tool.sip.project]
build-dir = "build"

# Windows-specific settings
[tool.sip.project.win32]
include-dirs = ["C:/MyLib/include"]
library-dirs = ["C:/MyLib/lib"]

# Linux-specific settings  
[tool.sip.project.linux]
include-dirs = ["/usr/include/mylib"]
library-dirs = ["/usr/lib"]

# macOS-specific settings
[tool.sip.project.darwin]
include-dirs = ["/usr/local/include/mylib"]
library-dirs = ["/usr/local/lib"]

Build Pipeline

Standard Build Process

  1. Configuration: Load pyproject.toml and apply settings
  2. Bootstrap: Create project and builder instances
  3. Generation: Process .sip files into C/C++ source
  4. Compilation: Compile generated source into extension modules
  5. Packaging: Create wheel or sdist with proper metadata

Error Handling

Build process errors are handled through SIP's standard exception system:

from sipbuild import handle_exception

try:
    # Build process
    project.build_wheel(wheel_directory)
except Exception as e:
    # Standard error handling and user-friendly messages
    handle_exception(e)

Build Artifacts

SIP generates several types of build artifacts:

  • Extension modules (.so/.pyd files) - Compiled binding code
  • sip module - Runtime support module
  • Type stubs (.pyi files) - Type information for IDEs
  • Documentation - API documentation and usage examples
  • Metadata - Package information and dependencies

Integration with Package Managers

pip Integration

# Install from source with pip
pip install .

# Install in development mode
pip install -e .

# Build wheel and install
pip wheel . && pip install *.whl

conda Integration

conda recipe example:

package:
  name: mypackage
  version: {{ environ.get('GIT_DESCRIBE_TAG', 'dev') }}

source:
  path: ..

build:
  script: {{ PYTHON }} -m pip install . -vv
  number: 0

requirements:
  build:
    - python
    - pip
    - sip
  run:
    - python

test:
  imports:
    - mymodule

setuptools Compatibility

SIP maintains compatibility with setuptools-based workflows:

# setup.py (legacy compatibility)
from setuptools import setup
from sipbuild import Project

# Use SIP project configuration
project = Project()
setup(
    name=project.name,
    version=project.version,
    ext_modules=project.get_bindings_modules()
)

This integration approach ensures SIP projects work seamlessly with existing Python packaging infrastructure while providing modern PEP 517 compliance.

Install with Tessl CLI

npx tessl i tessl/pypi-sip

docs

build-integration.md

cli-tools.md

configuration.md

core-api.md

index.md

tile.json