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 basic testing automation against all version of Python using nox #2536

Merged
merged 10 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ screenshot*.png

# Web demo app build
web_demo

.nox/
8 changes: 8 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ py-run-all-web:
py-run-all-rrd *ARGS:
just py-run-all --save {{ARGS}}

# Run all example with all supported Python versions (through nox)
emilk marked this conversation as resolved.
Show resolved Hide resolved
py-run-all-allpy *ARGS:
nox -s run_all -- {{ARGS}}

# Build and install the package into the venv
py-build *ARGS:
#!/usr/bin/env bash
Expand Down Expand Up @@ -84,6 +88,10 @@ py-lint:
py-test:
python -m pytest -vv rerun_py/tests/unit/

# Run tests on all supported Python versions (through nox)
py-test-allpy:
nox -s tests

# Serve the python docs locally
py-docs-serve:
mkdocs serve -f rerun_py/mkdocs.yml -w rerun_py
Expand Down
26 changes: 26 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Nox sessions.

This file is used by `nox` to run tests and examples against multiple Python versions.

See: http://nox.thea.codes
"""

from __future__ import annotations
abey79 marked this conversation as resolved.
Show resolved Hide resolved

import nox # type: ignore


@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
def tests(session: nox.Session) -> None:
"""Run the Python test suite"""
session.install("-r", "rerun_py/requirements-build.txt")
session.install("./rerun_py")
session.run("just", "py-test", external=True)


@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
def run_all(session: nox.Session) -> None:
"""Run all examples through the run_all.py script (pass args with: "-- <args>")"""
# Note: the run_all.py scripts installs all dependencies itself. In particular, we can install from
# examples/python/requirements.txt because it includes pyrealsense2, which is not available for mac.
session.run("python", "scripts/run_all.py", "--install-requirements", *session.posargs)
26 changes: 26 additions & 0 deletions scripts/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess
import time
from glob import glob
from pathlib import Path
from types import TracebackType
from typing import Any

Expand Down Expand Up @@ -184,6 +185,25 @@ def run_viewer_build() -> None:
assert returncode == 0, f"process exited with error code {returncode}"


def run_install_requirements(examples: list[str]) -> None:
"""Install dependencies for the provided list of examples if they have a requirements.txt file."""
args = []
for example in examples:
req = Path(example) / "requirements.txt"
if req.exists():
args.extend(["-r", req])

print("Installing examples requirements…")
returncode = subprocess.Popen(
[
"pip",
"install",
*args,
]
).wait()
assert returncode == 0, f"process exited with error code {returncode}"


def run_web(examples: list[str], separate: bool) -> None:
if not separate:
with Viewer(close=True, web=True) as viewer:
Expand Down Expand Up @@ -271,6 +291,9 @@ def run_native(examples: list[str], separate: bool, close: bool) -> None:
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(
"--install-requirements", action="store_true", help="Install Python requirements for each example."
)
parser.add_argument("--web", action="store_true", help="Run examples in a web viewer.")
parser.add_argument(
"--save",
Expand All @@ -292,6 +315,9 @@ def main() -> None:
run_sdk_build()
run_viewer_build()

if args.install_requirements:
run_install_requirements(examples)

if args.web:
run_web(examples, separate=args.separate)
return
Expand Down
15 changes: 11 additions & 4 deletions scripts/setup_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ set -x

cargo install cargo-cranky # Uses lints defined in Cranky.toml. See https://github.com/ericseppanen/cargo-cranky
cargo install --locked cargo-deny # https://github.com/EmbarkStudios/cargo-deny
cargo install just # Just a command runner
cargo install taplo-cli --locked # toml formatter/linter/lsp
cargo install typos-cli
cargo install just # https://github.com/casey/just - a command runner
cargo install taplo-cli --locked # https://github.com/tamasfe/taplo - toml formatter/linter/lsp
cargo install typos-cli # https://github.com/crate-ci/typos - typo detector


packagesNeeded='pngcrush'
packagesNeeded='pngcrush pipx'
if [ -x "$(command -v brew)" ]; then brew install $packagesNeeded
elif [ -x "$(command -v port)" ]; then sudo port install $packagesNeeded
elif [ -x "$(command -v apt-get)" ]; then sudo apt-get -y install $packagesNeeded
Expand All @@ -29,4 +29,11 @@ else
exit 1
fi

# ensure pipx is on the path
pipx ensurepath

# install nox for python testing automation
# https://nox.thea.codes/en/stable/
pipx install nox

echo "setup_dev.sh completed!"