Browse Source

migrate example to uv to make it independant of virtual environment activation

tags/v0.3.10^2
haixuantao haixuanTao 11 months ago
parent
commit
0cd764980d
16 changed files with 140 additions and 298 deletions
  1. +8
    -0
      Cargo.toml
  2. +3
    -3
      examples/camera/README.md
  3. +21
    -54
      examples/camera/run.rs
  4. +4
    -4
      examples/echo/README.md
  5. +4
    -4
      examples/openai-server/README.md
  6. +4
    -4
      examples/pyarrow-test/README.md
  7. +2
    -3
      examples/python-dataflow/README.md
  8. +7
    -13
      examples/python-dataflow/dataflow.yml
  9. +21
    -54
      examples/python-dataflow/run.rs
  10. +0
    -10
      examples/realsense/README.md
  11. +3
    -17
      examples/rerun-viewer/README.md
  12. +2
    -18
      examples/rerun-viewer/dataflow.yml
  13. +22
    -55
      examples/rerun-viewer/run.rs
  14. +11
    -4
      examples/vlm/README.md
  15. +22
    -55
      examples/vlm/run.rs
  16. +6
    -0
      libraries/core/src/lib.rs

+ 8
- 0
Cargo.toml View File

@@ -118,6 +118,14 @@ tokio-stream = "0.1.11"
name = "c-dataflow"
path = "examples/c-dataflow/run.rs"

[[example]]
name = "camera"
path = "examples/camera/run.rs"

[[example]]
name = "vlm"
path = "examples/vlm/run.rs"

[[example]]
name = "rust-dataflow"
path = "examples/rust-dataflow/run.rs"


+ 3
- 3
examples/camera/README.md View File

@@ -3,7 +3,7 @@
Make sure to have, dora and pip installed.

```bash
dora up
dora build dataflow.yml
dora start dataflow.yml
uv venv -p 3.11 --seed
dora build dataflow.yml --uv
dora run dataflow.yml --uv
```

+ 21
- 54
examples/camera/run.rs View File

@@ -1,6 +1,6 @@
use dora_core::{get_pip_path, get_python_path, run};
use dora_core::{get_uv_path, run};
use dora_tracing::set_up_tracing;
use eyre::{bail, ContextCompat, WrapErr};
use eyre::{bail, WrapErr};
use std::path::Path;

#[tokio::main]
@@ -11,57 +11,27 @@ async fn main() -> eyre::Result<()> {
std::env::set_current_dir(root.join(file!()).parent().unwrap())
.wrap_err("failed to set working dir")?;

run(
get_python_path().context("Could not get python binary")?,
&["-m", "venv", "../.env"],
None,
)
.await
.context("failed to create venv")?;
let venv = &root.join("examples").join(".env");
std::env::set_var(
"VIRTUAL_ENV",
venv.to_str().context("venv path not valid unicode")?,
);
let orig_path = std::env::var("PATH")?;
// bin folder is named Scripts on windows.
// 🤦‍♂️ See: https://github.com/pypa/virtualenv/commit/993ba1316a83b760370f5a3872b3f5ef4dd904c1
let venv_bin = if cfg!(windows) {
venv.join("Scripts")
} else {
venv.join("bin")
};
let uv = get_uv_path().context("Could not get uv binary")?;

if cfg!(windows) {
std::env::set_var(
"PATH",
format!(
"{};{orig_path}",
venv_bin.to_str().context("venv path not valid unicode")?
),
);
} else {
std::env::set_var(
"PATH",
format!(
"{}:{orig_path}",
venv_bin.to_str().context("venv path not valid unicode")?
),
);
}
run(&uv, &["venv", "-p", "3.10", "--seed"], None)
.await
.context("failed to create venv")?;

run(
get_pip_path().context("Could not get pip binary")?,
&["install", "maturin"],
Some(venv),
)
.await
.context("pip install maturin failed")?;
run(&uv, &["pip", "install", "maturin"], None)
.await
.context("uv pip install maturin failed")?;

run(
"maturin",
&["develop"],
Some(&root.join("apis").join("python").join("node")),
&uv,
&[
"run",
"maturin",
"develop",
"-m",
"../../apis/python/node/Cargo.toml",
"--uv",
],
None,
)
.await
.context("maturin develop failed")?;
@@ -79,7 +49,7 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--").arg("build").arg(dataflow);
cmd.arg("--").arg("build").arg(dataflow).arg("--uv");
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};
@@ -87,10 +57,7 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--")
.arg("daemon")
.arg("--run-dataflow")
.arg(dataflow);
cmd.arg("--").arg("run").arg(dataflow).arg("--uv");
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};


+ 4
- 4
examples/echo/README.md View File

@@ -1,9 +1,9 @@
# Dora echo example

Make sure to have, dora, pip and cargo installed.
Make sure to have, dora, uv and cargo installed.

```bash
dora up
dora build dataflow.yml
dora start dataflow.yml
uv venv -p 3.11 --seed
dora build dataflow.yml --uv
dora run dataflow.yml --uv
```

+ 4
- 4
examples/openai-server/README.md View File

@@ -4,12 +4,12 @@ This is a quick example to showcase how use the `dora-openai-server` to receive

Dora Openai Server is still experimental and may change in the future.

Make sure to have, dora, pip and cargo installed.
Make sure to have, dora, uv and cargo installed.

```bash
dora up
dora build dataflow.yml
dora start dataflow.yml
uv venv -p 3.11 --seed
dora build dataflow.yml --uv
dora run dataflow.yml --uv

# In a separate terminal
python openai_api_client.py


+ 4
- 4
examples/pyarrow-test/README.md View File

@@ -1,9 +1,9 @@
# Dora echo example

Make sure to have, dora, pip and cargo installed.
Make sure to have, dora, uv and cargo installed.

```bash
dora up
dora build dataflow.yml
dora start dataflow.yml
uv venv -p 3.11 --seed
dora build dataflow.yml --uv
dora run dataflow.yml --uv
```

+ 2
- 3
examples/python-dataflow/README.md View File

@@ -21,7 +21,7 @@ Then, you will need to install the dependencies:

```bash
cd examples/python-dataflow
dora build ./dataflow.yml (or dora build ./dataflow_dynamic.yml)
dora build ./dataflow.yml --uv (or dora build ./dataflow_dynamic.yml --uv)
```

It will install the required dependencies for the Python nodes.
@@ -29,8 +29,7 @@ It will install the required dependencies for the Python nodes.
Then you can run the dataflow:

```bash
dora up
dora start ./dataflow.yml (or dora start ./dataflow_dynamic.yml)
dora run ./dataflow.yml --uv (or dora start ./dataflow_dynamic.yml --uv)
```

**Note**: if you're running the dynamic dataflow, you will need to start manually the opencv-plot node:


+ 7
- 13
examples/python-dataflow/dataflow.yml View File

@@ -1,6 +1,6 @@
nodes:
- id: camera
build: pip install ../../node-hub/opencv-video-capture
build: pip install -e ../../node-hub/opencv-video-capture
path: opencv-video-capture
inputs:
tick: dora/timer/millis/20
@@ -12,22 +12,16 @@ nodes:
IMAGE_HEIGHT: 480

- id: object-detection
build: pip install ../../node-hub/dora-yolo
build: pip install -e ../../node-hub/dora-yolo
path: dora-yolo
inputs:
image:
source: camera/image
queue_size: 1
image: camera/image
outputs:
- bbox
env:
MODEL: yolov8n.pt

- id: plot
build: pip install ../../node-hub/opencv-plot
path: opencv-plot
build: pip install -e ../../node-hub/dora-rerun
path: dora-rerun
inputs:
image:
source: camera/image
queue_size: 1
bbox: object-detection/bbox
image: camera/image
boxes2d: object-detection/bbox

+ 21
- 54
examples/python-dataflow/run.rs View File

@@ -1,6 +1,6 @@
use dora_core::{get_pip_path, get_python_path, run};
use dora_core::{get_uv_path, run};
use dora_tracing::set_up_tracing;
use eyre::{bail, ContextCompat, WrapErr};
use eyre::{bail, WrapErr};
use std::path::Path;

#[tokio::main]
@@ -11,57 +11,27 @@ async fn main() -> eyre::Result<()> {
std::env::set_current_dir(root.join(file!()).parent().unwrap())
.wrap_err("failed to set working dir")?;

run(
get_python_path().context("Could not get python binary")?,
&["-m", "venv", "../.env"],
None,
)
.await
.context("failed to create venv")?;
let venv = &root.join("examples").join(".env");
std::env::set_var(
"VIRTUAL_ENV",
venv.to_str().context("venv path not valid unicode")?,
);
let orig_path = std::env::var("PATH")?;
// bin folder is named Scripts on windows.
// 🤦‍♂️ See: https://github.com/pypa/virtualenv/commit/993ba1316a83b760370f5a3872b3f5ef4dd904c1
let venv_bin = if cfg!(windows) {
venv.join("Scripts")
} else {
venv.join("bin")
};
let uv = get_uv_path().context("Could not get uv binary")?;

if cfg!(windows) {
std::env::set_var(
"PATH",
format!(
"{};{orig_path}",
venv_bin.to_str().context("venv path not valid unicode")?
),
);
} else {
std::env::set_var(
"PATH",
format!(
"{}:{orig_path}",
venv_bin.to_str().context("venv path not valid unicode")?
),
);
}
run(&uv, &["venv", "-p", "3.10", "--seed"], None)
.await
.context("failed to create venv")?;

run(
get_pip_path().context("Could not get pip binary")?,
&["install", "maturin"],
Some(venv),
)
.await
.context("pip install maturin failed")?;
run(&uv, &["pip", "install", "maturin"], None)
.await
.context("uv pip install maturin failed")?;

run(
"maturin",
&["develop"],
Some(&root.join("apis").join("python").join("node")),
&uv,
&[
"run",
"maturin",
"develop",
"-m",
"../../apis/python/node/Cargo.toml",
"--uv",
],
None,
)
.await
.context("maturin develop failed")?;
@@ -79,7 +49,7 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--").arg("build").arg(dataflow);
cmd.arg("--").arg("build").arg(dataflow).arg("--uv");
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};
@@ -87,10 +57,7 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--")
.arg("daemon")
.arg("--run-dataflow")
.arg(dataflow);
cmd.arg("--").arg("run").arg(dataflow).arg("--uv");
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};


+ 0
- 10
examples/realsense/README.md View File

@@ -1,10 +0,0 @@
# Quick example of using Pyrealsense

Make sure to follow the installation at: [`node-hub/dora-pyrealsense/README.md`](node-hub/dora-pyrealsense/README.md)

Then:

```bash
dora build dataflow.yaml
dora run dataflow.yaml
```

+ 3
- 17
examples/rerun-viewer/README.md View File

@@ -2,24 +2,10 @@

This examples shows how to create and connect dora to rerun.

This nodes is still experimental and format for passing Images, Bounding boxes, and text are probably going to change in the future.

## Getting Started

```bash
cargo install --force rerun-cli@0.15.1

