diff --git a/.circleci/config.yml b/.circleci/config.yml index 1c5a70a4..6f388daa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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: @@ -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: diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml new file mode 100644 index 00000000..1b2ad60b --- /dev/null +++ b/.github/workflows/wheels.yml @@ -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 + diff --git a/scripts/build-wheels-macOS.sh b/scripts/build-wheels-macOS.sh new file mode 100755 index 00000000..0c5f17a1 --- /dev/null +++ b/scripts/build-wheels-macOS.sh @@ -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/ . + diff --git a/setup.cfg b/setup.cfg index d82bdbbd..0d0c6295 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,7 +37,9 @@ python_requires = >= 3.5 packages = find: [options.package_data] -* = *.so +* = + *.so + *.dylib [sdist] formats = zip, gztar diff --git a/setup.py b/setup.py index 40e9aafc..02a4d08d 100644 --- a/setup.py +++ b/setup.py @@ -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} )