Skip to content

Commit 08d2fe8

Browse files
authored
Merge pull request #39 from mc-rtc/topic/cython
Add cython bindings
2 parents 91dcd4f + ca45dcc commit 08d2fe8

16 files changed

Lines changed: 287 additions & 42 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Current status:
1010
Allows to build mc-rtc and configure its runtime dependencies (`robots`, `controllers`, `observers`, `plugins`)
1111
- [x] Run `MCFrankaControl` with real Panda robots
1212
- [x] `mc-rtc-magnum` support (with older `glfw/imgui/implot` as submodules, as done in `mc-rtc-superbuild`)
13-
- [ ] Robots - all most commonly used robots are supported:
13+
- [x] Robots - all most commonly used robots are supported:
1414
- [x] JVRC1
1515
- [x] HRP-2Kai
1616
- [x] HRP-4
@@ -24,9 +24,9 @@ Current status:
2424
- [ ] UR10
2525
- [ ] Controllers
2626
- [x] Rolkneematics `panda-prosthesis` (through downstream flake in `panda-prosthesis` repository)
27-
- [ ] WIP: Hugo's polytopeController
27+
- [x] Hugo's polytopeController
2828
- [ ] `mc-mujoco`: building and running but some HiDPI scaling issues on Wayland with glfw 3.4
29-
- [ ] magnum packaging (external): in progress
29+
- [x] magnum packaging
3030
- [x] magnum
3131
- [x] SDL2Application: works
3232
- [x] GlfwApplication:

module.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let
1414
rawOverlays = [
1515
{
1616
name = "mc-rtc-pkgs";
17-
value = import ./overlay.nix { inherit with-ros; };
17+
value = import ./overlay.nix { inherit lib with-ros; };
1818
}
1919
]
2020
++ (lib.optional enablePrivateOverlay {
@@ -69,9 +69,11 @@ in
6969
// {
7070
# Main dependencies
7171
inherit (pkgs)
72+
eigen3-to-python
7273
spacevecalg
7374
rbdyn
7475
sch-core
76+
sch-core-python
7577
tasks
7678
tasks-qld
7779
tvm

overlay.nix

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Use this to access and override existing packages, or to call functions from the underlying package set.
77
*/
88
{
9+
lib,
910
with-ros ? false,
1011
...
1112
}:
@@ -45,11 +46,13 @@
4546
'';
4647
});
4748

49+
eigen3-to-python = prev.callPackage ./pkgs/eigen3-to-python { };
4850
spacevecalg = prev.callPackage ./pkgs/spacevecalg { };
4951
rbdyn = prev.callPackage ./pkgs/rbdyn { };
5052
eigen-qld = prev.callPackage ./pkgs/eigen-qld { };
5153
eigen-quadprog = prev.callPackage ./pkgs/eigen-quadprog { };
5254
sch-core = prev.callPackage ./pkgs/sch-core { };
55+
sch-core-python = prev.callPackage ./pkgs/sch-core-python { };
5356
#sch-visualization = prev.callPackage ./pkgs/sch-visualization {};
5457
sch-visualization = prev.callPackage ./pkgs/sch-visualization { };
5558
tasks-qld = prev.callPackage ./pkgs/tasks { };
@@ -221,7 +224,7 @@
221224
# This is not per-say recomended, but it can drastically reduce build time for these components, and also allow for seamless LSP integration in your editor.
222225
#
223226
# TODO: investigate use of ccacheStdenv
224-
# mc-rtc-superbuild = prev.callPackage ./pkgs/mc-rtc/mc-rtc-superbuild-symlinkjoin.nix.nix {
227+
# mc-rtc-superbuild = prev.callPackage ./pkgs/mc-rtc/mc-rtc-superbuild-symlinkjoin.nix.nix
225228

226229
# minimal superbuild environment (jvrc1, mc_rtc_ticker)
227230
mc-rtc-superbuild-minimal = prev.callPackage ./pkgs/mc-rtc/mc-rtc-superbuild-standalone.nix {
@@ -265,5 +268,18 @@
265268
};
266269

267270
sphinx-cmake = prev.callPackage ./pkgs/sphinx-cmake.nix { };
271+
272+
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
273+
(
274+
python-final: _python-prev:
275+
{
276+
# custom overrides would go here see gepetto/nix for examples
277+
}
278+
// lib.filesystem.packagesFromDirectoryRecursive {
279+
inherit (python-final) callPackage;
280+
directory = ./py-pkgs;
281+
}
282+
)
283+
];
268284
}
269285
)

