A short description of your project
Project description
cmake_pywhl
A CMake module for building Python wheels directly from CMake projects. It integrates compiled C/C++ extensions (via nanobind, pybind11, ctypes, etc.) and pure Python source files into PEP 427-compliant wheel archives, with full support for PEP 660 editable installs.
Requirements
- CMake 3.20+
- Python 3.12+
2. Integrate into your CMakeLists.txt
nanobind_add_module(_myext src/_myext.cpp)
# Declare a pywhl module (maps to a top-level Python package)
add_pywhl_module(mypackage
TARGETS _myext
SCRIPTS
# Can be individual files or folders
# Rules for files
folder1/file1.py # -> file1.py
folder4/file1.py@ext1 # -> ext1/file1.py
# Rules for folders
folder2 # folder2/subfolder1/file1.py -> subfolder/file1.py
folder3@ext1 # folder3/subfolder1/file1.py -> ext1/subfolder1/file1.py
)
# Create wheel and editable-install targets
add_pywhl_package(mypackage
VERSION "${PROJECT_VERSION}"
MODULES mypackage
LICENSE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
METADATA_FILE "${CMAKE_CURRENT_SOURCE_DIR}/METADATA"
)
3. Build
cmake -B build -DCMAKE_MODULE_PATH=/path/to/pywhl
cmake --build build # builds editable install (ALL target)
cmake --build build --target mypackage # builds the .whl file
The editable install target (mypackage_dev_whl) runs as part of ALL and installs import hooks into the active Python environment via a .pth file. The wheel target (mypackage) produces a distributable .whl archive.
API Reference
add_pywhl_module(name ...)
Registers a Python module (package directory) that will be included in a wheel.
| Parameter | Description |
|---|---|
TARGETS target1 ... |
CMake targets (compiled libraries or executables) whose output files are bundled |
SCRIPTS file_or_dir ... |
Python source files or directories; a directory with __init__.py is treated as a package |
DATA_FILES file ... |
Arbitrary data files to bundle |
EXCLUDE_REGEX pattern |
Regex pattern to exclude matching paths |
Scripts and data files can use src@dest syntax to rename items inside the wheel: mymodule/config.ini@config.ini.
add_pywhl_package(targetName ...)
Creates two CMake targets: a wheel-build target (targetName) and an editable-install target (default: targetName_dev_whl, runs as ALL).
| Parameter | Default | Description |
|---|---|---|
MODULES mod1 ... |
required | List of module names registered with add_pywhl_module |
VERSION x.y.z |
0.0.1 |
Wheel version |
LICENSE_FILE path |
./LICENSE |
License file (required) |
METADATA_FILE path |
./METADATA |
Package metadata template (Python string.Template syntax with ${name}, ${version}) |
ENTRY_POINTS_FILE path |
./entry_points.txt |
Console scripts / entry points |
EDITABLE_TARGET name |
targetName_dev_whl |
Override the editable target name |
whl_file_OUTVAR var |
— | CMake variable to receive the output wheel path |
METADATA template
The METADATA file is a Python string.Template supporting ${name} and ${version} substitutions:
Metadata-Version: 2.1
Name: ${name}
Version: ${version}
Summary: My package
Author: Your Name
License: MIT
entry_points.txt
Standard INI format accepted by pip:
[console_scripts]
my-tool = mypackage.cli:main
Project layout example
myproject/
├── CMakeLists.txt
├── LICENSE
├── METADATA
├── entry_points.txt # optional
├── src/
│ └── _myext.cpp # C++ nanobind extension
└── mypackage/
├── __init__.py # imports from _myext
└── helpers.py
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cmake_pywhl-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cmake_pywhl-0.0.2-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bac4dc06463a05989c207bbf4ddfcdf171a192e8df74b85db5fe5d92be009bee
|
|
| MD5 |
c7bf49f7ccf54dd2c7daa40d373c64ef
|
|
| BLAKE2b-256 |
deaa4fc1d072ceaea90e3d74fb85a794f6605bdbebe61420803d9e6b0f77b734
|
Provenance
The following attestation bundles were made for cmake_pywhl-0.0.2-py3-none-any.whl:
Publisher:
ci.yml on ankurvdev/cmake-pywhl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cmake_pywhl-0.0.2-py3-none-any.whl -
Subject digest:
bac4dc06463a05989c207bbf4ddfcdf171a192e8df74b85db5fe5d92be009bee - Sigstore transparency entry: 2043024301
- Sigstore integration time:
-
Permalink:
ankurvdev/cmake-pywhl@f4cb1290f70300e26916704c8c4070d838d53262 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/ankurvdev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f4cb1290f70300e26916704c8c4070d838d53262 -
Trigger Event:
push
-
Statement type: