Skip to content

Commit

Permalink
Explicitly use python3, move python override to ROS 1
Browse files Browse the repository at this point in the history
Everything uses Python 3 nowadays and the python = python3 override is
only needed for ROS 1 rosdep packages. Move this override to
ros1-overlay.nix, and make sure to use python3 explicitly everywhere
else.
  • Loading branch information
lopsided98 committed Dec 12, 2024
1 parent 51f08f3 commit 538d757
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions distros/ament-cmake-core-setup-hook/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ makeSetupHook, python }:
{ makeSetupHook, python3 }:

makeSetupHook {
name = "ament-cmake-core-setup-hook";
substitutions.python_executable = python.pythonOnBuildForHost.interpreter;
substitutions.python_executable = python3.pythonOnBuildForHost.interpreter;
} ./setup-hook.sh
12 changes: 6 additions & 6 deletions distros/build-ros-package/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, lib, pythonPackages, rosDistro, rosVersion }:
{ stdenv, lib, python3Packages, rosDistro, rosVersion }:
{ buildType ? "catkin"
# Too difficult to fix all the problems with the tests in each package
, doCheck ? false
Expand All @@ -17,7 +17,7 @@
, ...
}@args:

(if buildType == "ament_python" then pythonPackages.buildPythonPackage
(if buildType == "ament_python" then python3Packages.buildPythonPackage
else stdenv.mkDerivation) (args // {
inherit doCheck dontWrapQtApps separateDebugInfo;

Expand All @@ -41,7 +41,7 @@ else stdenv.mkDerivation) (args // {
# https://github.com/colcon/colcon-core/blob/0.12.1/colcon_core/task/python/build.py#L84
format = "other";

nativeBuildInputs = nativeBuildInputs ++ [ pythonPackages.setuptools ];
nativeBuildInputs = nativeBuildInputs ++ [ python3Packages.setuptools ];

buildPhase = ''
runHook preBuild
Expand All @@ -54,16 +54,16 @@ else stdenv.mkDerivation) (args // {
installPhase = ''
runHook preInstall
mkdir -p "$out/${pythonPackages.python.sitePackages}"
export PYTHONPATH="$out/${pythonPackages.python.sitePackages}:$PYTHONPATH"
mkdir -p "$out/${python3Packages.python.sitePackages}"
export PYTHONPATH="$out/${python3Packages.python.sitePackages}:$PYTHONPATH"
python setup.py install --prefix="$out" --single-version-externally-managed --record /dev/null
runHook postInstall
'';

postFixup = ''
${postFixup}
find "$out/lib" -mindepth 1 -maxdepth 1 -type d ! -name '${pythonPackages.python.libPrefix}' -print0 | while read -d "" libpkgdir; do
find "$out/lib" -mindepth 1 -maxdepth 1 -type d ! -name '${python3Packages.python.libPrefix}' -print0 | while read -d "" libpkgdir; do
wrapPythonProgramsIn "$libpkgdir" "$out $pythonPath"
done
'';
Expand Down
6 changes: 0 additions & 6 deletions distros/distro-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ let
python3 = pythonOverridesFor rosSelf.rosPython or self.python3;
python3Packages = rosSelf.python3.pkgs;

# While `python` in Nixpkgs is typically Python 2, this overlay has
# historically set it to Python 3 during the ROS transition. Keep it that
# way for compatibility.
python = rosSelf.python3;
pythonPackages = rosSelf.python.pkgs;

boost = self.boost.override {
python = rosSelf.python;
enablePython = true;
Expand Down
6 changes: 6 additions & 0 deletions distros/ros1-overlay.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
self:
rosSelf: rosSuper: with rosSelf.lib; {

# While `python` in Nixpkgs is typically Python 2, this overlay has
# historically set it to Python 3 as ROS 1 transitioned. Keep it that
# way for compatibility.
python = rosSelf.python3;
pythonPackages = rosSelf.python.pkgs;

# Fix usages of global Boost placeholders
# https://github.com/ros/actionlib/pull/197
actionlib = rosSuper.actionlib.overrideAttrs ({
Expand Down

1 comment on commit 538d757

@wentasah
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke a lot of things:

$ nix build -L .#humble.action-msgs
...
error: Package ‘python-2.7.18.8’ in /nix/store/avxvalb7xf8x4avmrbcvn1vr5yy46kxs-source/pkgs/development/interpreters/python/cpython/2.7/default.nix:336 is marked as insecure, refusing to evaluate.

Please sign in to comment.