Skip to content

Commit 7363aad

Browse files
committed
move Developers.md to htmlbook; because it's shared between manipualtion and underactuated
1 parent 80f2e17 commit 7363aad

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

Developers.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
```

book_name.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#! /usr/bin/env python3
2+
import os
3+
import re
4+
5+
def find_pyproject_toml(start_path=None):
6+
if start_path is None:
7+
start_path = os.getcwd()
8+
9+
pyproject_path = os.path.join(start_path, "pyproject.toml")
10+
if os.path.isfile(pyproject_path):
11+
return pyproject_path
12+
13+
parent_dir = os.path.dirname(start_path)
14+
if parent_dir == start_path: # Reached root directory
15+
raise AssertionError("could not find pyproject.toml")
16+
17+
return find_pyproject_toml(parent_dir)
18+
19+
def get_project_name():
20+
"""Extract project name from pyproject.toml file.
21+
22+
Args:
23+
pyproject_path: Path to pyproject.toml file
24+
25+
Returns:
26+
Project name as string
27+
28+
Raises:
29+
AssertionError: If project name cannot be found
30+
"""
31+
pyproject_path = find_pyproject_toml()
32+
with open(pyproject_path) as f:
33+
content = f.read()
34+
35+
# Look for name = "something" or name = 'something'
36+
match = re.search(r'''name\s*=\s*["']([^"']+)["']''', content)
37+
if not match:
38+
raise AssertionError("could not find project name in pyproject.toml")
39+
40+
return match.group(1)
41+
42+
if __name__ == "__main__":
43+
print(get_project_name())
44+
45+
46+
47+

0 commit comments

Comments
 (0)