Skip to content

Commit e0f1ba0

Browse files
committed
Update python-binding project files.
Add Github Actions and Cirrus CI task for Python wheel build.
1 parent cc327ee commit e0f1ba0

5 files changed

Lines changed: 203 additions & 9 deletions

File tree

.cirrus.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
build_and_store_wheels: &BUILD_AND_STORE_WHEELS
2+
install_cibuildwheel_script:
3+
- python -m pip install cibuildwheel==2.16.2
4+
run_cibuildwheel_script:
5+
- cibuildwheel
6+
wheels_artifacts:
7+
path: "wheelhouse/*"
8+
9+
# Upload only for tagged commit
10+
only_if: $CIRRUS_TAG != ''
11+
publish_script:
12+
- python -m pip install twine
13+
- python -m twine upload --repository-url https://upload.pypi.org/legacy/ --username __token__ wheelhouse/*.whl
14+
15+
16+
linux_aarch64_task:
17+
name: Build Linux aarch64 wheels.
18+
compute_engine_instance:
19+
image_project: cirrus-images
20+
image: family/docker-builder-arm64
21+
architecture: arm64
22+
platform: linux
23+
cpu: 4
24+
memory: 4G
25+
environment:
26+
TWINE_PASSWORD: ENCRYPTED[88f22b6fab51dc9306c5690f2ad999f4114320fecbcff933864d3f225bbd03037ca511742e8572fa2b63dfa9cebee365]
27+
28+
install_pre_requirements_script:
29+
- apt install -y python3-venv python-is-python3
30+
<<: *BUILD_AND_STORE_WHEELS

