|
| 1 | +## Requirements management with Poetry |
| 2 | + |
| 3 | +``` |
| 4 | +pip3 install poetry poetry-plugin-export |
| 5 | +poetry install --with=dev,docs |
| 6 | +``` |
| 7 | +(in a virtual environment) to install the requirements. |
| 8 | + |
| 9 | +## Please install the pre-commit hooks |
| 10 | + |
| 11 | +``` |
| 12 | +pip3 install pre-commit |
| 13 | +pre-commit install |
| 14 | +``` |
| 15 | + |
| 16 | +## Autoflake for notebooks |
| 17 | + |
| 18 | +`autoflake`` is not officially supported by nbqa because it has some risks: |
| 19 | +https://github.com/nbQA-dev/nbQA/issues/755 But it can be valuable to run it |
| 20 | +manually and check the results. |
| 21 | + |
| 22 | +``` |
| 23 | +nbqa autoflake --remove-all-unused-imports --in-place . |
| 24 | +``` |
| 25 | + |
| 26 | +## To Run the Unit Tests |
| 27 | + |
| 28 | +Install the prerequisites: |
| 29 | +```bash |
| 30 | +bash setup/.../install_prereqs.sh |
| 31 | +``` |
| 32 | + |
| 33 | +Make sure that you have done a recursive checkout in this repository, or have run |
| 34 | + |
| 35 | +```bash |
| 36 | +git submodule update --init --recursive |
| 37 | +``` |
| 38 | +Then run |
| 39 | +```bash |
| 40 | +bazel test //... |
| 41 | +``` |
| 42 | + |
| 43 | +## Updating dependencies |
| 44 | + |
| 45 | +Bazel currently uses requirements-bazel.txt, which we generate from poetry |
| 46 | + |
| 47 | +To generate it, run |
| 48 | +``` |
| 49 | +poetry lock && ./book/htmlbook/PoetryExport.sh |
| 50 | +``` |
| 51 | + |
| 52 | +## To update the pip wheels |
| 53 | + |
| 54 | +If you make a change to the dependencies or library directory, you |
| 55 | +will need to update the pip wheels. |
| 56 | +- First PR the code changes, and mark the PR with the `requires new pip wheels` label. |
| 57 | +- Once the PR is merged update the version number in `pyproject.toml`, then from |
| 58 | +the root directory, run: |
| 59 | +``` |
| 60 | +rm -rf dist/* |
| 61 | +poetry publish --build && cd book && ./Deepnote.sh |
| 62 | +``` |
| 63 | +- Finally, PR the updated pyproject.toml (without the `requires new pip wheels` label). |
| 64 | + |
| 65 | +Note: use `poetry config pypi-token.pypi <token>` once to set up your pypi token. |
| 66 | + |
| 67 | +# To update the Docker image (and pip wheels) |
| 68 | + |
| 69 | +It's good form to update the pip wheels first (so that the Docker contains the |
| 70 | +latest pip dependencies): |
| 71 | +``` |
| 72 | +rm -rf dist/* |
| 73 | +poetry publish --build |
| 74 | +./book/Deepnote_docker.sh |
| 75 | +cd book && ./Deepnote.sh |
| 76 | +``` |
| 77 | +And make sure to follow the printed instructions to build the image once on |
| 78 | +deepnote. The run a few notebooks on deepnote to convince yourself you haven't |
| 79 | +broken anything. |
| 80 | + |
| 81 | +## Building the documentation |
| 82 | + |
| 83 | +You will need to install `sphinx`: |
| 84 | +``` |
| 85 | +poetry install --with docs |
| 86 | +pip3 install sphinx myst-parser sphinx_rtd_theme |
| 87 | +``` |
| 88 | + |
| 89 | +From the root directory, run |
| 90 | +``` |
| 91 | +rm -rf book/python && sphinx-build -M html $(book/htmlbook/book_name.py) /tmp/my_doc && cp -r /tmp/my_doc/html book/python |
| 92 | +``` |
| 93 | +Note that the website will only install the dependencies in the `docs` group, so |
| 94 | +`poetry install --only docs` must obtain all of the relevant dependencies. |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +## To debug a notebook with a local build of Drake |
| 99 | + |
| 100 | +There are several approaches, but perhaps easiest is to just add a few lines at the top of the notebook: |
| 101 | +``` |
| 102 | +import sys |
| 103 | +import os |
| 104 | +
|
| 105 | +python_version = f"python{sys.version_info.major}.{sys.version_info.minor}" |
| 106 | +drake_path = os.path.expanduser(f"~/drake-install/lib/{python_version}/site-packages") |
| 107 | +if drake_path not in sys.path: |
| 108 | + sys.path.insert(0, drake_path) |
| 109 | +
|
| 110 | +import pydrake |
| 111 | +print(f"Using pydrake from: {pydrake.__file__}") |
| 112 | +``` |
0 commit comments