Skip to content

Commit

Permalink
implement python bindings as pyraydeon
Browse files Browse the repository at this point in the history
Includes the ability to add custom geometry rendering implemented in
python.
  • Loading branch information
cbgbt committed Nov 18, 2024
1 parent 7d8f023 commit 3fd6eab
Show file tree
Hide file tree
Showing 30 changed files with 1,215 additions and 129 deletions.
189 changes: 189 additions & 0 deletions .github/workflows/pyraydeon-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# This file is autogenerated by maturin v1.7.4
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- "*"
tags:
- "*"
pull_request:
workflow_dispatch:

permissions:
contents: read

defaults:
run:
working-directory: pyraydeon

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: "true"
manylinux: auto
working-directory: pyraydeon
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: "true"
manylinux: musllinux_1_2
working-directory: pyraydeon
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: "true"
working-directory: pyraydeon
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: "true"
working-directory: pyraydeon
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
working-directory: pyraydeon
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

# release:
# name: Release
# runs-on: ubuntu-latest
# if: ${{ startsWith(github.ref, 'refs/tags/pyraydeon-v') || github.event_name == 'workflow_dispatch' }}
# needs: [linux, musllinux, windows, macos, sdist]
# permissions:
# # Use to sign the release artifacts
# id-token: write
# # Used to upload release artifacts
# contents: write
# # Used to generate artifact attestation
# attestations: write
# steps:
# - uses: actions/download-artifact@v4
# - name: Generate artifact attestation
# uses: actions/attest-build-provenance@v1
# with:
# subject-path: "wheels-*/*"
# - name: Publish to PyPI
# if: "startsWith(github.ref, 'refs/tags/')"
# uses: PyO3/maturin-action@v1
# env:
# MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
# with:
# command: upload
# args: --non-interactive --skip-existing wheels-*/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Cargo.lock
build
target
*.svg
todo.txt

27 changes: 15 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
[package]
name = "raydeon"
version = "0.1.0"
authors = ["cbgbt <[email protected]>"]
edition = "2018"
[workspace]
resolver = "2"
members = [
"raydeon",
"pyraydeon",
]

[dependencies]

[workspace.dependencies]
raydeon = { path = "./raydeon", version = "0.1" }
pyrayeon = { path = "./pyraydeon", version = "0.1" }

anyhow = "1"
cgmath = "0.17"
collision = "0.20"
env_logger = "0.11"
euclid = "0.22"
float-cmp = "0.5"
log = "0.4"
rayon = "1.2"
tracing = { version = "0.1", features = ["log"] }

[dev-dependencies]
anyhow = "1"
env_logger = "0.11"
float-cmp = "0.5"
svg = "0.18"
tracing = "0.1"
72 changes: 72 additions & 0 deletions pyraydeon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/target

# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
.venv/
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
man/
venv/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

.DS_Store

# Sphinx documentation
docs/_build/

# PyCharm
.idea/

# VSCode
.vscode/

# Pyenv
.python-version
14 changes: 14 additions & 0 deletions pyraydeon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "pyraydeon"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "pyraydeon"
crate-type = ["cdylib"]

[dependencies]
raydeon.workspace = true

pyo3 = { version = "0.23", features = ["extension-module"] }
15 changes: 15 additions & 0 deletions pyraydeon/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

[project]
name = "pyraydeon"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]
[tool.maturin]
features = ["pyo3/extension-module"]
38 changes: 38 additions & 0 deletions pyraydeon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use pyo3::prelude::*;

macro_rules! pywrap {
($name:ident, $wraps:ty) => {
#[derive(Debug, Clone)]
#[pyclass(frozen)]
pub(crate) struct $name(pub(crate) $wraps);

impl ::std::ops::Deref for $name {
type Target = $wraps;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl From<$wraps> for $name {
fn from(value: $wraps) -> Self {
Self(value)
}
}
};
}

mod linear;
mod ray;
mod scene;
mod shapes;

/// A Python module implemented in Rust.
#[pymodule]
fn pyraydeon(m: &Bound<'_, PyModule>) -> PyResult<()> {
crate::linear::register(m)?;
crate::shapes::register(m)?;
crate::scene::register(m)?;
crate::ray::register(m)?;
Ok(())
}
Loading

0 comments on commit 3fd6eab

Please sign in to comment.