Skip to content

Commit a77f3be

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 a77f3be

28 files changed

Lines changed: 1881 additions & 247 deletions

.github/workflows/cpp.yml

Lines changed: 62 additions & 0 deletions
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/actions-setup-cmake@v1.13
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

Lines changed: 48 additions & 0 deletions
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

Lines changed: 39 additions & 0 deletions
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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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/cibuildwheel@v2.16.2
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+
runs-on: ubuntu-latest
63+
if: github.event_name == 'release' && github.event.action == 'published'
64+
steps:
65+
- uses: actions/setup-python@v4
66+
with:
67+
python-version: 3.x
68+
- uses: actions/download-artifact@v3
69+
with:
70+
name: artifact
71+
path: dist
72+
- uses: pypa/gh-action-pypi-publish@release/v1
73+
with:
74+
password: '${{ secrets.pypi_password }}'

.gitignore

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,172 @@ build/*
3939
docs/html/*
4040
examples/out/*
4141
examples/out_json_ref/*
42+
43+
# python eggs
44+
src/python/*.egg-info
45+
**/__pycache__
46+
**/*.pyc
47+
48+
49+
# Byte-compiled / optimized / DLL files
50+
__pycache__/
51+
*.py[cod]
52+
*$py.class
53+
54+
# C extensions
55+
*.so
56+
57+
# Distribution / packaging
58+
.Python
59+
build/
60+
develop-eggs/
61+
dist/
62+
downloads/
63+
eggs/
64+
.eggs/
65+
lib/
66+
lib64/
67+
parts/
68+
sdist/
69+
var/
70+
wheels/
71+
share/python-wheels/
72+
*.egg-info/
73+
.installed.cfg
74+
*.egg
75+
MANIFEST
76+
77+
# PyInstaller
78+
# Usually these files are written by a python script from a template
79+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
80+
*.manifest
81+
*.spec
82+
83+
# Installer logs
84+
pip-log.txt
85+
pip-delete-this-directory.txt
86+
87+
# Unit test / coverage reports
88+
htmlcov/
89+
.tox/
90+
.nox/
91+
.coverage
92+
.coverage.*
93+
.cache
94+
nosetests.xml
95+
coverage.xml
96+
*.cover
97+
*.py,cover
98+
.hypothesis/
99+
.pytest_cache/
100+
cover/
101+
102+
# Translations
103+
*.mo
104+
*.pot
105+
106+
# Django stuff:
107+
*.log
108+
local_settings.py
109+
db.sqlite3
110+
db.sqlite3-journal
111+
112+
# Flask stuff:
113+
instance/
114+
.webassets-cache
115+
116+
# Scrapy stuff:
117+
.scrapy
118+
119+
# Sphinx documentation
120+
docs/_build/
121+
122+
# PyBuilder
123+
.pybuilder/
124+
target/
125+
126+
# Jupyter Notebook
127+
.ipynb_checkpoints
128+
129+
# IPython
130+
profile_default/
131+
ipython_config.py
132+
133+
# pyenv
134+
# For a library or package, you might want to ignore these files since the code is
135+
# intended to run in multiple environments; otherwise, check them in:
136+
# .python-version
137+
138+
# pipenv
139+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
140+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
141+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
142+
# install all needed dependencies.
143+
#Pipfile.lock
144+
145+
# poetry
146+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
147+
# This is especially recommended for binary packages to ensure reproducibility, and is more
148+
# commonly ignored for libraries.
149+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
150+
#poetry.lock
151+
152+
# pdm
153+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
154+
#pdm.lock
155+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
156+
# in version control.
157+
# https://pdm.fming.dev/#use-with-ide
158+
.pdm.toml
159+
160+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
161+
__pypackages__/
162+
163+
# Celery stuff
164+
celerybeat-schedule
165+
celerybeat.pid
166+
167+
# SageMath parsed files
168+
*.sage.py
169+
170+
# Environments
171+
.env
172+
.venv
173+
env/
174+
venv/
175+
ENV/
176+
env.bak/
177+
venv.bak/
178+
179+
# Spyder project settings
180+
.spyderproject
181+
.spyproject
182+
183+
# Rope project settings
184+
.ropeproject
185+
186+
# mkdocs documentation
187+
/site
188+
189+
# mypy
190+
.mypy_cache/
191+
.dmypy.json
192+
dmypy.json
193+
194+
# Pyre type checker
195+
.pyre/
196+
197+
# pytype static type analyzer
198+
.pytype/
199+
200+
# Cython debug symbols
201+
cython_debug/
202+
**/_version.py
203+
204+
# PyCharm
205+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
206+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
207+
# and can be added to the global gitignore or merged into this file. For a more nuclear
208+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
209+
#.idea/
210+

0 commit comments

Comments
 (0)