Skip to main content

A utility to initialize basic CMake C++ / pybind11 projects.

Project description

pycpp-tools

A command-line utility to initialize basic CMake C++ / pybind11 projects.

Features

  • Initialize a CMake C++ project (CMake 3.30, C++23, Ninja)
  • Initialize a pure C project (--pure-c)
  • Initialize a pybind11 project (--pybind11)
  • Generate VS Code tasks.json / launch.json (CodeLLDB + clangd workflow)

Installation

pip install .
# or editable mode
pip install -e .

After installation, the pycpp command is available.

Usage

CMake C++ Project

pycpp init --name myproject

Generates: src/main.cpp, CMakeLists.txt, .vscode/tasks.json (config / build / run), .vscode/launch.json.

Pure C Project

pycpp init --name myproject --pure-c

Pybind11 Project

pycpp init --name demo --pybind11

Naming:

  • --name: C++ extension module name (default: demo)
  • Python package name / directory: py + name (e.g. pydemosrc/pydemo/)
  • Import: from pydemo import demo

Generated layout:

Path Description
cpp-src/pywrapper.cpp C++ / pybind11 sources
src/pydemo/__init__.py Empty package init
src/pydemo/demo.pyi Stub for the extension module
CMakeLists.txt Extension output under src/<package>/; paths injected via -D
pyproject.toml [tool.pycpp], package-data; requires-python = "==X.Y.*"
setup.py Marks a binary distribution so the wheel gets cp3xx-<plat> tags
scripts/cmake-config.py Reads toml and passes -D flags to cmake
scripts/clear.py Cleans build artifacts and extension binaries
scripts/package.py clear → config → cmake build → python -m build (uses Python from [tool.pycpp].python_dir)
test.py from pydemo import demo
.vscode/tasks.json config / build / run / clear / package
.vscode/launch.json debugpy + CodeLLDB

Default [tool.pycpp] fields:

[tool.pycpp]
python_dir = "..."          # current env sys.prefix
pybind11_dir = "..."        # .../share/cmake/pybind11
python_version = "3.13"
build_type = "Release"
cxx_standard = 23
cxx_compile = "clang-cl"
generator = "Ninja"

After editing toml, re-run config / package to apply changes (including output dir from [project].name).

Options:

  • --name <name>: C++ module name; Python package is py{name}
  • --pybind11: initialize as a pybind11 project
  • --pure-c: pure C project
  • --inplace-vscode: force overwrite existing .vscode tasks/launch files

Develop and debug

python scripts/cmake-config.py
cmake --build build
pip install -e .
python test.py

Or use VS Code tasks: configbuildrun.
Use pip install -e . for imports and IDE hints; no sys.path hacks in test.py.

Package and publish

Build the extension in the repo first, then package (no on-the-fly cmake inside the wheel build):

python scripts/package.py
# or VS Code task: package

Flow: clear → cmake configure/build → python -m build.
package.py switches to the interpreter under [tool.pycpp].python_dir so wheel tags (e.g. cp313-cp313-win_amd64) match the Python used for compilation.

Requires build (and setuptools from the generated project's build-system) in that environment.

Requirements

  • Python 3.13+ (for this tool)
  • CMake 3.30+
  • C++23-capable compiler (default: clang-cl)
  • Ninja
  • VS Code extensions:
    • CodeLLDB — C/C++ debugging
    • clangd — C/C++ IntelliSense (go-to-definition, completion, etc.; uses compile_commands.json from cmake config)

License

MIT License

Author

R.E. (redelephant@foxmail.com)

Project details


Download files

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

Source Distribution

pycpp_tools-0.4.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

pycpp_tools-0.4.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pycpp_tools-0.4.1.tar.gz.

File metadata

  • Download URL: pycpp_tools-0.4.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pycpp_tools-0.4.1.tar.gz
Algorithm Hash digest
SHA256 57a227a892c3a8543e8a30cd32bb8e740c31bc9b1c60b4e68d55ed45dca6fed4
MD5 b3c30fd4e9ce2299413f735372ef6ffc
BLAKE2b-256 44a0efb5434b1f6481ea0e927867feea64581d19442884f5a597a9325a3873e7

See more details on using hashes here.

File details

Details for the file pycpp_tools-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: pycpp_tools-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pycpp_tools-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f03b03b2aa536e7233f32f8bae44f8b1982632613772e76e85df2723e4acd497
MD5 98c558a41af53392c5c39ac0a00ffdec
BLAKE2b-256 9d1e49a75d9dcffafb203d208332423608d486aeea2cb5bbd0a4df2e7a503b81

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