Skip to main content

A setuptools command for packaging pre-built binary python extension modules.

If you are already using cmake as your build tool, having to then build your library with setuptools in order to package it can be annoying.

prebuild_binaries allows you to pass an already built extension module (.pyd file) to setuptools for inclusion in a wheel.

Note that it is your responsibility to do this with the same python version as the file was created with - however this is pretty easy to get right when it’s part of the same build chain.

API

class PrebuiltExtension (input_filename, package=None)

input_filename is the full path to the pre-built extension module (.pyd file) The stem of input_filename is used for the name of the extension module.

If package is passed then the name of the extension module will be <package>.<name>

class prebuilt_binary

setuptools command class that takes PrebuiltExtension instances as parameters and copies the input file to the correct location. It is a replacement for the setuptools build_ext command.

Minimal setup.py example

import os
from setuptools import setup
from prebuilt_binaries import prebuilt_binary, PrebuiltExtension

ext_module = PrebuiltExtension(os.environ['PREBUILT_FILE'])

setup(
    name='my_package',
    version='version',
    cmdclass={
        'build_ext': prebuilt_binary,
    },
    ext_modules=[ext_module]
)

In this example the PREBUILT_FILE environment variable contains the desired path. The cmdclass mapping is required to tell setuptools to use the prebuilt_binary class to “build” the extensions specified in ext_modules.

CMakeLists.txt example

find_package(Python REQUIRED)

file(GLOB build_wheel_SOURCE_FILES pyproject.toml setup.py)

add_custom_target(build_wheel
    COMMAND ${CMAKE_COMMAND} -E env PREBUILT_FILE=$<TARGET_FILE:py_module> ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py bdist_wheel
    SOURCES ${build_wheel_SOURCE_FILES}
    )

add_dependencies(build_wheel py_module)

In this example cmake file py_module is the name of the target that builds the extension module. It sets the PREBUILT_FILE environment variable used by setup.py to the output file of the py_module target.

Build dependencies

Don’t forget to set prebuilt_binaries as a build-time dependancy in your pyproject.toml file:

[build-system]
requires = ["setuptools", "prebuilt_binaries"]

or in your setup.cfg file:

[options]
setup_requires =
    setuptools
    prebuilt_binaries

Release files for prebuilt-binaries 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prebuilt-binaries 0.5.0
File Size Uploaded
prebuilt-binaries-0.5.0.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prebuilt-binaries 0.5.0
File Interpreter ABI Platform
prebuilt_binaries-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size:8.1 kB

Release files / prebuilt-binaries-0.5.0.tar.gz

Download URL prebuilt-binaries-0.5.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1abdfd4f95ad2eada643db11b77145ecab9b309a5fc16e0a58e738c583fe9625
BLAKE2b-256 checksum
How to use checksums
2361d2e16ff4d33e76439594321a24c09be31b180ace41085e3d26aaef9636b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.0

Release files / prebuilt_binaries-0.5.0-py3-none-any.whl

Download URL prebuilt_binaries-0.5.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
859568868899044823cb31eb2523168faf51953044a9174a3e97fa4aabc572cf
BLAKE2b-256 checksum
How to use checksums
fc050fa7dab47fccac6dab4fd0322e79adb17d8a862db0e50cdf89843bf059a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page