pkgs/eigen3-to-python/default.nix

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
stdenv,
3+
lib,
4+
cmake,
5+
pkg-config,
6+
eigen,
7+
fetchFromGitHub,
8+
python3Packages,
9+
}:
10+
11+
stdenv.mkDerivation {
12+
pname = "eigen3-to-python";
13+
version = "1.0.7";
14+
15+
# pr 35
16+
src = fetchFromGitHub {
17+
owner = "Kooolkimooov";
18+
repo = "Eigen3ToPython";
19+
rev = "a1dfb35c204b2732d0b60d4d2bb6edb4c6941f59";
20+
hash = "sha256-zNaMmaexyDBD2frMkO4z+Qj/AKtIxt6sRdwYcwoNJh8=";
21+
};
22+
23+
nativeBuildInputs = [
24+
cmake
25+
pkg-config
26+
python3Packages.cython
27+
python3Packages.python
28+
python3Packages.distutils
29+
python3Packages.pytest
30+
python3Packages.pip
31+
];
32+
33+
propagatedBuildInputs = [
34+
eigen
35+
python3Packages.numpy
36+
];
37+
38+
cmakeFlags = [
39+
"-DPIP_INSTALL_PREFIX=$out/lib/python3"
40+
"-DCMAKE_BUILD_TYPE=Release"
41+
"-DCYTHON_USE_CACHE=OFF"
42+
];
43+
44+
# Force pip to ignore the EXTERNALLY-MANAGED restriction in the sandbox
45+
PIP_BREAK_SYSTEM_PACKAGES = 1;
46+
# Force pip to use the Nix-provided python packages instead of checking PyPI
47+
PIP_NO_BUILD_ISOLATION = 1;
48+
49+
# Force Cython/Python to use the build directory for caching instead of /homeless-shelter
50+
preBuild = ''
51+
export HOME=$TMPDIR
52+
'';
53+
54+
doCheck = true;
55+
56+
# Override the default CMake install step
57+
installPhase = ''
58+
runHook preInstall
59+
60+
# 1. Define the destination directory inside the Nix store output
61+
# Using python.sitePackages handles the "lib/python3.13/site-packages" string automatically
62+
local targetDir="$out/${python3Packages.python.sitePackages}/eigen"
63+
mkdir -p "$targetDir"
64+
65+
ls -lR
66+
67+
# 2. Copy your built files from the build tree to the target store path
68+
# (Adjust 'build/python/Release/eigen/' path if your build folder structure differs slightly)
69+
cp -r python/Release/eigen/* "$targetDir"
70+
71+
runHook postInstall
72+
'';
73+
74+
meta = with lib; {
75+
description = "Provide Eigen3 to numpy conversion";
76+
homepage = "https://github.com/jrl-umi3218/Eigen3ToPython";
77+
license = licenses.bsd2;
78+
platforms = platforms.all;
79+
};
80+
}

pkgs/mc-rtc/mc-rtc-common.nix

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
let
66
version = "2.14.1";
7+
# TODO: PR 538
78
src = fetchFromGitHub {
8-
owner = "jrl-umi3218";
9+
owner = "Kooolkimooov";
910
repo = "mc_rtc";
10-
rev = "d1bb28f9bfab85a04ce1ff103289676cfa5bf4fc";
11-
hash = "sha256-a8Wh5Xhvs+vM7k0uEJzSDCSUOK58AJSRSJx3XyboHO0=";
11+
rev = "2846f365824531f162635323d0c32796842e02a8";
12+
hash = "sha256-zTxxZOZCwlMGrRGG8B9kRLJcCvXLvYSigej8yDpihwg=";
1213
};
1314
in
1415
{

pkgs/mc-rtc/mc-rtc.nix

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
libtool,
1616
geos,
1717
spdlog,
18+
fmt,
1819
ndcurves,
1920
mc-rtc-data,
2021
state-observation,
@@ -23,9 +24,8 @@
2324
rapidjson,
2425
boost,
2526
mesh-sampling,
26-
python313Packages,
27+
python3Packages,
2728
qt5,
28-
eigen-fmt,
2929
doxygen,
3030
bundler, # Ruby for bundle dependencies
3131
with-ros ? false,
@@ -61,6 +61,10 @@ in
6161
pkg-config
6262
jrl-cmakemodules
6363
qt5.wrapQtAppsHook
64+
python3Packages.distutils
65+
python3Packages.pytest
66+
python3Packages.cython
67+
python3Packages.python
6468
]
6569
++ [
6670
# for documentation
@@ -83,13 +87,16 @@ in
8387
rapidjson
8488
boost
8589
mesh-sampling
86-
eigen-fmt
87-
]
88-
++ [
89-
python313Packages.gitpython
90-
python313Packages.pyqt5
91-
python313Packages.matplotlib
90+
fmt
91+
python3Packages.tasks
9292
]
93+
++
94+
# for python utils (mc_rtc_new_fsm_controller, mc_log_ui, etc)
95+
[
96+
python3Packages.gitpython
97+
python3Packages.pyqt5
98+
python3Packages.matplotlib
99+
]
93100
++ lib.optional (with-ros && rclcpp != null) rclcpp
94101
++ lib.optional (with-ros && nav-msgs != null) nav-msgs
95102
++ lib.optional (with-ros && sensor-msgs != null) sensor-msgs
@@ -106,7 +113,6 @@ in
106113
cmakeFlags = [
107114
"-DBUILD_MC_RTC_PYTHON_UTILS=ON"
108115
"-DBUILD_TESTING=OFF"
109-
"-DPYTHON_BINDING=OFF"
110116
"-DINSTALL_DOCUMENTATION=ON"
111117
];
112118

pkgs/rbdyn/default.nix

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
tinyxml-2,
88
boost,
99
fetchurl,
10+
python3Packages,
1011
}:
1112

1213
stdenv.mkDerivation rec {
@@ -18,20 +19,26 @@ stdenv.mkDerivation rec {
1819
sha256 = "sha256-IFqX4z8r2JTwgNnPB35/vZKwgWoPO78ebnUvPdNOnjY=";
1920
};
2021

21-
nativeBuildInputs = [ cmake ];
22+
nativeBuildInputs = [
23+
cmake
24+
python3Packages.cython
25+
python3Packages.python
26+
python3Packages.distutils
27+
python3Packages.pytest
28+
];
29+
2230
propagatedBuildInputs = [
2331
spacevecalg
2432
yaml-cpp
2533
tinyxml-2
2634
boost
35+
python3Packages.spacevecalg
2736
]; # Add other dependencies here
2837

29-
postPatch = ''
30-
# Remove the include from the main CMakeLists.txt
31-
sed -i '/include(cmake\/cython\/cython.cmake)/d' CMakeLists.txt
32-
33-
# Add the include to the top of the python binding CMakeLists.txt
34-
sed -i '1i include(cmake/cython/cython.cmake)' binding/python/CMakeLists.txt
38+
# XXX: Without this fixupPhase fails due to RPATHS references to /build/
39+
preFixup = ''
40+
patchelf --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE" $out/${python3Packages.python.sitePackages}/rbdyn/rbdyn.so
41+
patchelf --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE" $out/${python3Packages.python.sitePackages}/rbdyn/parsers/parsers.so
3542
'';
3643

3744
doCheck = true;

pkgs/sch-core-python/default.nix

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
lib,
3+
stdenv,
4+
cmake,
5+
sch-core,
6+
spacevecalg,
7+
python3Packages,
8+
fetchFromGitHub,
9+
}:
10+
11+
stdenv.mkDerivation rec {
12+
pname = "sch-core-python";
13+
version = "1.0.5";
14+
15+
src = fetchFromGitHub {
16+
owner = "jrl-umi3218";
17+
repo = "sch-core-python";
18+
rev = "9b4a7d8189de30dc49edc7ccb0e1283e85686e62";
19+
hash = "sha256-Ml0fATe61R7tJ5m20Y7hjDwCa/WwIIG3f+qwV1zSz8k=";
20+
};
21+
22+
nativeBuildInputs = [
23+
cmake
24+
python3Packages.cython
25+
python3Packages.python
26+
python3Packages.distutils
27+
python3Packages.pytest
28+
];
29+
propagatedBuildInputs = [
30+
sch-core
31+
spacevecalg
32+
python3Packages.spacevecalg
33+
];
34+
35+
cmakeFlags = [
36+
"-DINSTALL_DOCUMENTATION=OFF"
37+
];
38+
39+
# Override the default CMake install step
40+
installPhase = ''
41+
runHook preInstall
42+
43+
# 1. Define the destination directory inside the Nix store output
44+
# Using python.sitePackages handles the "lib/python3.13/site-packages" string automatically
45+
local targetDir="$out/${python3Packages.python.sitePackages}/sch"
46+
mkdir -p "$targetDir"
47+
48+
ls -lR
49+
50+
# 2. Copy your built files from the build tree to the target store path
51+
# (Adjust 'build/python/Release/eigen/' path if your build folder structure differs slightly)
52+
cp -r python/Release/sch/* "$targetDir"
53+
54+
runHook postInstall
55+
'';
56+
57+
doCheck = false;
58+
59+
meta = with lib; {
60+
description = "sch-core: python bindings for sch-core - effective proximity queries";
61+
homepage = "https://github.com/jrl-umi3218/sch-core-python";
62+
license = licenses.bsd2;
63+
platforms = platforms.all;
64+
};
65+
}

0 commit comments

Comments
 (0)