Skip to content

Commit 3ea516d

Browse files
authored
Add examples for pip and poetry (#358)
1 parent 8e77639 commit 3ea516d

File tree

32 files changed

+1408
-11
lines changed

32 files changed

+1408
-11
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jobs:
2323
uses: ./.github/workflows/bazel_download.yml
2424
cmake_installed_apt:
2525
uses: ./.github/workflows/cmake_installed_apt.yml
26+
pip:
27+
uses: ./.github/workflows/pip.yml
28+
poetry:
29+
uses: ./.github/workflows/poetry.yml
2630
file_sync:
2731
name: file sync
2832
runs-on: ubuntu-latest

.github/workflows/pip.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-License-Identifier: MIT-0
2+
3+
---
4+
name: ci
5+
on:
6+
workflow_call:
7+
8+
jobs:
9+
macos_sonoma_arm_pip:
10+
name: macos sonoma 14 arm
11+
runs-on: macos-14
12+
steps:
13+
- name: checkout
14+
uses: actions/checkout@v4
15+
# See issue https://github.com/actions/setup-python/issues/577. There is
16+
# some kind of environment conflict between the symlinks found in the
17+
# GitHub Actions runner and `brew upgrade python` where `brew` detects and
18+
# refuses to overwrite symlinks. The cause for our runs is not clear,
19+
# we do not use that action, but if that issue is closed this section
20+
# can be removed.
21+
- name: sanitize GHA / brew python environment
22+
run: |
23+
# Remove the symlinks that cause issues.
24+
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
25+
sudo rm -rf /Library/Frameworks/Python.framework/
26+
- name: python setup
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.12'
30+
- name: venv setup and install
31+
working-directory: drake_pip
32+
run: setup/setup_env 3.12
33+
shell: zsh -eufo pipefail {0}
34+
- name: pip build and test
35+
working-directory: drake_pip
36+
run: .github/ci_build_test
37+
shell: zsh -efuo pipefail {0}
38+
ubuntu_jammy_pip:
39+
name: ubuntu 22.04 jammy
40+
runs-on: ubuntu-latest
41+
container: ubuntu:jammy
42+
steps:
43+
- name: checkout
44+
uses: actions/checkout@v4
45+
- name: pip setup
46+
working-directory: drake_pip
47+
run: .github/ubuntu_setup
48+
shell: bash
49+
- name: pip build and test
50+
working-directory: drake_pip
51+
run: .github/ci_build_test
52+
shell: bash

.github/workflows/poetry.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# SPDX-License-Identifier: MIT-0
2+
3+
---
4+
name: ci
5+
on:
6+
workflow_call:
7+
8+
jobs:
9+
macos_sonoma_arm_poetry:
10+
name: macos sonoma 14 arm
11+
runs-on: macos-14
12+
steps:
13+
- name: checkout
14+
uses: actions/checkout@v4
15+
# See issue https://github.com/actions/setup-python/issues/577. There is
16+
# some kind of environment conflict between the symlinks found in the
17+
# GitHub Actions runner and `brew upgrade python` where `brew` detects and
18+
# refuses to overwrite symlinks. The cause for our runs is not clear,
19+
# we do not use that action, but if that issue is closed this section
20+
# can be removed.
21+
- name: sanitize GHA / brew python environment
22+
run: |
23+
# Remove the symlinks that cause issues.
24+
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
25+
sudo rm -rf /Library/Frameworks/Python.framework/
26+
- name: python setup
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.12'
30+
- name: poetry setup
31+
working-directory: drake_poetry
32+
run: |
33+
.github/setup
34+
setup/install_prereqs 3.12
35+
shell: zsh -efuo pipefail {0}
36+
- name: poetry test
37+
working-directory: drake_poetry
38+
run: .github/ci_build_test
39+
shell: zsh -efuo pipefail {0}
40+
ubuntu_jammy_poetry:
41+
name: ubuntu 22.04 jammy
42+
runs-on: ubuntu-latest
43+
container: ubuntu:jammy
44+
steps:
45+
- name: checkout
46+
uses: actions/checkout@v4
47+
# setup and test must occur in one step
48+
# because when poetry is installed, the update to PATH
49+
# does not persist between steps on GHA
50+
- name: poetry setup and test
51+
working-directory: drake_poetry
52+
run: |
53+
.github/setup
54+
source $HOME/.profile
55+
setup/install_prereqs
56+
.github/ci_build_test
57+
shell: bash

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017-2023 by the drake-external-examples developers.
1+
Copyright (c) 2017-2025 by the drake-external-examples developers.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ own project:
88
* [`drake_cmake_external`](./drake_cmake_external)
99
* [`drake_cmake_installed`](./drake_cmake_installed)
1010
* [`drake_cmake_installed_apt`](./drake_cmake_installed_apt)
11+
* [`drake_pip`](./drake_pip)
12+
* [`drake_poetry`](./drake_poetry)
1113

1214
## Continuous Integration
1315

@@ -27,9 +29,12 @@ The intended purpose of each is described below:
2729
| `drake_cmake_external` | - | o |
2830
| `drake_cmake_installed` | o | - |
2931
| `drake_cmake_installed_apt` | o | - |
32+
| `drake_pip` | o | - |
33+
| `drake_poetry` | o | - |
3034
|| ![GitHub Actions](https://img.shields.io/github/actions/workflow/status/RobotLocomotion/drake-external-examples/ci.yml?branch=main) | [![Jenkins](https://img.shields.io/jenkins/build.svg?jobUrl=https://drake-jenkins.csail.mit.edu/job/RobotLocomotion/job/drake-external-examples/job/main)](https://drake-jenkins.csail.mit.edu/job/RobotLocomotion/job/drake-external-examples/) |
3135

3236

3337
Note, the GitHub Actions jobs only build and test `drake_bazel_download`,
34-
`drake_cmake_installed`, and `drake_cmake_installed_apt` since these are the
35-
exemplary cases for lightweight, open-source builds on public CI servers.
38+
`drake_cmake_installed`, `drake_cmake_installed_apt`, `drake_pip`, and
39+
`drake_poetry`, since these are the exemplary cases for lightweight,
40+
open-source builds on public CI servers.

drake_bazel_download/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017-2023 by the drake-external-examples developers.
1+
Copyright (c) 2017-2025 by the drake-external-examples developers.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

drake_bazel_external/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017-2023 by the drake-external-examples developers.
1+
Copyright (c) 2017-2025 by the drake-external-examples developers.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

drake_bazel_external_legacy/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017-2023 by the drake-external-examples developers.
1+
Copyright (c) 2017-2025 by the drake-external-examples developers.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

drake_cmake_external/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017-2023 by the drake-external-examples developers.
1+
Copyright (c) 2017-2025 by the drake-external-examples developers.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

drake_cmake_installed/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017-2023 by the drake-external-examples developers.
1+
Copyright (c) 2017-2025 by the drake-external-examples developers.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

drake_cmake_installed_apt/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017-2023 by the drake-external-examples developers.
1+
Copyright (c) 2017-2025 by the drake-external-examples developers.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

drake_pip/.github/ci_build_test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT-0
3+
4+
set -euxo pipefail
5+
6+
source env/bin/activate
7+
8+
cd src
9+
python3 particle_test.py
10+
11+
cd ..
12+
deactivate
13+
rm -rf env src/__pycache__

drake_pip/.github/ubuntu_setup

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT-0
3+
4+
set -euxo pipefail
5+
6+
echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries
7+
echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes
8+
9+
export DEBIAN_FRONTEND='noninteractive'
10+
11+
setup/install_prereqs

drake_pip/.github/workflows/ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-License-Identifier: MIT-0
2+
3+
---
4+
name: ci
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
- main
12+
schedule:
13+
- cron: '0 12 * * *'
14+
concurrency:
15+
# Cancel previous CI runs when additional commits are added to a pull request.
16+
# This will not cancel CI runs associated with `schedule` or `push`.
17+
group: ${{ github.head_ref || github.run_id }}
18+
cancel-in-progress: true
19+
jobs:
20+
macos_sonoma_arm_pip:
21+
name: macos sonoma 14 arm
22+
runs-on: macos-14
23+
steps:
24+
- name: checkout
25+
uses: actions/checkout@v4
26+
# See issue https://github.com/actions/setup-python/issues/577. There is
27+
# some kind of environment conflict between the symlinks found in the
28+
# GitHub Actions runner and `brew upgrade python` where `brew` detects and
29+
# refuses to overwrite symlinks. The cause for our runs is not clear,
30+
# we do not use that action, but if that issue is closed this section
31+
# can be removed.
32+
- name: sanitize GHA / brew python environment
33+
run: |
34+
# Remove the symlinks that cause issues.
35+
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
36+
sudo rm -rf /Library/Frameworks/Python.framework/
37+
- name: python setup
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: '3.12'
41+
- name: venv setup and install
42+
working-directory: drake_pip
43+
run: setup/setup_env 3.12
44+
shell: zsh -eufo pipefail {0}
45+
- name: pip build and test
46+
working-directory: drake_pip
47+
run: .github/ci_build_test
48+
shell: zsh -efuo pipefail {0}
49+
ubuntu_jammy_pip:
50+
name: ubuntu 22.04 jammy
51+
runs-on: ubuntu-latest
52+
container: ubuntu:jammy
53+
steps:
54+
- name: checkout
55+
uses: actions/checkout@v4
56+
- name: pip setup
57+
working-directory: drake_pip
58+
run: .github/ubuntu_setup
59+
shell: bash
60+
- name: pip build and test
61+
working-directory: drake_pip
62+
run: .github/ci_build_test
63+
shell: bash

drake_pip/LICENSE

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Copyright (c) 2017-2025 by the drake-external-examples developers.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16+
SOFTWARE.

drake_pip/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Python Project with Drake Installed from Pip
2+
3+
This installs Drake using [`pip`](https://pypi.org/project/pip/),
4+
the Python package manager.
5+
6+
# Instructions
7+
8+
Follow the setup instructions for [Ubuntu](#ubuntu-setup)
9+
or [Mac OS](#mac-setup).
10+
11+
See [Installation via Pip](https://drake.mit.edu/pip.html#stable-releases)
12+
for more information on installation.
13+
14+
## Ubuntu Setup
15+
16+
If on Ubuntu, first install the required packages:
17+
18+
```bash
19+
setup/install_prereqs
20+
```
21+
22+
This script will also run `setup/setup_env`, which creates the virtual environment for this project and installs Drake.
23+
24+
To start programming, simply activate the environment by calling:
25+
26+
```bash
27+
source env/bin/activate
28+
```
29+
30+
## Mac Setup
31+
32+
If on Mac OS X, simply ensure the correct version of Python
33+
is installed from Homebrew by referring to the
34+
[Supported Configurations](https://drake.mit.edu/installation.html#supported-configurations).
35+
36+
Then, run the following script to create the virtual environment for this project and install Drake:
37+
38+
```bash
39+
setup/setup_env
40+
```
41+
42+
*Note*: If you have multiple versions of Python installed,
43+
you can specify the correct version as an optional argument
44+
to the script. For example, `setup/setup_env 3.12`.
45+
46+
To start programming, simply activate the environment by calling:
47+
48+
```bash
49+
source env/bin/activate
50+
```
51+
52+
# Examples
53+
54+
To run the particle example tests in this directory,
55+
navigate to `src` and call the test file to execute the unit tests:
56+
57+
```bash
58+
cd src
59+
python3 particle_test.py
60+
```
61+
62+
For more information on what's available for Drake in Python,
63+
see [Using Drake from Python](https://drake.mit.edu/python_bindings.html)
64+
and the Python API [pydrake](https://drake.mit.edu/pydrake/index.html).

drake_pip/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Currently, this only includes the most recent version of drake.
2+
# Feel free to add more packages for your own project!
3+
drake

drake_pip/setup/install_prereqs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT-0
3+
4+
set -euxo pipefail
5+
6+
maybe_sudo=
7+
if [[ "${EUID}" -ne 0 ]]; then
8+
maybe_sudo=sudo
9+
fi
10+
11+
# Ubuntu-specific installations
12+
# See https://github.com/RobotLocomotion/drake/blob/master/tools/wheel/content/INSTALLATION
13+
# for a complete list of the required libraries to be installed.
14+
${maybe_sudo} apt-get update
15+
${maybe_sudo} apt-get install --no-install-recommends $(cat <<EOF
16+
libegl1
17+
libglib2.0-0
18+
libsm6
19+
libx11-6
20+
python3
21+
python3-venv
22+
EOF
23+
)
24+
25+
setup/setup_env

0 commit comments

Comments
 (0)