Skip to main content

Binding for wood project that is compiled into a binding using nanobind and scikit-build

Project description

wood_nano

Repository wood_nano has submodule wood in src directly. For new clones incase there is nothing in the src/wood folder do the following:

  •   git submodule update --init --recursive
    
CI status
pip builds Pip Action Status
wheels Wheel Action Status

This repository contains a tiny project showing how to create C++ bindings using nanobind and scikit-build-core. It was derived from the corresponding pybind11 example project developed by @henryiii.

Installation

  1. Clone this repository
  2. Run pip install ./wood_nano

CI Examples

The .github/workflows directory contains two continuous integration workflows for GitHub Actions. The first one (pip) runs automatically after each commit and ensures that packages can be built successfully and that tests pass.

The wheels workflow uses cibuildwheel to automatically produce binary wheels for a large variety of platforms. If a pypi_password token is provided using GitHub Action's secrets feature, this workflow can even automatically upload packages on PyPI.

Customization

Conda

conda config --add channels conda-forge
conda create -n wood python==3.8.16 pypy=7.3.11

Rhino ScriptEditor

C:/Users/petras/.rhinocode/py39-rh8/python.exe -m pip install . 
import os
import os.path as op
import sys
import ctypes

CONDA_ENV = r'C:\Users\petras\.conda\envs\wood'
COMPAS_WOOD_PATH = r'C:\brg\2_code\wood_nano\build\pp38-pypy38_pp73-win_amd64\Release'
sys.path.append(op.join(CONDA_ENV, r"Lib\site-packages"))
sys.path.append(COMPAS_WOOD_PATH)
os.add_dll_directory(op.join(CONDA_ENV, r'Library\bin'))
os.add_dll_directory(COMPAS_WOOD_PATH)

import nanobind_example
print(nanobind_example.add(1, 2))

Wood submodule and download dependecies

cd ~/brg/2_code/wood_nano/src
git submodule add https://github.com/petrasvestartas/wood.git
cd wood
sudo '/home/petras/brg/2_code/wood_nano/src/wood/install_ubuntu.sh'

For update:

git submodule update --init --recursive
# git submodule foreach git pull origin main
sudo rm -r build

Link wood dependencies to nanobind

  • Ubuntu - linked, Check: a) PCH is not speeding the build, b) SQL has no be unlocked like this sudo chown -R, be aware that the .sh file installs gmp and mpfr in ubuntu, not as a cmake source code.
  • Windows - linked, Check: a) C:\Users\petras.conda\envs\wood\Lib\site-packages\wood_nano must have cgal libgmp-10.dll and libmpfr-4.dll, it would be great that gmp and mpfr would be compiled together into one single .pyd file.
  • Mac - not linked

pip

conda create -n compas_wood_3_9_10 python==3.9.10 build setuptools wheel twine auditwheel
ubuntu:
export BUILDING_DIST="1" && python -m build --wheel
sudo apt-get install patchelf
sudo docker build -t manylinux2014_gcc13 .
auditwheel repair dist/wood_nano-0.0.7-cp39-cp39-linux_x86_64.whl --plat manylinux_2_35_x86_64 -w dist/
windows:
conda create -n compas_wood_3_9_10 python==3.9.10 build setuptools wheel twine
python -m build --wheel

Code wrapping

  • for development you need to use pip install . and even you changed init.py
  • function based on the EDX tutorial
  • Process: - add c++ and binded method in nanobind_binding.cpp - run pip install -e . to check if there are no C++ mistake - import the method in src/wood_nano/init.py - test the imported method in tests/test_basic.py - compas_wood - create a file called src/compas_wood/binding/binding_read_xml_polylines.py - compas_wood - add this name in init.py - compas_wood - fill the contents of the file and create a test under if name == "main" - compas_wood - write docstrings under the method - compas_wood - invoke docs and check the result

compas_wood

conda config --add channels conda-forge
conda create -n compas_wood_3_9_10 python==3.9_10 compas
conda activate compas_wood_3_9_10
conda install build setuptools wheel twine 
upload to pip https://github.com/petrasvestartas/compas_snippets

sudo apt install twine or conda install twine
cookiecutter gh:compas-dev/compas_package_template
export PATH="~/anaconda3/envs/compas_wood/bin:$PATH"
sudo apt install invoke
pip install -r requirements.txt

EDX

  • answer comments

MAC GIT CONFLICT RESOLVE

python -m compas_rhino.print_python_path sudo -H /Users/petras/.rhinocode/py39-rh8/python3.9 -m pip install . sudo -H /Users/petras/.rhinocode/py39-rh8/python3.9 -m pip install . --use-feature=in-tree-build

In this case, the default message is pre-filled, but you can modify it if needed. To proceed with the merge and accept the default commit message, you can follow these steps:

Press i on your keyboard to enter insert mode in the text editor. Make any changes to the commit message if necessary. Once you're done, press Esc to exit insert mode. Type :wq to save the commit message and exit the text editor. If you're using Vim, this command writes the changes and quits the editor.

Open Rhino from Terminal

/Applications/Rhino\ 8.app/Contents/MacOS/Rhinoceros start "" "C:\Program Files\Rhino 8\System\Rhino.exe"

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

wood-nano-0.1.2.tar.gz (104.7 MB view details)

Uploaded Source

Built Distribution

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

wood_nano-0.1.2-cp39-cp39-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file wood-nano-0.1.2.tar.gz.

File metadata

  • Download URL: wood-nano-0.1.2.tar.gz
  • Upload date:
  • Size: 104.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for wood-nano-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6e6973dd49a63118f0dc191f9099e95359c64187ef70f27c7f83726431c9c954
MD5 ee85c86afcdd9a0e4aacc5cd7ad9d144
BLAKE2b-256 8598b3922fc97266268a53536db534490448c714c3298450334eef20188099c8

See more details on using hashes here.

File details

Details for the file wood_nano-0.1.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: wood_nano-0.1.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for wood_nano-0.1.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 96f802eacc8e84bc166289a9d16f9cc371b3e12139918cd83a98159e4ce7890a
MD5 ee2a7665ba6cc0aa252f0c435ca9a20b
BLAKE2b-256 d2f8b185f94426b204c3a58a3bc56242ec761059f4b558b238bb87d90f9a32b3

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