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

Use PDM to manage macOS wheel dependencies #22437

Merged
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
105 changes: 98 additions & 7 deletions setup/python/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions setup/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
# the "locked" pdm output file via:
#
# tools/workspace/python/venv_upgrade
#
# This file primarily defines the set of Python dependencies that are used by
# Drake in various ways and are managed by tools/workspace/python/venv_sync.
# It is the responsibility of tools/workspace/python/repository.bzl to decide
# which dependency groups need to be installed.

[project]
name = "drake"
# The supported Python major/minor version should match the minimum listed in
# the root CMakeLists.txt and doc/_pages/from_source.md.
requires-python = ">=3.10"

# Dependencies needed to build Drake.
#
# WARNING for Drake Developers: This list must be kept in sync with
# setup/mac/binary_distribution/requirements.txt.
dependencies = [
Expand All @@ -20,12 +28,19 @@ dependencies = [
]

[dependency-groups]
# (Additional) dependencies needed to run Drake's tests.
test = [
"flask",
"six",
"u-msgpack-python",
"websockets",
]
# (Additional) dependencies needed to build a Drake wheel.
wheel = [
"delocate",
"setuptools",
"wheel",
]

[tool.pdm]
distribution = false
7 changes: 2 additions & 5 deletions tools/wheel/image/provision-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,5 @@ pip install \
semantic-version \
setuptools \
wheel \
auditwheel

if [[ "$(uname)" == "Linux" ]]; then
pip install patchelf
fi
auditwheel \
patchelf
27 changes: 7 additions & 20 deletions tools/wheel/macos/build-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,25 @@ ln -s "$(bazel info bazel-bin)" "$build_root"/bazel-bin
find "$build_root" -type d -print0 | xargs -0 chmod u+w

# -----------------------------------------------------------------------------
# Set up a Python virtual environment.
# Obtain and activate Drake's Python virtual environment.
# -----------------------------------------------------------------------------

readonly pyvenv_root="/opt/drake-wheel-build/$python/python"
readonly drake_python="$(bazel info output_base).drake_python"
readonly venv_drake="$drake_python/venv.drake"

# NOTE: Xcode ships python3, make sure to use the one from brew.
"$python_executable" -m venv "$pyvenv_root"

# We also need pythonX.Y-config, which isn't created as of writing (see also
# https://github.com/pypa/virtualenv/issues/169). Don't fail if it already
# exists, though, e.g. if the bug has been fixed.
ln -s "$python_prefix/bin/$python-config" \
"$pyvenv_root/bin/$python-config" || true # Allowed to already exist.

. "$pyvenv_root/bin/activate"
. "$venv_drake/bin/activate"

# -----------------------------------------------------------------------------
# Install tools to build the wheel.
# "Install" additional tools to build the wheel.
# -----------------------------------------------------------------------------

pip install --upgrade \
delocate \
setuptools \
wheel

ln -s \
"$build_root/bazel-bin/external/drake+/tools/wheel/strip_rpath" \
"$pyvenv_root/bin/strip_rpath"
"$venv_drake/bin/strip_rpath"

ln -s \
"$build_root/bazel-bin/external/drake+/tools/wheel/change_lpath" \
"$pyvenv_root/bin/change_lpath"
"$venv_drake/bin/change_lpath"

# -----------------------------------------------------------------------------
# Build the Drake wheel.
Expand Down
2 changes: 1 addition & 1 deletion tools/wheel/wheel_builder/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import shutil
import subprocess

from .common import create_snopt_tgz, die, wheel_name
from .common import create_snopt_tgz, die, gripe, wheel_name
from .common import build_root, resource_root, wheel_root, wheelhouse
from .common import test_root, find_tests

Expand Down
5 changes: 4 additions & 1 deletion tools/workspace/python/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ load(
"homebrew_prefix",
"which",
)
load("//tools/workspace:os.bzl", "is_wheel_build")

def _get_python_interpreter(repo_ctx):
"""Returns the tuple (python_interpreter_path, major_minor_version) based
Expand Down Expand Up @@ -131,7 +132,9 @@ def _prepare_venv(repo_ctx, python):
repo_ctx.watch(pdmlock)

# Choose which dependencies to install.
if repo_ctx.attr.requirements_flavor == "test":
if is_wheel_build(repo_ctx):
repo_ctx.file("@pdm-install-args", content = "-G wheel")
elif repo_ctx.attr.requirements_flavor == "test":
repo_ctx.file("@pdm-install-args", content = "-G test")
else:
repo_ctx.file("@pdm-install-args", content = "--prod")
Expand Down