From 9403424fc9a02db7d43522cf03395b2a711c7904 Mon Sep 17 00:00:00 2001 From: tyler-yankee Date: Wed, 22 Jan 2025 11:41:50 -0500 Subject: [PATCH] refactor pip example to use requirements.txt and install Drake from script --- .github/workflows/pip.yml | 8 ++-- drake_pip/.github/ci_build_test | 6 --- drake_pip/.github/workflows/ci.yml | 8 ++-- drake_pip/README.md | 61 ++++++++++++++++++++++-------- drake_pip/requirements.txt | 3 ++ drake_pip/setup/install_prereqs | 2 + drake_pip/setup/setup_env | 10 +++++ 7 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 drake_pip/requirements.txt create mode 100755 drake_pip/setup/setup_env diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 9a74609b..feaa82ac 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -27,11 +27,13 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.12' + - name: venv setup and install + working-directory: drake_pip + run: setup/setup_env 3.12 + shell: zsh -eufo pipefail {0} - name: pip build and test working-directory: drake_pip run: .github/ci_build_test - env: - PYTHON_VERSION: '3.12' shell: zsh -efuo pipefail {0} ubuntu_jammy_pip: name: ubuntu 22.04 jammy @@ -47,6 +49,4 @@ jobs: - name: pip build and test working-directory: drake_pip run: .github/ci_build_test - env: - PYTHON_VERSION: '3' shell: bash diff --git a/drake_pip/.github/ci_build_test b/drake_pip/.github/ci_build_test index 9228a462..10c4ac3a 100755 --- a/drake_pip/.github/ci_build_test +++ b/drake_pip/.github/ci_build_test @@ -3,13 +3,7 @@ set -euxo pipefail -"python$PYTHON_VERSION" --version -"python$PYTHON_VERSION" -m venv env - source env/bin/activate -pip install drake - -python3 -c 'import pydrake.all; print(pydrake.__file__)' cd src python3 particle_test.py diff --git a/drake_pip/.github/workflows/ci.yml b/drake_pip/.github/workflows/ci.yml index d2a20a04..3ff741e1 100644 --- a/drake_pip/.github/workflows/ci.yml +++ b/drake_pip/.github/workflows/ci.yml @@ -38,11 +38,13 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.12' + - name: venv setup and install + working-directory: drake_pip + run: setup/setup_env 3.12 + shell: zsh -eufo pipefail {0} - name: pip build and test working-directory: drake_pip run: .github/ci_build_test - env: - PYTHON_VERSION: '3.12' shell: zsh -efuo pipefail {0} ubuntu_jammy_pip: name: ubuntu 22.04 jammy @@ -58,6 +60,4 @@ jobs: - name: pip build and test working-directory: drake_pip run: .github/ci_build_test - env: - PYTHON_VERSION: '3' shell: bash diff --git a/drake_pip/README.md b/drake_pip/README.md index 7d49ff90..5b983712 100644 --- a/drake_pip/README.md +++ b/drake_pip/README.md @@ -3,36 +3,67 @@ This installs Drake using [`pip`](https://pypi.org/project/pip/), the Python package manager. -## Instructions +# Instructions -First, install the required Ubuntu packages: +Follow the setup instructions for [Ubuntu](#ubuntu-setup) +or [Mac OS](#mac-setup), and read the [General Overview](#general-overview) +for additional background information. -``` +## Ubuntu Setup + +If on Ubuntu, first install the required packages: + +```bash setup/install_prereqs ``` -For Mac users, simply ensure the correct version of Python +This script will also run `setup/setup_env`, which creates the virtual environment for this project and installs Drake. + +To start programming, simply activate the environment by calling: + +```bash +source env/bin/activate +``` + +## Mac Setup + +If on Mac OS X, simply ensure the correct version of Python is installed from Homebrew by referring to the [Supported Configurations](https://drake.mit.edu/installation.html#supported-configurations). -Create a [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment) -named `env` and activate it: +Then, run the following script to create the virtual environment for this project and install Drake: +```bash +setup/setup_env ``` -python3 -m venv env + +*Note*: If you have multiple versions of Python installed, +you can specify the correct version as an optional argument +to the script. For example, `setup/setup_env 3.12`. + +To start programming, simply activate the environment by calling: + +```bash source env/bin/activate ``` -Then install Drake for Python in the virtual environment: +## General Overview -``` -pip install drake -``` +The `setup_env` script takes care of the virtual environment +and Drake installation, but read below for a quick overview of the steps. -Call the following to ensure `pydrake` can be imported: +Create a [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment) +named `env` and activate it: +```bash +python3 -m venv env +source env/bin/activate ``` -python3 -c 'import pydrake.all; print(pydrake.__file__)' + +Then install Drake in the virtual environment using the provided `requirements.txt` file: + +```bash +pip3 install -r requirements.txt ``` That's all that is needed to use Drake from Python. @@ -42,12 +73,12 @@ For more information on what's available for Drake in Python, see [Using Drake from Python](https://drake.mit.edu/python_bindings.html) and the Python API [pydrake](https://drake.mit.edu/pydrake/index.html). -## Examples +# Examples To run the particle example tests in this directory, navigate to `src` and call the test file to execute the unit tests: -``` +```bash cd src python3 particle_test.py ``` diff --git a/drake_pip/requirements.txt b/drake_pip/requirements.txt new file mode 100644 index 00000000..c3441737 --- /dev/null +++ b/drake_pip/requirements.txt @@ -0,0 +1,3 @@ +# Currently, this only includes the most recent version of drake. +# Feel free to add more packages for your own project! +drake \ No newline at end of file diff --git a/drake_pip/setup/install_prereqs b/drake_pip/setup/install_prereqs index c85a2e8f..b1af6335 100755 --- a/drake_pip/setup/install_prereqs +++ b/drake_pip/setup/install_prereqs @@ -21,3 +21,5 @@ ${maybe_sudo} apt-get install --no-install-recommends $(cat <