Skip to content

Commit 586991a

Browse files
authored
Build wheels for pyobjus (#84)
* Build wheels. * No need to check for cython. * Use setuptools. * Cython needs to be available. * Cython needs to be installed for sdist and tests. * Missing pytest.
1 parent 8ac2543 commit 586991a

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

.github/workflows/deploy.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
name: Deploy sdist
1+
name: Deploy sdist/wheels
22

33
on: [push, pull_request]
44

5+
56
jobs:
67
deploy:
7-
runs-on: macOs-latest
8+
runs-on: macos-latest
9+
env:
10+
CIBW_BUILD_VERBOSITY: 3
11+
CIBW_BUILD: cp3{6,7,8,9,10}-*
12+
CIBW_ARCHS: "x86_64 universal2 arm64"
13+
CIBW_TEST_COMMAND: python -c "from pyobjus import autoclass, objc_str"
14+
CIBW_TEST_SKIP: "*arm64*"
815
steps:
916
- uses: actions/checkout@v2
1017

@@ -14,18 +21,20 @@ jobs:
1421
python-version: '3.x'
1522

1623
- name: Install dependencies
17-
run: |
18-
python -m pip install --upgrade pip setuptools
19-
pip install cython twine
24+
run: python -m pip install --upgrade twine cibuildwheel cython
2025

21-
- name: Build Package
26+
- name: Build sdist
2227
run: |
2328
python setup.py sdist --formats=gztar
2429
30+
- name: Build wheels
31+
run: |
32+
python -m cibuildwheel --output-dir dist
33+
2534
- name: Create artifacts
2635
uses: actions/upload-artifact@v1
2736
with:
28-
name: sdist
37+
name: wheels
2938
path: dist
3039

3140
- name: Upload to GitHub Releases
@@ -48,7 +57,6 @@ jobs:
4857
- name: Test sdist
4958
run: |
5059
pip uninstall cython -y
51-
5260
root="$(pwd)"
5361
cd ~
5462
pyobjus_fname=$(ls $root/dist/pyobjus-*.tar.gz)

.github/workflows/python-package.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: Python package
52

63
on: [push, pull_request]
@@ -11,20 +8,20 @@ jobs:
118
runs-on: macOs-latest
129
strategy:
1310
matrix:
14-
python-version: [3.6, 3.7, 3.8, 3.9]
11+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
1512

1613
steps:
1714
- uses: actions/checkout@v2
1815
- name: Set up Python ${{ matrix.python-version }}
1916
uses: actions/setup-python@v2
2017
with:
2118
python-version: ${{ matrix.python-version }}
22-
- name: Install dependencies
19+
20+
- name: Install project
2321
run: |
24-
python -m pip install --upgrade pip
25-
pip install --timeout=120 --user -U setuptools cython pytest
26-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27-
pip install --timeout=120 --user .
22+
pip install cython pytest
23+
pip install .
24+
2825
- name: Test with pytest
2926
run: |
3027
make test_lib

setup.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from distutils.core import setup, Extension
1+
from setuptools import setup, Extension
22
from os import environ, walk
33
from os.path import dirname, join, exists
44
import sys
5-
import subprocess
65
import platform
6+
from distutils.command.build_ext import build_ext
77

88
with open(join('pyobjus', '__init__.py')) as fd:
99
VERSION = [
@@ -20,20 +20,37 @@
2020
print("Pyobjus platform is {}".format(dev_platform))
2121

2222
# OSX
23+
files = []
2324
if dev_platform == 'darwin':
24-
try:
25-
from Cython.Distutils import build_ext
26-
except ImportError:
27-
raise
2825
files = ['pyobjus.pyx']
2926
# iOS
3027
elif dev_platform == 'ios':
31-
from distutils.command.build_ext import build_ext
3228
files = ['pyobjus.c']
3329

3430

3531
class PyObjusBuildExt(build_ext, object):
3632

33+
def __new__(cls, *a, **kw):
34+
# Note how this class is declared as a subclass of distutils
35+
# build_ext as the Cython version may not be available in the
36+
# environment it is initially started in. However, if Cython
37+
# can be used, setuptools will bring Cython into the environment
38+
# thus its version of build_ext will become available.
39+
# The reason why this is done as a __new__ rather than through a
40+
# factory function is because there are distutils functions that check
41+
# the values provided by cmdclass with issublcass, and so it would
42+
# result in an exception.
43+
# The following essentially supply a dynamically generated subclass
44+
# that mix in the cython version of build_ext so that the
45+
# functionality provided will also be executed.
46+
if dev_platform != 'ios':
47+
from Cython.Distutils import build_ext as cython_build_ext
48+
build_ext_cls = type(
49+
'PyObjusBuildExt', (PyObjusBuildExt, cython_build_ext), {})
50+
return super(PyObjusBuildExt, cls).__new__(build_ext_cls)
51+
else:
52+
return super(PyObjusBuildExt, cls).__new__(cls)
53+
3754
def build_extensions(self):
3855
# create a configuration file for pyobjus (export the platform)
3956
config_pxi_fn = join(dirname(__file__), 'pyobjus', 'config.pxi')
@@ -69,6 +86,7 @@ def build_extensions(self):
6986
'ttf', 'obj', 'mtl', 'kv', 'mpg', 'glsl', 'zip', 'h', 'm', 'md',
7087
)
7188

89+
7290
def tree(source, allowed_ext=data_allowed_ext, tree_name='share/pyobjus-'):
7391
found = {}
7492

0 commit comments

Comments
 (0)