Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setuptools support #296

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
name: Python CI/CD

on:
push:
branches: ['**']
tags-ignore: ['**']
pull_request:
release:
types:
- published

jobs:

build_sdist:
name: Build source distribution
runs-on: ubuntu-20.04

steps:

- name: Inspect Environment
run: |
env | grep ^GITHUB
echo ""
cat ${GITHUB_EVENT_PATH}
echo ""
env

- uses: actions/checkout@master
- run: git fetch --prune --unshallow

- uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
channel-priority: true
auto-update-conda: true
activate-environment: ci
python-version: 3.8
channels: conda-forge,robotology,defaults

- name: Mamba info
run: mamba info

- name: Mamba list
run: mamba list

- name: Install pypa/build
shell: bash -l {0}
run: mamba install build

# These dependencies can also be installed through apt.
# However, often blf needs more recent versions, therefore relying on conda-forge
# is more future-proof for what concerns CI.
# In any case, the sdist is built in this environment only for testing purpose,
# the distributed wheels are generated in a docker image compatible with manylinux.
- name: Install build dependencies
shell: bash -l {0}
run: |
# The CMake project included in the casadi wheel has few problems.
# 1) Importing the targets requires to find system dependencies that match their CI,
# probably due to non-relocatable resources.
# 2) The target of the vendored osqp is malformed, as a workaround we install osqp with
# conda and instruct blf to find it from there.
#sudo apt-get install -y coinor-libipopt-dev libmumps-dev libmumps-seq-dev
#sudo ln -s /usr/lib/x86_64-linux-gnu/libdmumps_seq.so /usr/lib/
# yarp
mamba install -y ace swig
# idyntree
mamba install -y assimp libxml2
# blf
mamba install -y compilers spdlog eigen casadi libosqp osqp-eigen qhull nlohmann_json

- name: Build the wheel from the sdist
shell: bash -l {0}
run: python -m build
# python -m build \
# -C--global-option=build_ext \
# -C--global-option="-Dosqp_DIR=$CONDA_PREFIX/lib/cmake/osqp"

- name: Install the wheel
shell: bash -l {0}
run: pip install dist/bipedal_locomotion_framework*.whl

- name: Python tests
shell: bash -l {0}
run: |
mamba install pytest
pytest $(find bindings/python/ -name "test_*.py")

- name: Remove external wheels
run: find dist/ -type f -not -name 'bipedal_locomotion_framework-*' -delete -print

- name: Inspect dist folder
run: ls -lah dist/

