Skip to content

Commit

Permalink
just py-run-all-{native|web|rrd} (#1927)
Browse files Browse the repository at this point in the history
* make all python examples handle unknown arguments gracefully

* just py-run-all-{native|web|rrd}
  • Loading branch information
teh-cmc authored Apr 19, 2023
1 parent b14087b commit 42a5ba2
Show file tree
Hide file tree
Showing 24 changed files with 71 additions and 31 deletions.
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out.rrd
3 changes: 2 additions & 1 deletion examples/python/api_demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ def main() -> None:
)

rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "api_demo")

Expand Down
3 changes: 2 additions & 1 deletion examples/python/arkitscenes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ def main() -> None:
help="Include the high resolution camera and depth images",
)
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "arkitscenes")
recording_path = ensure_recording_available(args.video_id, args.include_highres)
Expand Down
3 changes: 2 additions & 1 deletion examples/python/car/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def generate_car_data(num_frames: int) -> Iterator[SampleFrame]:
def main() -> None:
parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.")
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "car")
log_car_data()
Expand Down
3 changes: 2 additions & 1 deletion examples/python/clock/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def rotate(angle: float, len: float) -> Tuple[float, float, float]:
)
parser.add_argument("--steps", type=int, default=10_000, help="The number of time steps to log")
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "clock")
log_clock(args.steps)
Expand Down
3 changes: 2 additions & 1 deletion examples/python/colmap/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def main() -> None:
)
parser.add_argument("--resize", action="store", help="Target resolution to resize images")
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

if args.resize:
args.resize = tuple(int(x) for x in args.resize.split("x"))
Expand Down
3 changes: 2 additions & 1 deletion examples/python/deep_sdf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def main() -> None:
help="Path to a mesh to analyze. If set, overrides the `--mesh` argument.",
)
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "deep_sdf")

