Skip to content

Commit 8194c5e

Browse files
first commit
0 parents  commit 8194c5e

16 files changed

Lines changed: 631 additions & 0 deletions

File tree

.github/workflows/build-wheels.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build wheels
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
tags: [ "v*" ] # only build/publish on version tags
7+
pull_request:
8+
9+
jobs:
10+
build_wheels:
11+
name: Build wheels on ${{ matrix.os }}
12+
runs-on: ${{ matrix.os }}
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-latest, macos-latest, windows-latest]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.11"
26+
27+
- name: Install cibuildwheel
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install cibuildwheel
31+
32+
- name: Build wheels with cibuildwheel
33+
env:
34+
# Build CPython 3.10–3.13
35+
CIBW_BUILD: "cp3{10,11,12,13}-*"
36+
37+
# Skip musllinux (Alpine) and PyPy for now
38+
# muslinux uses libc and not glibc, which may cause compatibility issues
39+
# specially skip in CUDA projects. Nvidia does not provide CUDA support for Alpine.
40+
CIBW_SKIP: "pp* *-musllinux_*"
41+
42+
# macOS: build both x86_64 and arm64 wheels
43+
CIBW_ARCHS_MACOS: "x86_64 arm64"
44+
45+
# Test deps inside cibuildwheel’s test environment
46+
CIBW_TEST_REQUIRES: "pytest numpy"
47+
48+
# Run tests against the installed wheel
49+
CIBW_TEST_COMMAND: "pytest -q {project}/tests"
50+
51+
run: |
52+
cibuildwheel --output-dir wheelhouse
53+
54+
- name: List built wheels
55+
run: ls wheelhouse
56+
57+
# Always upload as CI artifacts (handy for debugging / manual download).
58+
# This is NOT PyPI, it's just stored on GitHub Actions.
59+
- name: Upload wheels as artifact
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: wheels-${{ matrix.os }}
63+
path: wheelhouse/*.whl

.gitignore

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# ----------------------------------------
2+
# Python general
3+
# ----------------------------------------
4+
*.pyc
5+
*.pyo
6+
*.pyd
7+
__pycache__/
8+
*.so
9+
*.dll
10+
*.dylib
11+
12+
# Caches
13+
.pytest_cache/
14+
.mypy_cache/
15+
.ruff_cache/
16+
.ipynb_checkpoints/
17+
.cache
18+
19+
# Virtual environments
20+
.venv/
21+
env/
22+
venv/
23+
24+
# ----------------------------------------
25+
# Build / packaging artifacts
26+
# ----------------------------------------
27+
build/
28+
dist/
29+
wheelhouse/
30+
*.egg-info/
31+
*.egg
32+
.eggs/
33+
34+
# Built wheels from cibuildwheel
35+
wheelhouse/
36+
37+
# sdists
38+
*.tar.gz
39+
40+
# ----------------------------------------
41+
# C++ build artifacts (pybind11, cmake, etc.)
42+
# ----------------------------------------
43+
*.o
44+
*.obj
45+
*.a
46+
*.lib
47+
*.mod
48+
*.exp
49+
*.pdb
50+
*.ilk
51+
*.manifest
52+
53+
# CMake artifacts
54+
CMakeCache.txt
55+
CMakeFiles/
56+
cmake-build-*/
57+
Makefile
58+
cmake_install.cmake
59+
60+
# Ninja build system
61+
*.ninja
62+
.ninja_deps
63+
.ninja_log
64+
65+
# ----------------------------------------
66+
# IDE / Editor settings
67+
# ----------------------------------------
68+
.vscode/
69+
.idea/
70+
*.swp
71+
*.swo
72+
73+
# ----------------------------------------
74+
# macOS system files
75+
# ----------------------------------------
76+
.DS_Store
77+
.AppleDouble
78+
.LSOverride
79+
*.plist
80+
81+
# macOS Resource Forks
82+
._*
83+
84+
# ----------------------------------------
85+
# Linux system files
86+
# ----------------------------------------
87+
*.out
88+
89+
# ----------------------------------------
90+
# Logs
91+
# ----------------------------------------
92+
*.log
93+
94+
# ----------------------------------------
95+
# Temporary files
96+
# ----------------------------------------
97+
tmp/
98+
temp/
99+
*~

