Skip to content

Commit

Permalink
Wheel for macOS
Browse files Browse the repository at this point in the history
* - draft wheel for macOS

* - added wheel testing

* - add platform tag to wheel

* - publish macOS wheel to PyPI & GHR
  • Loading branch information
miloserdova-l authored and anastasiia-kornilova committed Apr 20, 2021
1 parent df023f5 commit 25bf422
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 7 deletions.
63 changes: 58 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,56 @@ jobs:
root: ~/
paths:
- project/build/wheelhouse
test-wheel:
docker:
- image: cimg/base:stable
environment:
PYTHONPATH=./lib
steps:
- checkout
- attach_workspace:
at: ~/
- run:
name: "Install mrob & numpy"
command: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends python3-pip
python3 -m pip install ~/project/build/wheelhouse/mrob*.whl numpy
- run:
name: "Run FGraph_2d"
command: |
python3 mrobpy/tests/FGraph_2d.py
when: always
- run:
name: "Run FGraph_M3500"
command: |
python3 mrobpy/tests/FGraph_M3500.py
when: always
- run:
name: "Run FGraph_sphere"
command: |
python3 mrobpy/tests/FGraph_sphere.py
when: always
- run:
name: "Run SE3_examples"
command: |
python3 mrobpy/tests/SE3_examples.py
when: always
- run:
name: "Run FGraph_landmark_3d_example"
command: |
python3 mrobpy/tests/FGraph_landmark_3d_example.py
when: always
- run:
name: "Run FGraph_landmark_2d_example"
command: |
python3 mrobpy/tests/FGraph_landmark_2d_example.py
when: always
- run:
name: "Run PC_align"
command: |
python3 mrobpy/tests/PC_align.py
when: always
publish-github-release:
docker:
- image: cibuilds/github:0.10
Expand All @@ -98,7 +148,6 @@ jobs:
-u "${CIRCLE_PROJECT_USERNAME}" \
-r "${CIRCLE_PROJECT_REPONAME}" \
-c "${CIRCLE_SHA1}" \
-delete \
${VERSION} ~/project/build/wheelhouse/*.whl
publish-pypi:
docker:
Expand Down Expand Up @@ -133,19 +182,23 @@ workflows:
- build:
filters: *all-tags
- build-wheel:
filters: *all-tags
- publish-github-release:
requires:
- build
filters: *all-tags
- test-wheel:
requires:
- build-wheel
filters: *all-tags
- publish-github-release:
requires:
- test-wheel
filters:
<<: *all-tags
branches:
ignore: /.*/ # publish to GHR only tagged commits
- publish-pypi:
requires:
- build
- build-wheel
- test-wheel
filters:
<<: *all-tags
branches:
Expand Down
131 changes: 131 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Build macOS wheels

on: [push, pull_request]

jobs:
build_wheel:
name: Build wheel on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-10.15]
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Install packages
run: brew install coreutils

- name: Build wheel
run: sudo ./scripts/build-wheels-macOS.sh

- uses: actions/upload-artifact@v2
with:
path: ./dist/mrob*.whl

test_wheel:
name: Test Python ${{ matrix.python }} wheel on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: build_wheel
strategy:
fail-fast: false
matrix:
os: [macos-10.15]
python: [3.5, 3.9]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Download artifacts
uses: actions/download-artifact@v2

- name: Install mrob & numpy
run: |
python3 -m pip install ./artifact/mrob*.whl numpy
- name: Run FGraph_2d
run: |
python3 mrobpy/tests/FGraph_2d.py
- name: Run FGraph_M3500
run: |
python3 mrobpy/tests/FGraph_M3500.py
- name: Run FGraph_sphere
run: |
python3 mrobpy/tests/FGraph_sphere.py
- name: Run SE3_examples
run: |
python3 mrobpy/tests/SE3_examples.py
- name: Run FGraph_landmark_3d_example
run: |
python3 mrobpy/tests/FGraph_landmark_3d_example.py
- name: Run FGraph_landmark_2d_example
run: |
python3 mrobpy/tests/FGraph_landmark_2d_example.py
- name: Run PC_align
run: |
python3 mrobpy/tests/PC_align.py
publish_pypi:
name: Publish macOS wheel to PyPI
needs: test_wheel
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v2

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: artifact/

publish-github-release:
name: Publish macOS wheel to GitHub Releases
needs: test_wheel
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v2

- name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false

- name: Export release assets
id: path
run: |
whl=$(find artifact/ -name '*.whl' -exec basename {} \;)
echo "::set-output name=WHL::$whl"
- uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifact/${{ steps.path.outputs.WHL }}
asset_name: ${{ steps.path.outputs.WHL }}
asset_content_type: application/octet-stream

52 changes: 52 additions & 0 deletions scripts/build-wheels-macOS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2018, Skolkovo Institute of Science and Technology (Skoltech)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# build-wheels.sh
#
# Created on: Mar 22, 2021
# Author: Lyubov Miloserdova
# miloslubov@gmail.com
#

#!/bin/bash
set -euo pipefail
export LC_ALL=C
export MACOSX_DEPLOYMENT_TARGET=10.9

cd $(dirname $(greadlink -f "${BASH_SOURCE[0]}"))/..
mkdir -p ./build ./dist ./mrob

cp ./__init__.py ./mrob/__init__.py

cd ./build

NUMPROC=$(sysctl -n hw.ncpu)
echo "Running $NUMPROC parallel jobs"

for PYBIN in /Users/runner/hostedtoolcache/Python/3.*/x64/bin/python3.[5-9]
do
cmake .. -DPYTHON_EXECUTABLE:FILEPATH=$PYBIN \
-DCMAKE_MACOSX_RPATH=ON \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE \
-DCMAKE_INSTALL_RPATH="@loader_path"
make -j $NUMPROC

mv ../lib/* ../mrob
done

cd ../
python3 -m pip install --user -q build
python3 -m build --wheel --outdir dist/ .

4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ python_requires = >= 3.5
packages = find:

[options.package_data]
* = *.so
* =
*.so
*.dylib

[sdist]
formats = zip, gztar
Expand Down
31 changes: 30 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@

import setuptools


try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
import platform, os

class bdist_wheel(_bdist_wheel):

def finalize_options(self):
_bdist_wheel.finalize_options(self)
if platform.system() == "Darwin":
self.root_is_pure = False

def get_tag(self):
python, abi, plat = _bdist_wheel.get_tag(self)
if platform.system() == "Darwin":
python, abi = 'py3', 'none'
name = plat[:plat.find("_")]
for i in range(3):
plat = plat[plat.find("_") + 1:] # skip name and version of OS
arch = plat
version = os.getenv('MACOSX_DEPLOYMENT_TARGET').replace('.', '_')
plat = name + "_" + version + "_" + arch
return python, abi, plat

except ImportError:
bdist_wheel = None


setuptools.setup(
version_config=True
version_config=True,
cmdclass={'bdist_wheel': bdist_wheel}
)

0 comments on commit 25bf422

Please sign in to comment.