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

Add scripts/run_all.py #2046

Merged
merged 4 commits into from
May 4, 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
23 changes: 4 additions & 19 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,19 @@ py-dev-env:
echo "Do 'source venv/bin/activate' to use the virtual environment!"

# 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'
py-run-all *ARGS:
python3 "scripts/run_all.py" {{ARGS}}

# 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
just py-run-all --web

# 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
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'
just py-run-all --save {{ARGS}}

# Build and install the package into the venv
py-build *ARGS:
Expand Down
90 changes: 90 additions & 0 deletions scripts/run_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python3

"""Run all examples."""

import argparse
import os
import subprocess
import time
from glob import glob
from typing import Any, List


def run_py_example(path: str, args: List[str] = []) -> None:
process = subprocess.Popen(
["python3", "main.py", "--num-frames=30", "--steps=200"] + args,
cwd=path,
)
returncode = process.wait()
print(f"process exited with error code {returncode}")


def run_saved_example(path: str, args: List[str] = []) -> None:
process = subprocess.Popen(
["cargo", "run", "-p", "rerun", "--all-features", "--", "out.rrd"] + args,
cwd=path,
)
returncode = process.wait()
print(f"process exited with error code {returncode}")


def collect_examples() -> List[str]:
return [os.path.dirname(entry) for entry in glob("examples/python/**/main.py")]


def start_viewer(args: List[str] = []) -> Any:
process = subprocess.Popen(
["cargo", "run", "-p", "rerun", "--all-features", "--"] + args,
stdout=subprocess.PIPE,
)
time.sleep(1) # give it a moment to start
return process


def run_build() -> None:
process = subprocess.Popen(
["maturin", "develop", "--manifest-path", "rerun_py/Cargo.toml", '--extras="tests"'],
)
returncode = process.wait()
assert returncode == 0, f"process exited with error code {returncode}"


def main() -> None:
parser = argparse.ArgumentParser(description="Runs all examples.")
parser.add_argument("--skip-build", action="store_true", help="Skip building the Python SDK")
parser.add_argument("--web", action="store_true", help="Run all examples in a web viewer.")
parser.add_argument(
"--save",
action="store_true",
help="Run all examples, save them to disk as rrd, then view them natively.",
)

args = parser.parse_args()

examples = collect_examples()

if not args.skip_build:
run_build()

if args.web:
viewer = start_viewer(["--web-viewer"])
for example in examples:
run_py_example(example, ["--connect"])
viewer.kill()
elif args.save:
viewer = start_viewer()
for example in examples:
run_py_example(example, ["--save", "out.rrd"])
viewer.kill()

for example in examples:
run_saved_example(example)
else:
viewer = start_viewer()
for example in examples:
run_py_example(example)
viewer.kill()


if __name__ == "__main__":
main()