Skip to content

Commit

Permalink
Add Python pybind11 bindings + Upgrade ci/cd
Browse files Browse the repository at this point in the history
This PR adds python bindings as well as updates the backend build
process of the mmtf-cpp library significantly.  These improvements are
mainly from a convenience perspective and include:
- Removing all build-based submodules
- Moving to cmake fetchcontent build
- Simplify CMakeLists with better linking procedures
- Upgrade msgpack-c
- Upgrade catch2
- Move to github actions for ci/cd
- Use cibuildwheel for wheel cd

Pybind11 library:
The pybind11 library utilizes the c++ code of mmtf-cpp in order to build
an extremely fast cpp layer underneath the python interface.  You have
to keep in mind that moving between c++ and python is slow, but this is
still much faster than the previously existing python library. see this
example:

time to load a single mmtf file 1000x
cpp bare 0.29s
this library 0.44s
python og 4.34s
  • Loading branch information
danpf committed Dec 15, 2023
1 parent 3901478 commit 4cd3fda
Show file tree
Hide file tree
Showing 28 changed files with 1,887 additions and 247 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
name: cpp
'on':
workflow_dispatch: null
pull_request: null
push:
branches:
- master
concurrency:
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true
jobs:
build:
name: Build and test cpp
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
cc: gcc
cxx: g++
- os: ubuntu-22.04
cc: gcc
cxx: g++
env_list: EMSCRIPTEN=ON
- os: ubuntu-22.04
cc: clang
cxx: clang++
- os: ubuntu-22.04
cc: gcc
cxx: g++
cmake_args: "-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS='-march=native'"
- os: macos-latest
cc: clang
cxx: clang++
- os: windows-latest
cc: ''
cxx: ''
runs-on: '${{ matrix.os }}'
env:
CC: '${{ matrix.cc }}'
CXX: '${{ matrix.cxx }}'
CMAKE_ARGS: '${{ matrix.cmake_args }}'
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Set environment list variables
run: |
env_vars="${{ matrix.env_list }}"
for var in $env_vars; do
echo "$var" >> $GITHUB_ENV
done
if: matrix.os != 'windows-latest'
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: 3.16.x
- uses: seanmiddleditch/gha-setup-ninja@master
- name: build and test
run: ./ci/build_and_run_tests.sh
48 changes: 48 additions & 0 deletions .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: WASM
'on':
workflow_dispatch: null
push:
branches:
- master
concurrency:
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true
jobs:
build-wasm-emscripten:
name: Pyodide
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install pyodide-build
run: pip install pyodide-build==0.23.4
- name: Compute emsdk version
id: compute-emsdk-version
run: |
pyodide xbuildenv install --download
EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version)
echo "emsdk-version=$EMSCRIPTEN_VERSION" >> $GITHUB_OUTPUT
- uses: mymindstorm/setup-emsdk@v12
with:
version: '${{ steps.compute-emsdk-version.outputs.emsdk-version }}'
actions-cache-folder: emsdk-cache
- name: Build
run: CFLAGS=-fexceptions LDFLAGS=-fexceptions pyodide build
- uses: actions/upload-artifact@v3
with:
path: dist/*.whl
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Set up Pyodide virtual environment
run: |
pyodide venv .venv-pyodide
.venv-pyodide/bin/pip install $(echo -n dist/*.whl)
- name: Test
run: .venv-pyodide/bin/python -m unittest src/python/tests/tests.py
39 changes: 39 additions & 0 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Pip
'on':
workflow_dispatch: null
pull_request: null
push:
branches:
- master
concurrency:
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true
jobs:
build:
name: Build with Pip
runs-on: '${{ matrix.platform }}'
strategy:
fail-fast: false
matrix:
platform:
- windows-latest
- macos-latest
- ubuntu-latest
python-version:
- '3.8'
- '3.11'
- '3.12'
- pypy-3.8
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '${{ matrix.python-version }}'
- name: Build and install
run: pip install --verbose .
- name: Test
run: python src/python/tests/tests.py
79 changes: 79 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: Wheels
'on':
workflow_dispatch: null
pull_request: null
push:
branches:
- master
release:
types:
- published
env:
FORCE_COLOR: 3
concurrency:
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true
jobs:
build_sdist:
name: Build SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Build SDist
run: pipx run build --sdist
- name: Check metadata
run: pipx run twine check dist/*
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz
build_wheels:
name: 'Wheels on ${{ matrix.os }}'
runs-on: '${{ matrix.os }}'
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: universal2
CIBW_ARCHS_WINDOWS: auto ARM64
CMAKE_GENERATOR: '${{ env.CMAKE_GENERATOR }}'
- name: Verify clean directory
run: git diff --exit-code
shell: bash
- uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl
upload_all:
name: Upload if release
needs:
- build_wheels
- build_sdist
permissions:
id-token: write
environment:
name: publishing
url: https://pypi.org/p/mmtf-cppy
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/setup-python@v4
with:
python-version: 3.x
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
password: '${{ secrets.pypi_password }}'
Loading

0 comments on commit 4cd3fda

Please sign in to comment.