From a482fc17235d16771c171faf6809ef34f4ecf85c Mon Sep 17 00:00:00 2001
From: Guilhem Saurel <guilhem.saurel@laas.fr>
Date: Sun, 11 Oct 2020 01:19:37 +0200
Subject: [PATCH] get version from github api

---
 docker/manylinux2014/config/eigenpy/setup.py    | 2 +-
 docker/manylinux2014/config/hpp-fcl/setup.py    | 2 +-
 docker/manylinux2014/config/pinocchio/setup.py  | 2 +-
 docker/manylinux2014/scripts/build_wheels.sh    | 8 ++++----
 docker/manylinux2014/scripts/patch_whitelist.py | 3 +--
 docker/manylinux2014/scripts/setup.sh           | 4 +++-
 6 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/docker/manylinux2014/config/eigenpy/setup.py b/docker/manylinux2014/config/eigenpy/setup.py
index 88628ac..028c0a2 100644
--- a/docker/manylinux2014/config/eigenpy/setup.py
+++ b/docker/manylinux2014/config/eigenpy/setup.py
@@ -8,7 +8,7 @@ except FileNotFoundError:
 
 setup(
     name="eigenpy",
-    version="2.5.0",
+    version="VERSION",
     description="Bindings between Numpy and Eigen using Boost.Python",
     long_description=long_description,
     long_description_content_type="text/markdown",
diff --git a/docker/manylinux2014/config/hpp-fcl/setup.py b/docker/manylinux2014/config/hpp-fcl/setup.py
index 4dd6941..0a852d4 100644
--- a/docker/manylinux2014/config/hpp-fcl/setup.py
+++ b/docker/manylinux2014/config/hpp-fcl/setup.py
@@ -8,7 +8,7 @@ except FileNotFoundError:
 
 setup(
     name="hpp-fcl",
-    version="1.6.0",
+    version="VERSION",
     description="HPP fork of FCL -- The Flexible Collision Library",
     long_description=long_description,
     long_description_content_type="text/markdown",
diff --git a/docker/manylinux2014/config/pinocchio/setup.py b/docker/manylinux2014/config/pinocchio/setup.py
index ac8487b..a215ee7 100644
--- a/docker/manylinux2014/config/pinocchio/setup.py
+++ b/docker/manylinux2014/config/pinocchio/setup.py
@@ -8,7 +8,7 @@ except FileNotFoundError:
 
 setup(
     name="pinocchio",
-    version="2.5.0",
+    version="VERSION",
     description="A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives",
     long_description=long_description,
     long_description_content_type="text/markdown",
diff --git a/docker/manylinux2014/scripts/build_wheels.sh b/docker/manylinux2014/scripts/build_wheels.sh
index 24a8871..d4df0b7 100755
--- a/docker/manylinux2014/scripts/build_wheels.sh
+++ b/docker/manylinux2014/scripts/build_wheels.sh
@@ -3,13 +3,13 @@
 TARGET=${1:-eigenpy}
 PYVER=${2:-3.9}
 
-VERSION="$(grep version "/io/config/$TARGET/setup.py" | head -1 | cut -d'"' -f2)"
+export CMAKE_PREFIX_PATH="~/.local:/opt/openrobots"
+VERSION="$(grep version setup.py | head -1 | cut -d'"' -f2)"
 TARVER="$TARGET-$VERSION"
 WHEEL_DIR="${TARGET/-/_}-$VERSION"
 PACKAGE="$TARGET"
 [ "$TARGET" = "hpp-fcl" ] && PACKAGE=hppfcl
 PYBIN="$(find /opt/python -name "cp${PYVER/.}*")/bin"
-export CMAKE_PREFIX_PATH="~/.local:/opt/openrobots"
 INSTALLED_PREFIX="$PWD/_skbuild/linux-x86_64-$PYVER/cmake-install"
 SITE_PACKAGES="lib/python$PYVER/site-packages"
 USER_PACKAGES="$HOME/.local/$SITE_PACKAGES"
@@ -19,7 +19,7 @@ PACKAGE_DIR="$WHEEL_DIR/$WHEEL_DIR.data/data/$SITE_PACKAGES/$PACKAGE"
 
 # Install dependencies
 "$PYBIN/pip" install --user --find-links=/io/dist/ \
-    $(grep install_requires "/io/config/$TARGET/setup.py" | sed "s/.*\['//;s/'\].*//;s/,//")
+    $(grep install_requires setup.py | sed "s/.*\['//;s/'\].*//;s/,//")
 
 # Build wheels
 "$PYBIN/python" setup.py bdist_wheel -j"$(nproc)" -DBUILD_TESTING=OFF -DINSTALL_DOCUMENTATION=OFF \
@@ -54,7 +54,7 @@ for lib in "$WHEEL_DIR/${LIB_DIR}"/*
 do patchelf --set-rpath '$ORIGIN' "$lib"
 done
 
-# .cmake files should not have references to _skbuild
+# fix .cmake files: remove _skbuild references & update lib name with their hash from auditwheel
 MAIN_LIB=$(find "$WHEEL_DIR/$LIB_DIR" -name "lib$TARGET-*.so") # eigenpy-2.5.0/eigenpy.libs/libeigenpy-0c5e8890.so
 MAIN_LIB_NAME=$(basename "$MAIN_LIB") # libeigenpy-0c5e8890.so
 MAIN_LIB_NAME_NO_HASH=$(echo "$MAIN_LIB_NAME" | sed 's/-[[:xdigit:]]\{8\}//') # libeigenpy.so
diff --git a/docker/manylinux2014/scripts/patch_whitelist.py b/docker/manylinux2014/scripts/patch_whitelist.py
index 2ca3526..03cf151 100755
--- a/docker/manylinux2014/scripts/patch_whitelist.py
+++ b/docker/manylinux2014/scripts/patch_whitelist.py
@@ -13,14 +13,13 @@ from pathlib import Path
 
 import auditwheel
 
-USER_PACKAGES = Path(sys.argv[-1])
 POLICY = Path(auditwheel.__file__).parent / 'policy/policy.json'
 
 with POLICY.open() as f:
     policies = json.load(f)
 
 deps = []
-for dep in USER_PACKAGES.glob('*.libs'):
+for dep in Path(sys.argv[-1]).glob('*.libs'):
     deps.append(dep.name)
     for lib in dep.glob('*.so*'):
         policies[-1]["lib_whitelist"].append(lib.name)
diff --git a/docker/manylinux2014/scripts/setup.sh b/docker/manylinux2014/scripts/setup.sh
index f5bfb38..3f3afb0 100755
--- a/docker/manylinux2014/scripts/setup.sh
+++ b/docker/manylinux2014/scripts/setup.sh
@@ -4,7 +4,7 @@ TARGET=${1:-eigenpy}
 PYVER=${2:-3.9}
 
 URL="$(grep url "/io/config/$TARGET/setup.py" | cut -d'"' -f2)"
-VERSION="$(grep version "/io/config/$TARGET/setup.py" | head -1 | cut -d'"' -f2)"
+VERSION="$(curl -sSL "$(echo $URL | sed 's:github.com:api.github.com/repos:')/releases/latest" | grep tag_name | sed 's/[^.0-9]//g')"
 
 mkdir -p /io/wheelhouse
 [ "$(ls -A /io/wheelhouse)" ] && { echo "./wheelhouse should be empty before running this script."; exit; }
@@ -15,6 +15,8 @@ curl -sSL "$URL/releases/download/v$VERSION/$TARGET-$VERSION.tar.gz" \
 cp "/io/config/$TARGET/setup.py" .
 cp /scripts/pyproject.toml .
 
+sed -i "s/VERSION/$VERSION/" setup.py
+
 # Fix CMake for scikit-build
 find . -name CMakeLists.txt | xargs sed -i 's/PYTHON_INCLUDE_DIRS/PYTHON_INCLUDE_DIR/'
 sed -i 's/REQUIRED COMPONENTS Interpreter Development/REQUIRED COMPONENTS Interpreter/' cmake/python.cmake
-- 
GitLab