Docker/Dockerfile-python-3.13

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.13
2+
3+
ARG USERNAME=user
4+
ARG UID=1000
5+
ARG GID=1000
6+
7+
# create a group for the user and add the user
8+
RUN if getent group ${GID} >/dev/null; then \
9+
echo "Group with GID ${GID} already exists, using it."; \
10+
GROUP_NAME=$(getent group ${GID} | cut -d: -f1); \
11+
else \
12+
GROUP_NAME=${USERNAME}; \
13+
groupadd --gid ${GID} ${GROUP_NAME}; \
14+
fi && \
15+
useradd --uid ${UID} --gid ${GID} --create-home --shell /bin/bash ${USERNAME}
16+
17+
WORKDIR /home/${USERNAME}
18+
RUN chown -R ${UID}:${GID} /home/${USERNAME}
19+
20+
# set user
21+
USER ${USERNAME}
22+
CMD ["/bin/bash"]

Docker/build-run.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
THIS_DIR=$(dirname "$(realpath "$0")")
4+
ROOT_DIR=$(realpath "$THIS_DIR/..")
5+
6+
DOCKERFILE=python-3.13
7+
8+
9+
build_image(){
10+
docker build -f Docker/Dockerfile-${DOCKERFILE} \
11+
--build-arg USERNAME=$(whoami) \
12+
--build-arg UID=$(id -u) \
13+
--build-arg GID=$(id -g) \
14+
-t ${DOCKERFILE}-image .
15+
}
16+
17+
run_image(){
18+
docker run \
19+
-v ${ROOT_DIR}:/home/$(whoami) \
20+
-it \
21+
${DOCKERFILE}-image \
22+
/bin/bash
23+
}
24+
25+
croak(){
26+
echo "[ERROR] $*" > /dev/stderr
27+
exit 1
28+
}
29+
30+
main(){
31+
if [[ -z "$TASK" ]]; then
32+
croak "No TASK specified."
33+
fi
34+
echo "[INFO] running $TASK $*"
35+
$TASK "$@"
36+
}
37+
38+
main "$@"
39+
40+
# TASK=build_image ./Docker/build-run.sh
41+
# TASK=run_image ./Docker/build-run.sh

MANIFEST.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# MANIFEST.in needed to include non-Python files in the package to build wheel distributions
2+
# e.g. C++ source files, headers, README, pyproject.toml, etc.
3+
4+
include pyproject.toml
5+
include README.md
6+
7+
recursive-include src *.py *.cpp *.hpp *.h
8+
recursive-include include *.hpp *.h

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Python CPP Boilerplate
2+
3+
4+
## Compile and install the package
5+
6+
Create a new package
7+
8+
```bash
9+
rm -rf .venv
10+
python3 -m venv .venv
11+
.venv/bin/python -m pip install --upgrade pip
12+
```
13+
14+
Then compile C++ bindings and install with pip
15+
16+
```bash
17+
.venv/bin/python -m pip install .
18+
```
19+
20+
## Run an example
21+
22+
To check that this is working try importing the package and running a script
23+
24+
```bash
25+
.venv/bin/python -c "import package_example"
26+
.venv/bin/python scripts/example.py
27+
```
28+
29+
## Tesing
30+
31+
Run tests
32+
33+
```bash
34+
.venv/bin/python -m pip install -e ".[test]"
35+
.venv/bin/pytest -v
36+
```
37+
38+
## Linting
39+
40+
Using ruff
41+
42+
```bash
43+
.venv/bin/python -m pip install -e ".[test]"
44+
.venv/bin/ruff format .
45+
46+
.venv/bin/mypy src
47+
```

include/matmul.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef MATMUL_H
2+
#define MATMUL_H
3+
4+
void matmul(const float* A, const float* B, float* C, std::size_t M, std::size_t N, std::size_t K);
5+
void printmatrix(const float* A, int M, int N);
6+
7+
#endif

pyproject.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel", "pybind11>=2.10"]
3+
build-backend = "setuptools.build_meta"
4+
5+
6+
[tool.ruff]
7+
line-length = 99
8+
9+
[tool.ruff.lint]
10+
select = [
11+
# Pyflakes
12+
"F",
13+
# Pycodestyle & Warnings
14+
"E",
15+
"W",
16+
# isort for unsorted imports
17+
"I001",
18+
]
19+
20+
[tool.ruff.format]
21+
quote-style = "single"
22+
indent-style = "space"
23+
docstring-code-format = true
24+
docstring-code-line-length = 20
25+
26+
[tool.mypy]
27+
python_version = "3.13"
28+
ignore_missing_imports = true
29+
exclude = "^(build/|\\.venv/)"
30+
31+
[tool.pytest.ini_options]
32+
testpaths = ["tests"]
33+
addopts = "-v"

0 commit comments

Comments
 (0)