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

Build/install wheel for Python packages #1196

Open
wants to merge 1 commit into
base: noetic-devel
Choose a base branch
from
Open
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
29 changes: 22 additions & 7 deletions cmake/templates/python_distutils_install.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,25 @@ echo_and_run mkdir -p "$DESTDIR@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@"
echo_and_run /usr/bin/env \
PYTHONPATH="@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@:@CMAKE_BINARY_DIR@/@PYTHON_INSTALL_DIR@:$PYTHONPATH" \
CATKIN_BINARY_DIR="@CMAKE_BINARY_DIR@" \
"@PYTHON_EXECUTABLE@" \
"@CMAKE_CURRENT_SOURCE_DIR@/setup.py" \
@SETUPTOOLS_EGG_INFO@ \
build --build-base "@CMAKE_CURRENT_BINARY_DIR@" \
install \
--root="${DESTDIR-/}" \
@SETUPTOOLS_ARG_EXTRA@ --prefix="@CMAKE_INSTALL_PREFIX@" --install-scripts="@CMAKE_INSTALL_PREFIX@/@CATKIN_GLOBAL_BIN_DESTINATION@"
"@PYTHON_EXECUTABLE@" "-m" "build" \
"--no-isolation" \
"--wheel" \
"--outdir" "@CMAKE_CURRENT_BINARY_DIR@/wheel" \
"@CMAKE_CURRENT_SOURCE_DIR@"

# Use pip to install the whl archive into the workspace's install directory
WHEELFILE=$(ls "@CMAKE_CURRENT_BINARY_DIR@"/wheel/*.whl)
echo_and_run /usr/bin/env \
PYTHONPATH="@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@:@CMAKE_BINARY_DIR@/@PYTHON_INSTALL_DIR@:$PYTHONPATH" \
CATKIN_BINARY_DIR="@CMAKE_BINARY_DIR@" \
PYTHONUSERBASE="@CMAKE_INSTALL_PREFIX@" \
"@PYTHON_EXECUTABLE@" "-m" "pip" "install" \
"--root" "/" \
"--isolated" \
"--no-deps" \
"--no-index" \
"--progress-bar" "off" \
"--disable-pip-version-check" \
"--user" \
"--upgrade" \
"$WHEELFILE"
Copy link
Member Author

Choose a reason for hiding this comment

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

I tested various combinations of the --root, --target, and --prefix options available in pip (see https://stackoverflow.com/a/53870246/109517) and the --root + --user + PYTHONUSERBASE route seems the least hacky.

Copy link
Member Author

@mikepurvis mikepurvis Apr 11, 2024

Choose a reason for hiding this comment

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

This might also be over the top to be involving pip here when it could be as simple as reaching into setuptools to invoke the install/run method:

https://github.com/pypa/setuptools/blob/6ee23bf0579c52e1cbe7c97fc20fd085ff2a25c7/setuptools/command/install.py#L78-L89

Or using the new pypa/installer method as suggested in the original warning message: https://installer.pypa.io/en/stable/

4 changes: 4 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
<buildtool_depend>cmake</buildtool_depend>
<buildtool_depend condition="$ROS_PYTHON_VERSION == 2">python-setuptools</buildtool_depend>
<buildtool_depend condition="$ROS_PYTHON_VERSION == 3">python3-setuptools</buildtool_depend>
<buildtool_depend condition="$ROS_PYTHON_VERSION == 3">python3-build</buildtool_depend>
<buildtool_depend condition="$ROS_PYTHON_VERSION == 3">python3-wheel</buildtool_depend>

<buildtool_export_depend>cmake</buildtool_export_depend>
<buildtool_export_depend condition="$ROS_PYTHON_VERSION == 3">python3-setuptools</buildtool_export_depend>
<buildtool_export_depend condition="$ROS_PYTHON_VERSION == 3">python3-build</buildtool_export_depend>
<buildtool_export_depend condition="$ROS_PYTHON_VERSION == 3">python3-wheel</buildtool_export_depend>
Copy link
Member Author

Choose a reason for hiding this comment

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

Probably need a dep here for pip too; on NixOS at least neither the module nor executable is bundled with Python: https://search.nixos.org/packages?query=pip


<build_export_depend>google-mock</build_export_depend>
<build_export_depend>gtest</build_export_depend>
Expand Down