Skip to content

Commit ff347ac

Browse files
committed
Add Python pybind11 bindings + Upgrade ci/cd
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
1 parent 3901478 commit ff347ac

28 files changed

+1885
-247
lines changed

.github/workflows/cpp.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: cpp
3+
'on':
4+
workflow_dispatch: null
5+
pull_request: null
6+
push:
7+
branches:
8+
- master
9+
concurrency:
10+
group: '${{ github.workflow }}-${{ github.ref }}'
11+
cancel-in-progress: true
12+
jobs:
13+
build:
14+
name: Build and test cpp
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- os: ubuntu-22.04
20+
cc: gcc
21+
cxx: g++
22+
- os: ubuntu-22.04
23+
cc: gcc
24+
cxx: g++
25+
env_list: EMSCRIPTEN=ON
26+
- os: ubuntu-22.04
27+
cc: clang
28+
cxx: clang++
29+
- os: ubuntu-22.04
30+
cc: gcc
31+
cxx: g++
32+
cmake_args: "-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS='-march=native'"
33+
- os: macos-latest
34+
cc: clang
35+
cxx: clang++
36+
- os: windows-latest
37+
cc: ''
38+
cxx: ''
39+
runs-on: '${{ matrix.os }}'
40+
env:
41+
CC: '${{ matrix.cc }}'
42+
CXX: '${{ matrix.cxx }}'
43+
CMAKE_ARGS: '${{ matrix.cmake_args }}'
44+
steps:
45+
- uses: actions/checkout@v4
46+
with:
47+
submodules: true
48+
fetch-depth: 0
49+
- name: Set environment list variables
50+
run: |
51+
env_vars="${{ matrix.env_list }}"
52+
for var in $env_vars; do
53+
echo "$var" >> $GITHUB_ENV
54+
done
55+
if: matrix.os != 'windows-latest'
56+
- name: Setup cmake
57+
uses: jwlawson/[email protected]
58+
with:
59+
cmake-version: 3.16.x
60+
- uses: seanmiddleditch/gha-setup-ninja@master
61+
- name: build and test
62+
run: ./ci/build_and_run_tests.sh

.github/workflows/emscripten.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: WASM
3+
'on':
4+
workflow_dispatch: null
5+
push:
6+
branches:
7+
- master
8+
concurrency:
9+
group: '${{ github.workflow }}-${{ github.ref }}'
10+
cancel-in-progress: true
11+
jobs:
12+
build-wasm-emscripten:
13+
name: Pyodide
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: true
19+
fetch-depth: 0
20+
- uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.11'
23+
- name: Install pyodide-build
24+
run: pip install pyodide-build==0.23.4
25+
- name: Compute emsdk version
26+
id: compute-emsdk-version
27+
run: |
28+
pyodide xbuildenv install --download
29+
EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version)
30+
echo "emsdk-version=$EMSCRIPTEN_VERSION" >> $GITHUB_OUTPUT
31+
- uses: mymindstorm/setup-emsdk@v12
32+
with:
33+
version: '${{ steps.compute-emsdk-version.outputs.emsdk-version }}'
34+
actions-cache-folder: emsdk-cache
35+
- name: Build
36+
run: CFLAGS=-fexceptions LDFLAGS=-fexceptions pyodide build
37+
- uses: actions/upload-artifact@v3
38+
with:
39+
path: dist/*.whl
40+
- uses: actions/setup-node@v4
41+
with:
42+
node-version: 18
43+
- name: Set up Pyodide virtual environment
44+
run: |
45+
pyodide venv .venv-pyodide
46+
.venv-pyodide/bin/pip install $(echo -n dist/*.whl)
47+
- name: Test
48+
run: .venv-pyodide/bin/python -m unittest src/python/tests/tests.py

.github/workflows/pip.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Pip
3+
'on':
4+
workflow_dispatch: null
5+
pull_request: null
6+
push:
7+
branches:
8+
- master
9+
concurrency:
10+
group: '${{ github.workflow }}-${{ github.ref }}'
11+
cancel-in-progress: true
12+
jobs:
13+
build:
14+
name: Build with Pip
15+
runs-on: '${{ matrix.platform }}'
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
platform:
20+
- windows-latest
21+
- macos-latest
22+
- ubuntu-latest
23+
python-version:
24+
- '3.8'
25+
- '3.11'
26+
- '3.12'
27+
- pypy-3.8
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
submodules: true
32+
fetch-depth: 0
33+
- uses: actions/setup-python@v4
34+
with:
35+
python-version: '${{ matrix.python-version }}'
36+
- name: Build and install
37+
run: pip install --verbose .
38+
- name: Test
39+
run: python src/python/tests/tests.py

.github/workflows/wheels.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
name: Wheels
3+
'on':
4+
workflow_dispatch: null
5+
pull_request: null
6+
push:
7+
branches:
8+
- master
9+
release:
10+
types:
11+
- published
12+
env:
13+
FORCE_COLOR: 3
14+
concurrency:
15+
group: '${{ github.workflow }}-${{ github.ref }}'
16+
cancel-in-progress: true
17+
jobs:
18+
build_sdist:
19+
name: Build SDist
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
submodules: true
25+
- name: Build SDist
26+
run: pipx run build --sdist
27+
- name: Check metadata
28+
run: pipx run twine check dist/*
29+
- uses: actions/upload-artifact@v3
30+
with:
31+
path: dist/*.tar.gz
32+
build_wheels:
33+
name: 'Wheels on ${{ matrix.os }}'
34+
runs-on: '${{ matrix.os }}'
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
os:
39+
- ubuntu-latest
40+
- macos-latest
41+
- windows-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
with:
45+
submodules: true
46+
- uses: pypa/[email protected]
47+
env:
48+
CIBW_ARCHS_MACOS: universal2
49+
CIBW_ARCHS_WINDOWS: auto ARM64
50+
CMAKE_GENERATOR: '${{ env.CMAKE_GENERATOR }}'
51+
- name: Verify clean directory
52+
run: git diff --exit-code
53+
shell: bash
54+
- uses: actions/upload-artifact@v3
55+
with:
56+
path: wheelhouse/*.whl
57+
upload_all:
58+
name: Upload if release
59+
needs:
60+
- build_wheels
61+
- build_sdist
62+
permissions:
63+
id-token: write
64+
environment:
65+
name: publishing
66+
url: https://pypi.org/p/mmtf-cppy
67+
runs-on: ubuntu-latest
68+
if: github.event_name == 'release' && github.event.action == 'published'
69+
steps:
70+
- uses: actions/setup-python@v4
71+
with:
72+
python-version: 3.x
73+
- uses: actions/download-artifact@v3
74+
with:
75+
name: artifact
76+
path: dist
77+
- uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)