Skip to content

Add Python bindings for meshoptimizer #850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
158a1ca
Basic python wrapper
afshawnlotfi Mar 3, 2025
8d2f21b
Added Python Github Action
afshawnlotfi Mar 4, 2025
25d6cf5
Refactor Python package workflow and setup configuration
afshawnlotfi Mar 5, 2025
82bb6be
Update Python workflow to comment out package publishing step and mod…
afshawnlotfi Mar 5, 2025
cc4cc28
Update Python workflow to trigger on manual dispatch instead of relea…
afshawnlotfi Mar 5, 2025
c379104
Remove version information from the Mesh class
afshawnlotfi Mar 5, 2025
c0a2f44
Refactor setup.py to dynamically gather source files from the src dir…
afshawnlotfi Mar 5, 2025
556a846
Re-enable package publishing step in Python workflow
afshawnlotfi Mar 5, 2025
f933054
Add Python workflow for package build and testing; remove deprecated …
afshawnlotfi Mar 5, 2025
1ea8095
Fix indentation in release workflow for artifact upload step
afshawnlotfi Mar 5, 2025
374793d
Add macOS and Windows to the release workflow matrix
afshawnlotfi Mar 5, 2025
6b79f41
Enhance setup.py with platform-specific compile and link arguments fo…
afshawnlotfi Mar 5, 2025
190a8f0
Remove unnecessary directory change in test execution step of release…
afshawnlotfi Mar 5, 2025
e503ec7
Comment out package build and storage steps for Ubuntu in release wor…
afshawnlotfi Mar 5, 2025
25d1093
Change directory to 'python' before running tests in release workflow
afshawnlotfi Mar 5, 2025
cc875f9
Refactor get_source_files and get_build_args functions in setup.py fo…
afshawnlotfi Mar 5, 2025
5468a91
Simplify get_source_files function in setup.py by removing unnecessar…
afshawnlotfi Mar 5, 2025
7d405e6
Update README to include Python interface installation instructions a…
afshawnlotfi Mar 5, 2025
61cd534
Only have low level api
afshawnlotfi Mar 5, 2025
ced74a3
Bump version to 0.2.20a2 in setup.py
afshawnlotfi Mar 5, 2025
2c99ca2
Refactor setup.py to generate module file from template and streamlin…
afshawnlotfi Mar 5, 2025
5219e26
Bump version to 0.2.20a3 in setup.py
afshawnlotfi Mar 5, 2025
b68cff5
Refactor Python bindings: replace module.template.cpp, update setup.p…
afshawnlotfi Mar 5, 2025
6879cc9
Update MANIFEST.in to prune unnecessary directories and adjust source…
afshawnlotfi Mar 5, 2025
f1ef8e4
Add debug print statement for source files in generate_module_file fu…
afshawnlotfi Mar 5, 2025
3623568
Remove debug print statement and fix string formatting in generate_mo…
afshawnlotfi Mar 5, 2025
7b3f35e
Working build
afshawnlotfi Mar 5, 2025
affa323
Removed uneeded files
afshawnlotfi Mar 5, 2025
ffc0334
Bump version to 0.2.20a4 in setup.py
afshawnlotfi Mar 5, 2025
76ea72f
Add encoding and decoding for index sequences; update setup.py versio…
afshawnlotfi Mar 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
35 changes: 35 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Python Package

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for setuptools_scm to determine version

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine

- name: Build package
run: |
cd python
python -m build --sdist

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: python/dist/
skip-existing: true
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,42 @@ jobs:
with:
name: meshoptimizer-npm
path: js/meshoptimizer-*.tgz

python:
strategy:
matrix:
os: [ubuntu, macos, windows]
runs-on: ${{matrix.os}}-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for setuptools_scm to determine version

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install package
run: |
python -m pip install --upgrade pip
pip install build
cd python
pip install -e .

- name: Run tests
run: |
cd python
python -m unittest discover -v

# - name: Build package
# run: |
# python -m build --sdist
# if: matrix.os == 'ubuntu'

# - name: Store package
# uses: actions/upload-artifact@v4
# with:
# name: python-package
# path: python/dist/*
# if: matrix.os == 'ubuntu'
277 changes: 277 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
python/bindings/module.cpp
python/src
# IDE integrations
/.idea/
/.vs/
Expand All @@ -11,3 +13,278 @@

# Test files
/data/

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

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

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

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk
Loading