A Python bindings generator for C and C++ libraries
—
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.
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.
"""
passConfigure SIP as build backend in pyproject.toml:
[build-system]
requires = ["sip"]
build-backend = "sipbuild.api"SIP supports custom project and builder factories for extensibility:
class CustomProject(AbstractProject):
"""Custom project implementation."""
pass
class CustomBuilder(AbstractBuilder):
"""Custom builder implementation."""
passConfiguration in pyproject.toml:
[tool.sip.project]
project-factory = "mypackage:CustomProject"
builder-factory = "mypackage:CustomBuilder"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.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"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!')"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 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)SIP generates several types of build artifacts:
# Install from source with pip
pip install .
# Install in development mode
pip install -e .
# Build wheel and install
pip wheel . && pip install *.whlconda 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:
- mymoduleSIP 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