Skip to content

Commit 28a27f7

Browse files
syoyobfut
andauthored
Bfut python new setup (tinyobjloader#345)
* Delete MANIFEST.in * Update setup.py per current pybind11 example; set relative include paths to library header * Move setup.py and pyproject.toml to root, delete MANIFEST.in * Update Python build per current pybind11 example, setting binding relative include paths to library header * Update azure pipeline build. Use pipx to build source dist of Python package. * Fix black(python format checker) install * Use 'latest' OS image. * Disable aarch64 linux build support in Azure pipeline build since it takes too much time to build. Co-authored-by: Benjamin Futász <34510704+bfut@users.noreply.github.com>
1 parent 9109078 commit 28a27f7

File tree

10 files changed

+104
-183
lines changed

10 files changed

+104
-183
lines changed

azure-pipelines.yml

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
variables:
22
# https://cibuildwheel.readthedocs.io/en/stable/cpp_standards/
3-
# python2.7 + C++11(pybind11) is not available.
4-
CIBW_SKIP: "cp27-win* pp27-win32 pp36-win32"
3+
# cibuildwheel now supports python 3.6+(as of 2022 Oct)
4+
#CIBW_SKIP: "pp*"
55
CIBW_BEFORE_BUILD: "pip install pybind11"
6+
CIBW_ARCHS_LINUXBEFORE_BUILD: "pip install pybind11"
7+
# disable aarch64 build for a while since it(pulling docker aarch64 image) exceeds Azure's 60 min limit
8+
# NOTE: aarch64 linux support in Azure pipeline is not yet officially supported(as of 2022 Oct) https://github.com/microsoft/azure-pipelines-agent/issues/3935
9+
#CIBW_ARCHS_LINUX: auto aarch64
10+
CIBW_ARCHS_MACOS: x86_64 universal2 arm64
611
#CIBW_BEFORE_BUILD_MACOS: "pip install -U pip setuptools"
712
#CIBW_BEFORE_BUILD_LINUX: "pip install -U pip setuptools"
813
#CIBW_TEST_COMMAND: TODO "python -c \"import tinyobjloader; tinyobjloader.test()\""
@@ -24,7 +29,11 @@ jobs:
2429
steps:
2530
- task: UsePythonVersion@0
2631
- script: |
27-
pip install black==19.10b0
32+
# 19.10b0 triggers 'cannot import name '_unicodefun' from 'click'' error.
33+
# https://stackoverflow.com/questions/71673404/importerror-cannot-import-name-unicodefun-from-click
34+
#pip install black==19.10b0
35+
pip install black==22.3.0
36+
2837
black --check python/
2938
displayName: Check Python code format
3039
@@ -37,27 +46,25 @@ jobs:
3746
- bash: |
3847
python3 -m pip install --upgrade pip
3948
pip3 install cibuildwheel twine
40-
# Make the header files available to the build.
41-
cp *.h python
42-
mkdir python/mapbox
43-
cp mapbox/earcut.hpp python/mapbox/
44-
cd python
49+
50+
# Use pipx to build source dist
51+
pip3 install pipx
4552
4653
# Source dist
47-
python3 setup.py sdist
54+
pipx run build --sdist
4855
ls -la dist/*
4956
5057
# build binary wheels
51-
cibuildwheel --output-dir wheelhouse .
58+
cibuildwheel --platform linux --output-dir wheelhouse .
5259
5360
- task: CopyFiles@2
5461
inputs:
55-
contents: 'python/wheelhouse/**'
62+
contents: 'wheelhouse/**'
5663
targetFolder: $(Build.ArtifactStagingDirectory)
5764

5865
- task: CopyFiles@2
5966
inputs:
60-
contents: 'python/dist/**'
67+
contents: 'dist/**'
6168
targetFolder: $(Build.ArtifactStagingDirectory)
6269

6370
- task: PublishBuildArtifacts@1
@@ -66,7 +73,7 @@ jobs:
6673
artifactName: tinyobjDeployLinux
6774

6875
- job: macos
69-
pool: {vmImage: 'macOS-10.15'}
76+
pool: {vmImage: 'macOS-latest'}
7077
variables:
7178
# Support C++11: https://github.com/joerick/cibuildwheel/pull/156
7279
MACOSX_DEPLOYMENT_TARGET: 10.9
@@ -75,37 +82,27 @@ jobs:
7582
- bash: |
7683
python3 -m pip install --upgrade pip
7784
pip3 install cibuildwheel
78-
# Make the header files available to the build.
79-
cp *.h python
80-
mkdir python/mapbox
81-
cp mapbox/earcut.hpp python/mapbox/earcut.hpp
82-
cd python
83-
cibuildwheel --output-dir wheelhouse .
85+
cibuildwheel --platform macos --output-dir wheelhouse .
8486
- task: CopyFiles@2
8587
inputs:
86-
contents: 'python/wheelhouse/*.whl'
88+
contents: 'wheelhouse/*.whl'
8789
targetFolder: $(Build.ArtifactStagingDirectory)
8890
- task: PublishBuildArtifacts@1
8991
inputs:
9092
path: $(Build.ArtifactStagingDirectory)
9193
artifactName: tinyobjDeployMacOS
9294

9395
- job: windows
94-
pool: {vmImage: 'windows-2019'}
96+
pool: {vmImage: 'windows-latest'}
9597
steps:
9698
- task: UsePythonVersion@0
9799
- bash: |
98100
python -m pip install --upgrade pip
99101
pip install cibuildwheel
100-
# Make the header files available to the build.
101-
cp *.h python
102-
mkdir python/mapbox
103-
cp mapbox/earcut.hpp python/mapbox/
104-
cd python
105-
cibuildwheel --output-dir wheelhouse .
102+
cibuildwheel --platform windows --output-dir wheelhouse .
106103
- task: CopyFiles@2
107104
inputs:
108-
contents: 'python/wheelhouse/*.whl'
105+
contents: 'wheelhouse/*.whl'
109106
targetFolder: $(Build.ArtifactStagingDirectory)
110107
- task: PublishBuildArtifacts@1
111108
inputs:
@@ -114,7 +111,7 @@ jobs:
114111

115112
- job: deployPyPI
116113
# Based on vispy: https://github.com/vispy/vispy/blob/master/azure-pipelines.yml
117-
pool: {vmImage: 'Ubuntu-16.04'}
114+
pool: {vmImage: 'ubuntu-latest'}
118115
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
119116
dependsOn:
120117
- linux
@@ -145,9 +142,9 @@ jobs:
145142
find .
146143
python -m pip install --upgrade pip
147144
pip install twine
148-
echo tinyobjDeployLinux/python/dist/*
149-
echo tinyobjDeployLinux/python/wheelhouse/* tinyobjDeployMacOS/python/wheelhouse/* tinyobjDeployWindows/python/wheelhouse/*
150-
twine upload -u "__token__" --skip-existing tinyobjDeployLinux/python/dist/* tinyobjDeployLinux/python/wheelhouse/* tinyobjDeployMacOS/python/wheelhouse/* tinyobjDeployWindows/python/wheelhouse/*
145+
echo tinyobjDeployLinux/dist/*
146+
echo tinyobjDeployLinux/wheelhouse/* tinyobjDeployMacOS/wheelhouse/* tinyobjDeployWindows/wheelhouse/*
147+
twine upload -u "__token__" --skip-existing tinyobjDeployLinux/dist/* tinyobjDeployLinux/wheelhouse/* tinyobjDeployMacOS/wheelhouse/* tinyobjDeployWindows/wheelhouse/*
151148
env:
152149
TWINE_PASSWORD: $(pypiToken2)
153150

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel", "pip>=19.2", "pybind11>=2.8.0"]
3+
build-backend = "setuptools.build_meta"

python/MANIFEST.in

Lines changed: 0 additions & 6 deletions
This file was deleted.

python/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
all:
2-
python setup.py build
2+
cd .. && python -m pip install .
33

44
t:
55
python sample.py

python/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
## Requirements
77

8-
* python 3.x(3.6+ recommended)
9-
* python 2.7 may work, but not officially supported.
8+
* python 3.6+
109

1110
## Install
1211

@@ -67,18 +66,17 @@ https://github.com/syoyo/tinyobjloader/blob/master/python/sample.py
6766

6867
## How to build
6968

70-
Using `cibuildwheel` is an recommended way to build a python module.
69+
Using `cibuildwheel` is a recommended way to build a python module.
7170
See $tinyobjloader/azure-pipelines.yml for details.
7271

7372
### Developer build
7473

75-
Edit `setup.py` and uncomment `Developer option` lines
76-
7774
Assume pip is installed.
7875

7976
```
80-
$ pip install pybind11
81-
$ python setup.py build
77+
$ git clone https://github.com/tinyobjloader/tinyobjloader
78+
$ cd tinyobjloader
79+
$ python -m pip install .
8280
```
8381

8482
## License
@@ -87,4 +85,3 @@ MIT(tinyobjloader) and ISC(mapbox earcut) license.
8785

8886
## TODO
8987
* [ ] Writer saver
90-

python/bindings.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// define some helper functions for pybind11
1010
#define TINY_OBJ_LOADER_PYTHON_BINDING
11-
#include "tiny_obj_loader.h"
11+
#include "../tiny_obj_loader.h"
1212

1313
namespace py = pybind11;
1414

@@ -132,7 +132,7 @@ PYBIND11_MODULE(tinyobjloader, tobj_module)
132132
.def("numpy_indices", [] (mesh_t &instance) {
133133
// Flatten indexes. index_t is composed of 3 ints(vertex_index, normal_index, texcoord_index).
134134
// numpy_indices = [0, -1, -1, 1, -1, -1, ...]
135-
// C++11 or later should pack POD struct tightly and does not reorder variables,
135+
// C++11 or later should pack POD struct tightly and does not reorder variables,
136136
// so we can memcpy to copy data.
137137
// Still, we check the size of struct and byte offsets of each variable just for sure.
138138
static_assert(sizeof(index_t) == 12, "sizeof(index_t) must be 12");

python/pyproject.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

python/setup.py

Lines changed: 0 additions & 131 deletions
This file was deleted.

python/tiny_obj_loader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
#define TINYOBJLOADER_USE_MAPBOX_EARCUT
77

88
#define TINYOBJLOADER_IMPLEMENTATION
9-
#include "tiny_obj_loader.h"
9+
#include "../tiny_obj_loader.h"

0 commit comments

Comments
 (0)