Skip to content

Commit

Permalink
Build wheels for pyobjus (#84)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
matham authored Mar 18, 2022
1 parent 8ac2543 commit 586991a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
name: Deploy sdist
name: Deploy sdist/wheels

on: [push, pull_request]


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

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install cython twine
run: python -m pip install --upgrade twine cibuildwheel cython

- name: Build Package
- name: Build sdist
run: |
python setup.py sdist --formats=gztar
- name: Build wheels
run: |
python -m cibuildwheel --output-dir dist
- name: Create artifacts
uses: actions/upload-artifact@v1
with:
name: sdist
name: wheels
path: dist

- name: Upload to GitHub Releases
Expand All @@ -48,7 +57,6 @@ jobs:
- name: Test sdist
run: |
pip uninstall cython -y
root="$(pwd)"
cd ~
pyobjus_fname=$(ls $root/dist/pyobjus-*.tar.gz)
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on: [push, pull_request]
Expand All @@ -11,20 +8,20 @@ jobs:
runs-on: macOs-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies

- name: Install project
run: |
python -m pip install --upgrade pip
pip install --timeout=120 --user -U setuptools cython pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install --timeout=120 --user .
pip install cython pytest
pip install .
- name: Test with pytest
run: |
make test_lib
Expand Down
32 changes: 25 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from distutils.core import setup, Extension
from setuptools import setup, Extension
from os import environ, walk
from os.path import dirname, join, exists
import sys
import subprocess
import platform
from distutils.command.build_ext import build_ext

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

# OSX
files = []
if dev_platform == 'darwin':
try:
from Cython.Distutils import build_ext
except ImportError:
raise
files = ['pyobjus.pyx']
# iOS
elif dev_platform == 'ios':
from distutils.command.build_ext import build_ext
files = ['pyobjus.c']


class PyObjusBuildExt(build_ext, object):

def __new__(cls, *a, **kw):
# Note how this class is declared as a subclass of distutils
# build_ext as the Cython version may not be available in the
# environment it is initially started in. However, if Cython
# can be used, setuptools will bring Cython into the environment
# thus its version of build_ext will become available.
# The reason why this is done as a __new__ rather than through a
# factory function is because there are distutils functions that check
# the values provided by cmdclass with issublcass, and so it would
# result in an exception.
# The following essentially supply a dynamically generated subclass
# that mix in the cython version of build_ext so that the
# functionality provided will also be executed.
if dev_platform != 'ios':
from Cython.Distutils import build_ext as cython_build_ext
build_ext_cls = type(
'PyObjusBuildExt', (PyObjusBuildExt, cython_build_ext), {})
return super(PyObjusBuildExt, cls).__new__(build_ext_cls)
else:
return super(PyObjusBuildExt, cls).__new__(cls)

def build_extensions(self):
# create a configuration file for pyobjus (export the platform)
config_pxi_fn = join(dirname(__file__), 'pyobjus', 'config.pxi')
Expand Down Expand Up @@ -69,6 +86,7 @@ def build_extensions(self):
'ttf', 'obj', 'mtl', 'kv', 'mpg', 'glsl', 'zip', 'h', 'm', 'md',
)


def tree(source, allowed_ext=data_allowed_ext, tree_name='share/pyobjus-'):
found = {}

Expand Down

0 comments on commit 586991a

Please sign in to comment.