Skip to content
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
56 changes: 30 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
sudo -H -u runner ./setup/submodule_checkout
# Install system packages as root
INSTALL_JUPYTER=0 ./setup/ubuntu/24.04/install_prereqs.sh
sudo -H -u runner python3 -m pip install --user --break-system-packages poetry==2.1.4
sudo -H -u runner python3 -m pip install --user --break-system-packages poetry==2.5.1
sudo -H -u runner python3 -m poetry config virtualenvs.in-project true
sudo -H -u runner python3 -m poetry install --all-extras --with dev
rm -rf /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin /var/lib/apt/lists/* /var/log/apt/*
Expand Down Expand Up @@ -182,25 +182,23 @@ jobs:
if-no-files-found: ignore
retention-days: 14

# TODO(russt): add noble-pip-core workflow which only runs the tests in manipulation,
# but uses the manipulation module from pip.
# TODO(russt): add noble-pip-core workflow which only runs the tests in
# manipulation, but uses the manipulation module from pip.
noble-pip-all:
name: ubuntu noble using pip all
name: ubuntu noble using wheel all
runs-on: ubuntu-24.04
container: ubuntu:24.04
needs: [check-approval]
if: >
((github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository)
||
(github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository &&
needs.check-approval.outputs.should-run == 'true')
||
(github.event_name != 'pull_request' &&
github.event_name != 'pull_request_target'))
&&
!contains(github.event.pull_request.labels.*.name, 'requires new pip wheels')
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository)
||
(github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository &&
needs.check-approval.outputs.should-run == 'true')
||
(github.event_name != 'pull_request' &&
github.event_name != 'pull_request_target')
steps:
- name: pre-checkout setup
run: |
Expand Down Expand Up @@ -248,14 +246,17 @@ jobs:
sudo -H -u runner ./setup/submodule_checkout
# Install system packages as root
./setup/ubuntu/24.04/install_prereqs.sh
rm -rf ./manipulation # remove local module, force pip module.
# Test this revision's wheel before publishing a release to PyPI.
sudo -H -u runner python3 -m pip wheel --no-deps --wheel-dir /tmp/manipulation-wheels .
WHEEL_PATH="$(find /tmp/manipulation-wheels -name 'manipulation-*.whl')"
rm -rf ./manipulation # Force the tests to import the installed wheel.
# CPU wheels are a CI-only choice; leave published requirements unchanged.
sudo -H -u runner python3 -m pip install --user --break-system-packages \
--index-url https://download.pytorch.org/whl/cpu 'torch>=2.3,<3.0' 'torchvision>=0.18,<1.0'
# Keep the subsequent resolver from replacing these with GPU builds.
sudo -H -u runner python3 -c 'from importlib.metadata import version; print("\n".join(f"{p}=={version(p)}" for p in ("torch", "torchvision")))' > /tmp/ci-torch-constraints.txt
sudo -H -u runner python3 -m pip install --user --break-system-packages \
--constraint /tmp/ci-torch-constraints.txt --upgrade manipulation[all] pytest pytest-timeout 'pytest-xdist>=3.6,<4'
--constraint /tmp/ci-torch-constraints.txt "${WHEEL_PATH}[all]" pytest pytest-timeout 'pytest-xdist>=3.6,<4'
sudo -H -u runner python3 -c 'import torch, torchvision; print(torch.__version__, torchvision.__version__); assert "+cpu" in torch.__version__ and "+cpu" in torchvision.__version__; assert torch.version.cuda is None'
rm -rf /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin /var/lib/apt/lists/* /var/log/apt/*
shell: bash
Expand Down Expand Up @@ -287,6 +288,7 @@ jobs:

tahoe:
name: macos tahoe 26
# Drake 1.58+ only publishes macOS 26 (arm64) wheels.
runs-on: macos-26
needs: [check-approval]
if: >
Expand Down Expand Up @@ -317,7 +319,7 @@ jobs:
submodules: recursive

- name: setup python
uses: actions/setup-python@v5
uses: actions/setup-python@v7
with:
python-version: '3.13'

Expand All @@ -337,22 +339,24 @@ jobs:
run: |
./setup/submodule_checkout
./setup/mac/install_prereqs.sh
python -m pip install --user poetry==2.1.4
python -m pip install --user poetry==2.5.1
python -m poetry config virtualenvs.in-project true
python -m poetry env use "$(python -c 'import sys; print(sys.executable)')"
python -m poetry install --all-extras --with dev
# Enable lcm multicast; see drake #22322 for details.
sudo route -nv delete 224.0.0.0/4
sudo route -nv add -net 224.0.0.0/4 -interface lo0
shell: zsh -efuo pipefail {0}

- name: configure LCM multicast loopback
run: |
# https://drake.mit.edu/troubleshooting.html#lcm-macos
sudo route -nv delete 224.0.0.0/4 || true
sudo route -nv add -net 224.0.0.0/4 -interface lo0

- name: prefetch remote packages
run: XDG_CACHE_HOME=/tmp .venv/bin/python -m setup.prefetch_remotes
shell: zsh -efuo pipefail {0}

- name: test
run: |
set -euo pipefail
XDG_CACHE_HOME=/tmp DRAKE_ALLOW_NETWORK=lcm:meshcat .venv/bin/python -m pytest -n 2 --dist loadfile -ra --durations=30 --junitxml=test-results/pytest.xml
shell: zsh -efuo pipefail {0}

Expand All @@ -366,7 +370,7 @@ jobs:
retention-days: 14

lint:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: [check-approval]
if: >
(github.event_name == 'pull_request' &&
Expand Down Expand Up @@ -396,7 +400,7 @@ jobs:
submodules: recursive

- name: setup python
uses: actions/setup-python@v5
uses: actions/setup-python@v7
with:
python-version: '3.10'

Expand All @@ -420,7 +424,7 @@ jobs:
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 2.1.4
version: 2.5.1
virtualenvs-create: true
virtualenvs-in-project: true

Expand Down
2 changes: 1 addition & 1 deletion book/htmlbook
92 changes: 10 additions & 82 deletions book/test_notebook_coverage.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
"""Check that every notebook in the book is executed by some test.

A notebook is covered when an `ipynb_test(...)` call in a `test_*.py` file in
the notebook's directory registers it. Exercise notebooks are generated from
the private solutions checkout, so a registration in
`solutions/notebooks/<chapter>/` also covers `book/<chapter>/exercises/`; that
check is skipped when the checkout is absent.

Notebooks that cannot run in CI must be listed in `UNTESTED` with a reason, so
that disabling a test leaves a visible record.
See htmlbook/notebook_coverage.py. Notebooks that cannot run in CI must be
listed in `UNTESTED` with a reason.
"""

from __future__ import annotations

import ast
import subprocess
from pathlib import Path

import pytest
from htmlbook.notebook_coverage import (
assert_book_notebooks_are_tested,
assert_exercise_notebooks_are_tested,
assert_untested_list_is_current,
)

REPO_ROOT = Path(__file__).resolve().parents[1]
BOOK = REPO_ROOT / "book"
Expand All @@ -35,83 +30,16 @@
}


def _book_notebooks() -> list[Path]:
"""Tracked notebooks in book/, excluding submodules."""
output = subprocess.check_output(
["git", "ls-files", "--", "*.ipynb"], cwd=BOOK, text=True
)
return sorted(BOOK / line for line in output.splitlines())


def _registered_notebooks(directory: Path) -> set[str]:
"""Notebook names registered via ipynb_test() in directory/test_*.py."""
names = set()
for test_file in directory.glob("test_*.py"):
tree = ast.parse(test_file.read_text(encoding="utf-8"))
for node in ast.walk(tree):
if (
isinstance(node, ast.Call)
and isinstance(node.func, ast.Name)
and node.func.id == "ipynb_test"
and node.args
and isinstance(node.args[0], ast.Constant)
):
names.add(node.args[0].value)
return names


def _is_exercise(notebook: Path) -> bool:
return notebook.parent.name == "exercises"


def _publicly_covered(notebook: Path) -> bool:
return notebook.name in _registered_notebooks(notebook.parent)


def _relative(notebook: Path) -> str:
return notebook.relative_to(BOOK).as_posix()


def test_book_notebooks_are_tested() -> None:
missing = [
_relative(nb)
for nb in _book_notebooks()
if not _is_exercise(nb)
and not _publicly_covered(nb)
and _relative(nb) not in UNTESTED
]
assert not missing, (
"These notebooks are not run by any test. Register each one with "
"ipynb_test() in a test_*.py file in its directory, or add it to "
f"UNTESTED in {Path(__file__).name} with the reason it cannot run:\n "
+ "\n ".join(missing)
)
assert_book_notebooks_are_tested(BOOK, UNTESTED)


def test_untested_list_is_current() -> None:
notebooks = {_relative(nb): nb for nb in _book_notebooks()}
stale = []
for path in UNTESTED:
if path not in notebooks:
stale.append(f"{path}: no such tracked notebook")
elif _publicly_covered(notebooks[path]):
stale.append(f"{path}: now registered with ipynb_test()")
assert not stale, "Remove these entries from UNTESTED:\n " + "\n ".join(stale)
assert_untested_list_is_current(BOOK, UNTESTED)


@pytest.mark.skipif(
not SOLUTIONS_NOTEBOOKS.is_dir(), reason="needs the solutions checkout"
)
def test_exercise_notebooks_are_tested() -> None:
missing = []
for nb in _book_notebooks():
if not _is_exercise(nb) or _publicly_covered(nb):
continue
chapter = nb.parent.parent.name
if nb.name not in _registered_notebooks(SOLUTIONS_NOTEBOOKS / chapter):
missing.append(_relative(nb))
assert not missing, (
"These exercise notebooks are not run by any public or solutions test. "
"Register each one with ipynb_test() in "
"solutions/notebooks/<chapter>/test_*.py:\n " + "\n ".join(missing)
)
assert_exercise_notebooks_are_tested(BOOK, SOLUTIONS_NOTEBOOKS)
29 changes: 24 additions & 5 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ normal user cache (or `XDG_CACHE_HOME`, when set).

Each CI test job runs `python -m setup.prefetch_remotes` before pytest,
using the same Python installation, user, and `XDG_CACHE_HOME=/tmp` as the tests.
The pip job prefetches using the installed manipulation wheel, matching its tests.
The prefetch retries failed downloads (see `book/htmlbook/drake_remotes.py`).
The pip job builds a wheel from the commit under test, installs it, and
prefetches using that installation, matching its tests.
During pytest, `DRAKE_ALLOW_NETWORK=lcm:meshcat` disables PackageMap downloads
while allowing Meshcat and LCM. Notebook subprocesses inherit these settings.
An uncached remote package therefore fails instead of silently downloading.
Expand All @@ -21,13 +23,30 @@ DRAKE_ALLOW_NETWORK=lcm:meshcat .venv/bin/python -m pytest -ra

If a test reports that PackageMap networking is disabled and no matching cache
entry exists, check that prefetch and pytest use the same user and cache directory.
If a test adds a new remote package, add it to `setup/prefetch_remotes.py`, which
also works with the pip job's published wheel. This list covers packages used
by tests; it deliberately excludes models such as Gymnasium Robotics that
notebooks only download in interactive mode.
If a test adds a new remote package, add it to `setup/prefetch_remotes.py`.
This list covers packages used by tests; it deliberately excludes models such
as Gymnasium Robotics that notebooks only download in interactive mode.

See Drake's [network policy documentation](https://drake.mit.edu/doxygen_cxx/group__allow__network.html).

# Notebook coverage

`book/test_notebook_coverage.py` fails when a tracked notebook is not
registered with `ipynb_test()` in a `test_*.py` file in its directory. Notebooks
that cannot run in CI go in its `UNTESTED` mapping with a reason. Exercise
notebooks are covered by tests in the solutions checkout; that check is skipped
when `solutions/` is absent. The shared logic is in
`book/htmlbook/notebook_coverage.py`.

# Solutions in CI

When the `SOLUTIONS_TOKEN` repository secret is set, each test job clones
`RobotLocomotion/manipulation-solutions` at the revision in
`solutions_sha.txt`, and pytest runs its tests too. Without the secret, the
jobs skip the solutions tests. Fork pull requests do not receive secrets until
a maintainer applies the `approved-for-ci` label, which runs the workflow
through `pull_request_target`.

# CI timings

Each test job prints its 30 slowest pytest phases and uploads a JUnit report as
Expand Down
53 changes: 0 additions & 53 deletions manipulation/test/test_remote_cache.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup/mac/Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

brew "python@3.13"
brew "tidy-html5"
brew "gprof2dot" # Supplies dot for pydot
brew "graphviz" # Supplies dot for pydot
2 changes: 1 addition & 1 deletion setup/mac/install_prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

set -euxo pipefail

if [[ "${EUID}" -eq 0 ]]; then
if [[ "${EUID:-}" -eq 0 ]]; then
echo 'ERROR: This script must NOT be run as root' >&2
exit 1
fi
Expand Down
Loading
Loading