Expand Down
3 changes: 2 additions & 1 deletion examples/python/dicom/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def ensure_dataset_downloaded() -> Iterable[Path]:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.")
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
rr.script_setup(args, "dicom")
dicom_files = ensure_dataset_downloaded()
read_and_log_dicom_dataset(dicom_files)
Expand Down
5 changes: 2 additions & 3 deletions examples/python/dna/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
`examples/python/dna/main.py`
"""

import sys
from math import tau

import numpy as np
Expand All @@ -15,8 +14,8 @@
from rerun_demo.util import bounce_lerp, interleave
from scipy.spatial.transform import Rotation

# sanity-check since all other example scripts take arguments:
assert len(sys.argv) == 1, f"{sys.argv[0]} does not take any arguments"
_, unknown = __import__("argparse").ArgumentParser().parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.init("DNA Abacus")

Expand Down
8 changes: 3 additions & 5 deletions examples/python/minimal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

"""Demonstrates the most barebone usage of the Rerun SDK."""

import sys

import numpy as np
import rerun as rr

_, unknown = __import__("argparse").ArgumentParser().parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.spawn()

positions = np.vstack([xyz.ravel() for xyz in np.mgrid[3 * [slice(-5, 5, 10j)]]]).T
colors = np.vstack([rgb.ravel() for rgb in np.mgrid[3 * [slice(0, 255, 10j)]]]).astype(np.uint8).T

rr.log_points("my_points", positions=positions, colors=colors)


# sanity-check since all other example scripts take arguments:
assert len(sys.argv) == 1, f"{sys.argv[0]} does not take any arguments"
3 changes: 2 additions & 1 deletion examples/python/mp_pose/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def main() -> None:
parser.add_argument("--no-segment", action="store_true", help="Don't run person segmentation.")
rr.script_add_args(parser)

args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
rr.script_setup(args, "mp_pose")

video_path = args.video_path # type: str
Expand Down
3 changes: 2 additions & 1 deletion examples/python/multiprocessing/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def task(title: str) -> None:

def main() -> None:
parser = argparse.ArgumentParser(description="Test multi-process logging to the same Rerun server")
parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.init("multiprocessing")
rr.spawn(connect=False) # this is the viewer that each process will connect to
Expand Down
3 changes: 2 additions & 1 deletion examples/python/multithreading/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def rect_logger(path: str, color: npt.NDArray[np.float32]) -> None:
def main() -> None:
parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.")
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "multithreading")

Expand Down
1 change: 0 additions & 1 deletion examples/python/notebook/cube.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"STEPS = 100\n",
"twists = math.pi * np.sin(np.linspace(0, math.tau, STEPS)) / 4\n",
"for t in range(STEPS):\n",
Expand Down
3 changes: 2 additions & 1 deletion examples/python/nyud/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def download_progress(url: str, dst: Path) -> None:
)
parser.add_argument("--subset-idx", type=int, default=0, help="The index of the subset of the recording to use.")
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "nyud")
recording_path = ensure_recording_downloaded(args.recording)
Expand Down
3 changes: 2 additions & 1 deletion examples/python/objectron/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ def main() -> None:
)

rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "objectron")

Expand Down
3 changes: 2 additions & 1 deletion examples/python/opencv_canny/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def main() -> None:
parser.add_argument("--num-frames", type=int, default=None, help="The number of frames to log")

rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "opencv_canny")

Expand Down
3 changes: 2 additions & 1 deletion examples/python/plots/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def main() -> None:
description="demonstrates how to integrate python's native `logging` with the Rerun SDK"
)
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "plot")

Expand Down
3 changes: 2 additions & 1 deletion examples/python/raw_mesh/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def main() -> None:
help="Path to a scene to analyze. If set, overrides the `--scene` argument.",
)
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "raw_mesh")

Expand Down
3 changes: 2 additions & 1 deletion examples/python/segment_anything/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def main() -> None:
parser.add_argument("images", metavar="N", type=str, nargs="*", help="A list of images to process.")

rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "segment_anything")
logging.getLogger().addHandler(rr.LoggingHandler("logs"))
Expand Down
3 changes: 2 additions & 1 deletion examples/python/stable_diffusion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def main() -> None:
)

rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "Depth Guided Stable Diffusion")

Expand Down
3 changes: 2 additions & 1 deletion examples/python/text_logging/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def main() -> None:
)
parser.add_argument("--repeat", type=int, default=1, help="How many times do we want to run the log function?")
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "text_logging")

Expand Down
3 changes: 2 additions & 1 deletion examples/python/tracking_hf_opencv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ def main() -> None:
parser.add_argument("--dataset_dir", type=Path, default=DATASET_DIR, help="Directory to save example videos to.")
parser.add_argument("--video_path", type=str, default="", help="Full path to video to run on. Overrides `--video`.")
rr.script_add_args(parser)
args = parser.parse_args()
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]

rr.script_setup(args, "tracking_hf_opencv")

Expand Down
30 changes: 27 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,35 @@ py-dev-env:
venv/bin/pip install -r rerun_py/requirements-lint.txt
echo "Do 'source venv/bin/activate' to use the virtual environment!"
# Run all examples
py-run-all: py-build
# Run all examples with the specified args
py-run-all *ARGS: py-build
#!/usr/bin/env bash
set -euo pipefail
find examples/python/ -name main.py | xargs -I _ sh -c 'cd $(dirname _) && echo $(pwd) && python3 main.py {{ARGS}} --num-frames=30 --steps=200'
# Run all examples in the native viewer
py-run-all-native: py-run-all

# Run all examples in the web viewer
py-run-all-web:
#!/usr/bin/env bash
set -euo pipefail
function cleanup {
kill $(jobs -p)
}
trap cleanup EXIT

cargo r -p rerun --all-features -- --web-viewer &
just py-run-all --connect

# Run all examples, save them to disk as rrd, then view them natively
py-run-all-rrd *ARGS:
#!/usr/bin/env bash
set -euo pipefail
fd main.py | xargs -I _ sh -c "echo _ && python3 _"
just py-run-all --save out.rrd
cargo r -p rerun --all-features --
find examples/python/ -name main.py | xargs -I _ sh -c 'cd $(dirname _) && echo $(pwd) && cargo r -p rerun --all-features -- out.rrd'
# Build and install the package into the venv
py-build *ARGS:
Expand Down

0 comments on commit 42a5ba2

Please sign in to comment.