- uses: actions/upload-artifact@v2
with:
name: dist
path: dist/*.tar.gz

# TODO:
# Building wheels is disabled
# https://github.com/dic-iit/bipedal-locomotion-framework/pull/296#issuecomment-870492568
#
# build_wheels:
# name: Build wheels [${{ matrix.os }}]
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# python-version:
# - 3.8
# os:
# - ubuntu-20.04
# #- macos-latest
# #- windows-latest
#
# steps:
#
# - uses: actions/checkout@master
# - run: git fetch --prune --unshallow
#
# - name: Set up Python
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
#
# - name: Install cibuildwheel
# run: pip install --pre cibuildwheel
#
# - name: Build wheels
# run: python -m cibuildwheel --output-dir wheelhouse
# env:
# CIBW_BUILD_VERBOSITY: 1
# CIBW_BUILD: cp37-*_x86_64 cp38-*_x86_64 cp39-*_x86_64
# CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_24
# CIBW_ENVIRONMENT_LINUX: "AUDITWHEEL_PLAT=manylinux_2_24_x86_64 CC=clang-7 CXX=clang++-7"
# CIBW_BEFORE_ALL_LINUX: |
# apt-get update &&\
# apt-get install -y libace-dev &&\
# apt-get install -y libassimp-dev libxml2-dev coinor-libipopt-dev &&\
# apt-get install -y clang-7 libspdlog-dev libeigen3-dev &&\
# apt-get install -y git &&\
# git clone https://github.com/qhull/qhull /tmp/qhull &&\
# cmake -B /tmp/qhull/build -S /tmp/qhull &&\
# cd /tmp/qhull/build && make install &&\
# git clone --recursive https://github.com/oxfordcontrol/osqp /tmp/osqp &&\
# cmake -B /tmp/osqp/build -S /tmp/osqp -DBUILD_SHARED_LIBS:BOOL=OFF &&\
# cmake --build /tmp/osqp/build --target install &&\
# git clone https://github.com/robotology/osqp-eigen /tmp/osqp-eigen &&\
# cmake -B /tmp/osqp-eigen/build -S /tmp/osqp-eigen -DBUILD_SHARED_LIBS:BOOL=OFF &&\
# cmake --build /tmp/osqp-eigen/build --target install &&\
# git clone https://github.com/nlohmann/json /tmp/json &&\
# cmake -B /tmp/json/build -S /tmp/json -DBUILD_SHARED_LIBS:BOOL=OFF &&\
# cmake --build /tmp/json/build --target install
# CIBW_BEFORE_BUILD_LINUX: python -m pip install --upgrade pip
# CIBW_TEST_REQUIRES: pytest
# CIBW_TEST_COMMAND: "pytest $(find bindings/python/ -name 'test_*.py')"
#
# - name: Inspect wheelhouse folder
# run: ls -lah wheelhouse/
#
# - uses: actions/upload-artifact@v2
# with:
# name: dist
# path: ./wheelhouse/*.whl

upload_pypi:
needs:
- build_sdist
# - build_wheels
runs-on: ubuntu-latest
# Master branch produces pre-releases.
# GitHub Releases 'vX.Y.Z' produce stable releases.

steps:

- uses: actions/download-artifact@v2
with:
name: dist
path: dist

- name: Inspect dist folder
run: ls -lah dist/

# Validate the tag accordingly to PEP440
# From https://stackoverflow.com/a/37972030/12150968
- name: Check PEP440 compliance
if: github.event_name == 'release'
run: |
sudo apt-get update
sudo apt-get install -y source-highlight
last_tag_with_v="$(git describe --abbrev=0 --tags)"
last_tag=${last_tag_with_v#v}
rel_regexp='^(\d+!)?(\d+)(\.\d+)+([\.\-\_])?((a(lpha)?|b(eta)?|c|r(c|ev)?|pre(view)?)\d*)?(\.?(post|dev)\d*)?$'
echo ""
echo $last_tag
echo ""
check-regexp ${rel_regexp} ${last_tag}
match=$(check-regexp ${rel_regexp} ${last_tag} | grep matches | cut -d ' ' -f 5)
test $match -eq 1 && true

# TODO:
# Uploading to PyPI is currently disabled while waiting to find a workaround to build compliant wheels
# https://github.com/dic-iit/bipedal-locomotion-framework/pull/296#issuecomment-870492568
#
# - uses: pypa/gh-action-pypi-publish@master
# if: |
# github.repository == 'dic-iit/bipedal-locomotion-framework' &&
# ((github.event_name == 'release' && github.event.action == 'published') ||
# (github.event_name == 'push' && github.ref == 'refs/heads/main'))
# with:
# user: __token__
# password: ${{ secrets.PYPI_TOKEN }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project are documented in this file.
- Add a synchronization mechanism for the `AdvanceableRunner` class (https://github.com/dic-iit/bipedal-locomotion-framework/pull/403)
- Add the possibility to use spdlog with YARP (https://github.com/ami-iit/bipedal-locomotion-framework/pull/408)
- Add new Advanceable exposing `UnicyclePlanner` (https://github.com/dic-iit/bipedal-locomotion-framework/pull/320)
- Add setuptools support (https://github.com/dic-iit/bipedal-locomotion-framework/pull/296)

### Changed
- Add `name` parameter to the `AdvanceableRunner` class (https://github.com/dic-iit/bipedal-locomotion-framework/pull/406)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ option(ENABLE_RPATH "Enable RPATH for this library" ON)
mark_as_advanced(ENABLE_RPATH)
include(AddInstallRPATHSupport)
add_install_rpath_support(BIN_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}"
LIB_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
LIB_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" "${CMAKE_INSTALL_PREFIX}"
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}"
DEPENDS ENABLE_RPATH
USE_LINK_PATH)
Expand Down
2 changes: 2 additions & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if(FRAMEWORK_COMPILE_PYTHON_BINDINGS)
# Install the resulting Python package for the active interpreter
if(FRAMEWORK_DETECT_ACTIVE_PYTHON_SITEPACKAGES)
set(PYTHON_INSTDIR ${Python3_SITELIB}/bipedal_locomotion_framework)
elseif(FRAMEWORK_PACKAGE_FOR_PYPI)
set(PYTHON_INSTDIR ${CMAKE_INSTALL_PREFIX})
else()
execute_process(COMMAND ${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))"
OUTPUT_VARIABLE _PYTHON_INSTDIR)
Expand Down
11 changes: 9 additions & 2 deletions cmake/BipedalLocomotionFrameworkDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ find_package(OsqpEigen 0.6.3 QUIET)
checkandset_dependency(OsqpEigen)
dependency_classifier(OsqpEigen MINIMUM_VERSION 0.6.3 IS_USED ${FRAMEWORK_USE_OsqpEigen})

find_package(Python3 3.6 COMPONENTS Interpreter Development QUIET)
checkandset_dependency(Python3 MINIMUM_VERSION 3.6 COMPONENTS Interpreter Development)
# https://github.com/pybind/pybind11/pull/2689
if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
set(BLF_Python_Development_Component "Development")
else()
set(BLF_Python_Development_Component "Development.Module")
endif()

find_package(Python3 3.6 COMPONENTS Interpreter ${BLF_Python_Development_Component} QUIET)
checkandset_dependency(Python3 MINIMUM_VERSION 3.6 COMPONENTS Interpreter ${BLF_Python_Development_Component})

find_package(pybind11 2.4.3 CONFIG QUIET)
checkandset_dependency(pybind11)
Expand Down
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"wheel",
"setuptools>=45",
"setuptools_scm[toml]>=6.0",
"cmake-build-extension",
"pybind11",
"idyntree>=3.1.0",
# "casadi",
"ycm_cmake_modules",
# "yarp_middleware>=3.5.1",
"yarp_middleware @ git+https://github.com/robotology/[email protected]#egg=yarp_middleware&subdirectory=scripts/pip",
"manifpy @ git+https://github.com/artivis/manif",
]

[tool.setuptools_scm]
local_scheme = "dirty-tag"

[tool.cibuildwheel]
build-frontend = "build"
47 changes: 47 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[metadata]
name = bipedal_locomotion_framework
description = Suite of libraries for achieving bipedal locomotion on humanoid robots.
long_description = file: README.md
long_description_content_type = text/markdown
author = Diego Ferigo
author_email = [email protected]
license = LGPL
platforms = any
url = https://ami-iit.github.io/bipedal-locomotion-framework

project_urls =
Tracker = https://github.com/ami-iit/bipedal-locomotion-framework/issues
Documentation = https://ami-iit.github.io/bipedal-locomotion-framework
Source = https://github.com/ami-iit/bipedal-locomotion-framework

keywords =
robot
robotics
locomotion
humanoid
framework

classifiers =
Development Status :: 5 - Production/Stable
Operating System :: POSIX :: Linux
Operating System :: MacOS
Operating System :: Microsoft :: Windows
Framework :: Robot Framework
Intended Audience :: Science/Research
Intended Audience :: Developers
Intended Audience :: Education
Programming Language :: C++
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)

[options]
zip_safe = False
python_requires = >=3.6

[options.extras_require]
testing =
pytest
pytest-icdiff
all =
%(testing)s
71 changes: 71 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

import os
import sys

import cmake_build_extension
import setuptools

if "CIBUILDWHEEL" in os.environ and os.environ["CIBUILDWHEEL"] == "1":
CIBW_CMAKE_OPTIONS = [
# Prevent CMake to use lib64 on Debian Stretch
"-DCMAKE_INSTALL_LIBDIR=lib",
]
else:
CIBW_CMAKE_OPTIONS = []


setuptools.setup(
cmdclass=dict(build_ext=cmake_build_extension.BuildExtension),
ext_modules=[
cmake_build_extension.CMakeExtension(
name="BlfCMakeProject",
install_prefix="bipedal_locomotion_framework",
cmake_depends_on=[
"idyntree",
"pybind11",
"ycm_cmake_modules",
"yarp",
"manifpy",
# "casadi",
],
disable_editable=True,
cmake_configure_options=[
f"-DPython3_EXECUTABLE:PATH={sys.executable}",
"-DFRAMEWORK_PACKAGE_FOR_PYPI:BOOL=ON",
"-DBUILD_SHARED_LIBS:BOOL=OFF",
# *_USE_*
"-DFRAMEWORK_USE_Catch2:BOOL=OFF",
"-DFRAMEWORK_USE_LieGroupControllers:BOOL=OFF",
"-DFRAMEWORK_USE_OpenCV:BOOL=OFF",
"-DFRAMEWORK_USE_OsqpEigen:BOOL=ON",
"-DFRAMEWORK_USE_PCL:BOOL=OFF",
"-DFRAMEWORK_USE_Python3:BOOL=ON",
"-DFRAMEWORK_USE_Qhull:BOOL=ON",
"-DFRAMEWORK_USE_VALGRIND:BOOL=OFF",
"-DFRAMEWORK_USE_YARP:BOOL=ON",
"-DFRAMEWORK_USE_casadi:BOOL=ON",
"-DFRAMEWORK_USE_cppad:BOOL=OFF",
"-DFRAMEWORK_USE_manif:BOOL=ON",
"-DFRAMEWORK_USE_matioCpp:BOOL=OFF",
"-DFRAMEWORK_USE_nlohmann_json:BOOL=ON",
"-DFRAMEWORK_USE_pybind11:BOOL=ON",
"-DFRAMEWORK_USE_realsense2:BOOL=OFF",
"-DFRAMEWORK_USE_tomlplusplus:BOOL=OFF",
# *_COMPILE_*
"-DFRAMEWORK_COMPILE_Contact:BOOL=ON",
"-DFRAMEWORK_COMPILE_Math:BOOL=ON",
"-DFRAMEWORK_COMPILE_PYTHON_BINDINGS:BOOL=ON",
"-DFRAMEWORK_COMPILE_Planners:BOOL=ON",
"-DFRAMEWORK_COMPILE_RobotInterface:BOOL=ON",
"-DFRAMEWORK_COMPILE_System:BOOL=ON",
"-DFRAMEWORK_COMPILE_YarpImplementation:BOOL=ON",
"-DFRAMEWORK_COMPILE_YarpUtilities:BOOL=ON",
"-DFRAMEWORK_COMPILE_JointPositionTrackingApplication:BOOL=OFF",
]
+ CIBW_CMAKE_OPTIONS,
)
],
)