Skip to main content

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

Project description

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)

input_filename is the full path to the pre-built extension module (.pyd file)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prebuilt_binaries-0.3.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file prebuilt_binaries-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prebuilt_binaries-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a142ca10ea8d480711bce6eadf768146fb7eb755c76d1e7a08c908b97c84315
MD5 2cf0011fbfa0e68df68c14c7f233449b
BLAKE2b-256 7ec4b5311a2c9c6d769b207e6133eccf29aaea2c984a13d869cc96a1b45fd1f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page