.github/workflow/wheels.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Build and upload to PyPI
2+
3+
# Build on every branch push, tag push, and pull request change:
4+
on: [push, pull_request]
5+
6+
jobs:
7+
8+
build_wheels:
9+
name: Build wheels on ${{ matrix.os }}
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest, macos-latest]
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
fetch-tags: true # Optional, use if you use setuptools_scm
20+
21+
- name: Build wheels
22+
uses: pypa/cibuildwheel@v2.16.2
23+
# to supply options, put them in 'env', like:
24+
# env:
25+
# CIBW_SOME_OPTION: value
26+
# Disable building PyPy wheels on all platforms
27+
env:
28+
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
29+
CIBW_ARCHS_WINDOWS: "AMD64 x86"
30+
# disable aarm64 build since its too slow to build(docker + qemu)
31+
CIBW_ARCHS_LINUX: "x86_64 i686"
32+
# it looks cibuildwheel fails to add version string to wheel file for python 3.6, so skip it
33+
CIBW_SKIP: pp*
34+
35+
- uses: actions/upload-artifact@v4
36+
with:
37+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
38+
path: ./wheelhouse/*.whl
39+
40+
# It looks cibuildwheels did not clean build folder(CMake), and it results to Windows arm64 build failure(trying to reuse x86 build of .obj)
41+
# So supply separated build job for Windows ARM64 build
42+
# TODO: clean build folder using CIBW_BEFORE_ALL?
43+
build_win_arm64_wheels:
44+
name: Build ARM64 wheels on Windows.
45+
runs-on: windows-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
with:
49+
fetch-depth: 0
50+
fetch-tags: true # Optional, use if you use setuptools_scm
51+
52+
- name: Build wheels
53+
uses: pypa/cibuildwheel@v2.16.2
54+
# to supply options, put them in 'env', like:
55+
# env:
56+
# CIBW_SOME_OPTION: value
57+
# Disable building PyPy wheels on all platforms
58+
env:
59+
CIBW_ARCHS_WINDOWS: "ARM64"
60+
CIBW_SKIP: pp*
61+
62+
- uses: actions/upload-artifact@v4
63+
with:
64+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
65+
path: ./wheelhouse/*.whl
66+
67+
make_sdist:
68+
name: Make SDist
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v4
72+
with:
73+
fetch-depth: 0 # Optional, use if you use setuptools_scm
74+
fetch-tags: true # Optional, use if you use setuptools_scm
75+
76+
- name: Build SDist
77+
run: pipx run build --sdist
78+
79+
- uses: actions/upload-artifact@v4
80+
with:
81+
name: cibw-sdist
82+
path: dist/*.tar.gz
83+
84+
upload_all:
85+
needs: [build_wheels, build_wheels, make_sdist]
86+
runs-on: ubuntu-latest
87+
environment: release
88+
permissions:
89+
# IMPORTANT: this permission is mandatory for trusted publishing
90+
id-token: write
91+
# upload to PyPI on every tag starting with 'v'
92+
# NOTE: Without github.event_name & githug.ref check, `upload_all` task is still triggered on 'main' branch push.
93+
# (then get 'Branch "main" is not allowed to deploy to release due to environment protection rules.' error)
94+
# So still do event_name and github.ref check.
95+
# TODO: Make it work only using Github `environment` feature.
96+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
97+
# alternatively, to publish when a GitHub Release is created, use the following rule:
98+
# if: github.event_name == 'push' && github.event.action == 'published'
99+
steps:
100+
- uses: actions/download-artifact@v4
101+
with:
102+
pattern: cibw-*
103+
path: dist
104+
merge-multiple: true
105+
106+
- uses: pypa/gh-action-pypi-publish@release/v1
107+
with:
108+
# Use Trusted Publisher feature:
109+
# https://docs.pypi.org/trusted-publishers/
110+
# so no use of PYPI_API_TOKEN
111+
#password: ${{ secrets.PYPI_API_TOKEN }}
112+
#
113+
# Avoid race condition when using multiple CIs
114+
skip-existing: true
115+
verbose: true

MANIFEST.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include pyproject.toml
2+
include setup.py
3+
include README.md
4+
include LICENSE
5+
include python/sample.py
6+
include python/bindings.cc
7+
include python/tiny_obj_loader.cc
8+
include tiny_obj_loader.h

pyproject.toml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
[build-system]
2-
requires = ["setuptools>=42", "wheel", "pip>=19.2", "pybind11>=2.8.0"]
2+
3+
requires = [
4+
# NOTE: setuptools_scm>=8 is not supported in py3.6 cibuildwheel env.
5+
# so use older setuptools_scm for a while
6+
#"setuptools>=64",
7+
#"setuptools_scm>=8",
8+
"setuptools>=45",
9+
"setuptools_scm[toml]<8",
10+
"wheel",
11+
"pybind11>=2.10.0",
12+
]
313
build-backend = "setuptools.build_meta"
14+
15+
[tool.black]
16+
line-length = 140
17+
18+
[project]
19+
name = "tinyobjloader"
20+
21+
# version: Use setuptools_scm
22+
dynamic = ["version", "classifiers", "authors", "description"]
23+
24+
25+
readme = {file = "README.md", content-type = "text/markdown"}
26+
27+
# Project URLs in pyproject.toml is not mature.
28+
# so write it to setup.py
29+
# https://github.com/pypa/packaging-problems/issues/606
30+
#
31+
# [project.urils]
32+
33+
34+
[tool.setuptools_scm]
35+
# setuptools_scm>=8
36+
#version_file = "python/_version.py"
37+
38+
# setuptools_scm<8
39+
write_to = "python/_version.py"

setup.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
from pybind11.setup_helpers import Pybind11Extension#, build_ext
77
from setuptools import setup
88

9-
__version__ = "2.0.0rc10"
9+
try:
10+
# try to read setuptools_scm generated _version.py
11+
from .python import _version
12+
except:
13+
__version__ = "2.0.0rc10"
1014

1115
with open("README.md", "r", encoding="utf8") as fh:
1216
long_description = fh.read()
@@ -31,13 +35,14 @@
3135

3236
setup(
3337
name="tinyobjloader",
34-
version=__version__,
38+
packages=['python'],
39+
#version=__version__,
3540
author="Syoyo Fujita",
3641
author_email="syoyo@lighttransport.com",
3742
url="https://github.com/tinyobjloader/tinyobjloader",
38-
project_urls={
39-
"Issue Tracker": "https://github.com/tinyobjloader/tinyobjloader/issues",
40-
},
43+
#project_urls={
44+
# "Issue Tracker": "https://github.com/tinyobjloader/tinyobjloader/issues",
45+
#},
4146
description="Tiny but powerful Wavefront OBJ loader",
4247
long_description=long_description,
4348
long_description_content_type='text/markdown',
@@ -55,10 +60,10 @@
5560
"Programming Language :: Python :: 3",
5661
],
5762
ext_modules=ext_modules,
58-
extras_require={"test": "pytest"},
63+
#extras_require={"test": "pytest"},
5964
# Currently, build_ext only provides an optional "highest supported C++
6065
# level" feature, but in the future it may provide more features.
6166
# cmdclass={"build_ext": build_ext},
62-
zip_safe=False,
63-
python_requires=">=3.6",
67+
#zip_safe=False,
68+
#python_requires=">=3.6",
6469
)

0 commit comments

Comments
 (0)