Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove weird-looking argument parsing in examples #2398

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/python/api_demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ def main() -> None:
)

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

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

rr.script_setup(args, "arkitscenes")
recording_path = ensure_recording_available(args.video_id, args.include_highres)
Expand Down
3 changes: 1 addition & 2 deletions examples/python/car/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

rr.script_setup(args, "car")
log_car_data()
Expand Down
3 changes: 1 addition & 2 deletions examples/python/clock/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

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

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

rr.script_setup(args, "deep_sdf")

Expand Down
3 changes: 1 addition & 2 deletions examples/python/dicom/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()
rr.script_setup(args, "dicom")
dicom_files = ensure_dataset_downloaded()
read_and_log_dicom_dataset(dicom_files)
Expand Down
5 changes: 3 additions & 2 deletions examples/python/dna/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"""
from __future__ import annotations

import sys
from math import tau

import numpy as np
import rerun as rr # pip install rerun-sdk
from rerun_demo.data import build_color_spiral
from rerun_demo.util import bounce_lerp, interleave

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

rr.init("DNA Abacus")

Expand Down
6 changes: 4 additions & 2 deletions examples/python/minimal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"""Demonstrates the most barebone usage of the Rerun SDK."""
from __future__ import annotations

import sys

import numpy as np
import rerun as rr # pip install rerun-sdk

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

rr.init("minimal", spawn=True)

Expand Down
3 changes: 1 addition & 2 deletions examples/python/minimal_options/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.")
rr.script_add_args(parser)
args, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

rr.script_setup(args, "minimal_options")

Expand Down
3 changes: 1 addition & 2 deletions examples/python/mp_pose/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def main() -> None:
parser.add_argument("--no-segment", action="store_true", help="Don't run person segmentation.")
rr.script_add_args(parser)

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

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

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

rr.init("multiprocessing")
rr.spawn(connect=False) # this is the viewer that each child process will connect to
Expand Down
3 changes: 1 addition & 2 deletions examples/python/multithreading/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

rr.script_setup(args, "multithreading")

Expand Down
3 changes: 1 addition & 2 deletions examples/python/nyud/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

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

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

rr.script_setup(args, "objectron")

Expand Down
3 changes: 1 addition & 2 deletions examples/python/opencv_canny/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

rr.script_setup(args, "opencv_canny")

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

rr.script_setup(args, "plot")

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

rr.script_setup(args, "raw_mesh")

Expand Down
3 changes: 1 addition & 2 deletions examples/python/segment_anything/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

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

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

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

Expand Down
3 changes: 1 addition & 2 deletions examples/python/text_logging/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

rr.script_setup(args, "text_logging")

Expand Down
3 changes: 1 addition & 2 deletions examples/python/tracking_hf_opencv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ 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, unknown = parser.parse_known_args()
[__import__("logging").warning(f"unknown arg: {arg}") for arg in unknown]
args = parser.parse_args()

rr.script_setup(args, "tracking_hf_opencv")

Expand Down
38 changes: 18 additions & 20 deletions scripts/build_demo_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def save(self) -> None:

logging.info(f"Running {in_path}, outputting to {out_dir}")
os.makedirs(out_dir, exist_ok=True)

args = [
"python3",
in_path,
f"--save={out_dir}/data.rrd",
]

subprocess.run(
[
"python3",
in_path,
"--num-frames=30",
"--steps=200",
f"--save={out_dir}/data.rrd",
]
+ self.build_args,
args + self.build_args,
check=True,
)

Expand Down Expand Up @@ -100,7 +100,7 @@ def collect_examples() -> list[Example]:
title=EXAMPLES[name]["title"],
description=EXAMPLES[name]["description"],
commit=commit,
build_args=EXAMPLES[name]["build_args"].split(" "),
build_args=EXAMPLES[name]["build_args"],
)
if example.supports_save():
examples.append(example)
Expand Down Expand Up @@ -155,9 +155,7 @@ def main() -> None:
)
parser.add_argument("--skip-wasm-build", action="store_true", help="Skip the web viewer Wasm build")

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

if not args.skip_wasm_build:
build_wasm()
Expand Down Expand Up @@ -192,21 +190,21 @@ def main() -> None:
This is a swiss-army-knife example showing the usage of most of the Rerun SDK APIs.
The data logged is static and meaningless.
""",
"build_args": "",
"build_args": [],
},
"car": {
"title": "Car",
"description": """
A very simple 2D car is drawn using OpenCV, and a depth image is simulated and logged as a point cloud.
""",
"build_args": "",
"build_args": [],
},
"clock": {
"title": "Clock",
"description": """
An example visualizing an analog clock with hour, minute and seconds hands using Rerun Arrow3D primitives.
""",
"build_args": "",
"build_args": [],
},
"colmap": {
"title": "COLMAP",
Expand All @@ -221,31 +219,31 @@ def main() -> None:
and we use Rerun to visualize the individual camera frames, estimated camera poses,
and resulting point clouds over time.
""",
"build_args": "--resize=800x600",
"build_args": ["--resize=800x600"],
},
"dicom": {
"title": "Dicom",
"description": """
Example using a <a href="https://en.wikipedia.org/wiki/DICOM" target="_blank">DICOM</a> MRI scan.
This demonstrates the flexible tensor slicing capabilities of the Rerun viewer.
""",
"build_args": "",
"build_args": [],
},
"plots": {
"title": "Plots",
"description": """
This example demonstrates how to log simple plots with the Rerun SDK.
Charts can be created from 1-dimensional tensors, or from time-varying scalars.
""",
"build_args": "",
"build_args": [],
},
"raw_mesh": {
"title": "Raw Mesh",
"description": """
This example demonstrates how to use the Rerun SDK to log raw 3D meshes (so-called "triangle soups")
and their transform hierarchy. Simple material properties are supported.
""",
"build_args": "",
"build_args": [],
},
"text_logging": {
"title": "Text Logging",
Expand All @@ -255,7 +253,7 @@ def main() -> None:
Rerun is able to act as a Python logging handler, and can show all your Python log messages
in the viewer next to your other data.
""",
"build_args": "",
"build_args": [],
},
}

Expand Down
11 changes: 10 additions & 1 deletion scripts/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from types import TracebackType
from typing import Any

EXTRA_ARGS = {
"examples/python/clock": ["--steps=200"], # Make it faster
"examples/python/opencv_canny": ["--num-frames=30"], # Make sure it finishes
}


def start_process(args: list[str], cwd: str, wait: bool) -> Any:
process = subprocess.Popen(
Expand All @@ -30,7 +35,11 @@ def start_process(args: list[str], cwd: str, wait: bool) -> Any:


def run_py_example(path: str, viewer_port: int | None = None, wait: bool = True, save: str | None = None) -> Any:
args = ["python3", "main.py", "--num-frames=30", "--steps=200"]
args = ["python3", "main.py"]

if path in EXTRA_ARGS:
args += EXTRA_ARGS[path]

if save is not None:
args += [f"--save={save}"]
if viewer_port is not None:
Expand Down