## To install this package
git clone git@github.com:dora-rs/dora.git
cargo install --git https://github.com/dora-rs/dora dora-rerun

dora start dataflow.yml --attach
uv venv -p 3.11 --seed
dora build dataflow.yml --uv
dora run dataflow.yml --uv
```

You will see two visualizations. One from matplotlib and one from rerun for comparison.

## CI/CD

This example is not tested on the CI/CD as visualization is not really testable.

Please reach out in case of issues at: https://github.com/dora-rs/dora/issues

+ 2
- 18
examples/rerun-viewer/dataflow.yml View File

@@ -12,27 +12,11 @@ nodes:
IMAGE_HEIGHT: 480
ENCODING: rgb8

- id: object-detection
build: pip install -e ../../node-hub/dora-yolo
path: dora-yolo
inputs:
image:
source: camera/image
queue_size: 1
outputs:
- bbox
env:
MODEL: yolov8n.pt
FORMAT: xywh

- id: rerun
build: cargo build -p dora-rerun --release
path: dora-rerun
inputs:
image:
source: camera/image
queue_size: 1
boxes2d: object-detection/bbox
image: camera/image
env:
RERUN_FLUSH_TICK_SECS: "0.001"
RERUN_FLUSH_TICK_SECS: 0.001
RERUN_MEMORY_LIMIT: 25%

+ 22
- 55
examples/rerun-viewer/run.rs View File

@@ -1,6 +1,6 @@
use dora_core::{get_pip_path, get_python_path, run};
use dora_core::{get_uv_path, run};
use dora_tracing::set_up_tracing;
use eyre::{bail, ContextCompat, WrapErr};
use eyre::{bail, WrapErr};
use std::path::Path;

#[tokio::main]
@@ -11,62 +11,32 @@ async fn main() -> eyre::Result<()> {
std::env::set_current_dir(root.join(file!()).parent().unwrap())
.wrap_err("failed to set working dir")?;

run(
get_python_path().context("Could not get python binary")?,
&["-m", "venv", "../.env"],
None,
)
.await
.context("failed to create venv")?;
let venv = &root.join("examples").join(".env");
std::env::set_var(
"VIRTUAL_ENV",
venv.to_str().context("venv path not valid unicode")?,
);
let orig_path = std::env::var("PATH")?;
// bin folder is named Scripts on windows.
// 🤦‍♂️ See: https://github.com/pypa/virtualenv/commit/993ba1316a83b760370f5a3872b3f5ef4dd904c1
let venv_bin = if cfg!(windows) {
venv.join("Scripts")
} else {
venv.join("bin")
};
let uv = get_uv_path().context("Could not get uv binary")?;

if cfg!(windows) {
std::env::set_var(
"PATH",
format!(
"{};{orig_path}",
venv_bin.to_str().context("venv path not valid unicode")?
),
);
} else {
std::env::set_var(
"PATH",
format!(
"{}:{orig_path}",
venv_bin.to_str().context("venv path not valid unicode")?
),
);
}
run(&uv, &["venv", "-p", "3.10", "--seed"], None)
.await
.context("failed to create venv")?;

run(
get_pip_path().context("Could not get pip binary")?,
&["install", "maturin"],
Some(venv),
)
.await
.context("pip install maturin failed")?;
run(&uv, &["pip", "install", "maturin"], None)
.await
.context("uv pip install maturin failed")?;

run(
"maturin",
&["develop"],
Some(&root.join("apis").join("python").join("node")),
&uv,
&[
"run",
"maturin",
"develop",
"-m",
"../../apis/python/node/Cargo.toml",
"--uv",
],
None,
)
.await
.context("maturin develop failed")?;

let dataflow = Path::new("dataflow.yml");
let dataflow = Path::new("qwen2-5-vl-vision-only-dev.yml");
run_dataflow(dataflow).await?;

Ok(())
@@ -79,7 +49,7 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--").arg("build").arg(dataflow);
cmd.arg("--").arg("build").arg(dataflow).arg("--uv");
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};
@@ -87,10 +57,7 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--")
.arg("daemon")
.arg("--run-dataflow")
.arg(dataflow);
cmd.arg("--").arg("run").arg(dataflow).arg("--uv");
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};


+ 11
- 4
examples/vlm/README.md View File

@@ -1,11 +1,18 @@
# Quick example on using a VLM with dora-rs

Make sure to have, dora, pip and cargo installed.
Make sure to have, dora, uv and cargo installed.

```bash
dora build https://raw.githubusercontent.com/dora-rs/dora/main/examples/vlm/qwenvl.yml
cd examples/vlm
uv venv -p 3.11 --seed
dora build qwen2-5-vl-vision-only-dev.yml --uv
dora run qwen2-5-vl-vision-only-dev.yml --uv
```

dora run https://raw.githubusercontent.com/dora-rs/dora/main/examples/vlm/qwenvl.yml
- Without cloning the repository:

# Wait for the qwenvl, whisper model to download which can takes a bit of time.
```bash
uv venv -p 3.11 --seed
dora build https://raw.githubusercontent.com/dora-rs/dora/main/examples/vlm/qwenvl.yml --uv
dora run https://raw.githubusercontent.com/dora-rs/dora/main/examples/vlm/qwenvl.yml --uv
```

+ 22
- 55
examples/vlm/run.rs View File

@@ -1,6 +1,6 @@
use dora_core::{get_pip_path, get_python_path, run};
use dora_core::{get_uv_path, run};
use dora_tracing::set_up_tracing;
use eyre::{bail, ContextCompat, WrapErr};
use eyre::{bail, WrapErr};
use std::path::Path;

#[tokio::main]
@@ -11,62 +11,32 @@ async fn main() -> eyre::Result<()> {
std::env::set_current_dir(root.join(file!()).parent().unwrap())
.wrap_err("failed to set working dir")?;

run(
get_python_path().context("Could not get python binary")?,
&["-m", "venv", "../.env"],
None,
)
.await
.context("failed to create venv")?;
let venv = &root.join("examples").join(".env");
std::env::set_var(
"VIRTUAL_ENV",
venv.to_str().context("venv path not valid unicode")?,
);
let orig_path = std::env::var("PATH")?;
// bin folder is named Scripts on windows.
// 🤦‍♂️ See: https://github.com/pypa/virtualenv/commit/993ba1316a83b760370f5a3872b3f5ef4dd904c1
let venv_bin = if cfg!(windows) {
venv.join("Scripts")
} else {
venv.join("bin")
};
let uv = get_uv_path().context("Could not get uv binary")?;

if cfg!(windows) {
std::env::set_var(
"PATH",
format!(
"{};{orig_path}",
venv_bin.to_str().context("venv path not valid unicode")?
),
);
} else {
std::env::set_var(
"PATH",
format!(
"{}:{orig_path}",
venv_bin.to_str().context("venv path not valid unicode")?
),
);
}
run(&uv, &["venv", "-p", "3.10", "--seed"], None)
.await
.context("failed to create venv")?;

run(
get_pip_path().context("Could not get pip binary")?,
&["install", "maturin"],
Some(venv),
)
.await
.context("pip install maturin failed")?;
run(&uv, &["pip", "install", "maturin"], None)
.await
.context("uv pip install maturin failed")?;

run(
"maturin",
&["develop"],
Some(&root.join("apis").join("python").join("node")),
&uv,
&[
"run",
"maturin",
"develop",
"-m",
"../../apis/python/node/Cargo.toml",
"--uv",
],
None,
)
.await
.context("maturin develop failed")?;

let dataflow = Path::new("dataflow.yml");
let dataflow = Path::new("qwen2-5-vl-vision-only-dev.yml");
run_dataflow(dataflow).await?;

Ok(())
@@ -79,7 +49,7 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--").arg("build").arg(dataflow);
cmd.arg("--").arg("build").arg(dataflow).arg("--uv");
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};
@@ -87,10 +57,7 @@ async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--")
.arg("daemon")
.arg("--run-dataflow")
.arg(dataflow);
cmd.arg("--").arg("run").arg(dataflow).arg("--uv");
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};


+ 6
- 0
libraries/core/src/lib.rs View File

@@ -56,6 +56,12 @@ pub fn get_pip_path() -> Result<std::path::PathBuf, eyre::ErrReport> {
Ok(python)
}

// Search for uv binary.
pub fn get_uv_path() -> Result<std::path::PathBuf, eyre::ErrReport> {
which::which("uv")
.context("failed to find `uv`. Make sure to install it using: https://docs.astral.sh/uv/getting-started/installation/")
}

// Helper function to run a program
pub async fn run<S>(program: S, args: &[&str], pwd: Option<&Path>) -> eyre::Result<()>
where


Loading…
Cancel
Save