You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

run.rs 2.4 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. use dora_core::{get_pip_path, get_python_path, run};
  2. use dora_download::download_file;
  3. use dora_tracing::set_up_tracing;
  4. use eyre::{ContextCompat, WrapErr};
  5. use std::path::Path;
  6. #[tokio::main]
  7. async fn main() -> eyre::Result<()> {
  8. set_up_tracing("python-dataflow-runner")?;
  9. let root = Path::new(env!("CARGO_MANIFEST_DIR"));
  10. std::env::set_current_dir(root.join(file!()).parent().unwrap())
  11. .wrap_err("failed to set working dir")?;
  12. run(
  13. get_python_path().context("Could not get python binary")?,
  14. &["-m", "venv", "../.env"],
  15. None,
  16. )
  17. .await
  18. .context("failed to create venv")?;
  19. let venv = &root.join("examples").join(".env");
  20. std::env::set_var(
  21. "VIRTUAL_ENV",
  22. venv.to_str().context("venv path not valid unicode")?,
  23. );
  24. let orig_path = std::env::var("PATH")?;
  25. // bin folder is named Scripts on windows.
  26. // 🤦‍♂️ See: https://github.com/pypa/virtualenv/commit/993ba1316a83b760370f5a3872b3f5ef4dd904c1
  27. let venv_bin = if cfg!(windows) {
  28. venv.join("Scripts")
  29. } else {
  30. venv.join("bin")
  31. };
  32. if cfg!(windows) {
  33. std::env::set_var(
  34. "PATH",
  35. format!(
  36. "{};{orig_path}",
  37. venv_bin.to_str().context("venv path not valid unicode")?
  38. ),
  39. );
  40. } else {
  41. std::env::set_var(
  42. "PATH",
  43. format!(
  44. "{}:{orig_path}",
  45. venv_bin.to_str().context("venv path not valid unicode")?
  46. ),
  47. );
  48. }
  49. run(
  50. get_python_path().context("Could not get pip binary")?,
  51. &["-m", "pip", "install", "--upgrade", "pip"],
  52. None,
  53. )
  54. .await
  55. .context("failed to install pip")?;
  56. run(
  57. get_pip_path().context("Could not get pip binary")?,
  58. &["install", "-r", "requirements.txt"],
  59. None,
  60. )
  61. .await
  62. .context("pip install failed")?;
  63. run(
  64. "maturin",
  65. &["develop"],
  66. Some(&root.join("apis").join("python").join("node")),
  67. )
  68. .await
  69. .context("maturin develop failed")?;
  70. download_file(
  71. "https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt",
  72. Path::new("yolov8n.pt"),
  73. )
  74. .await
  75. .context("Could not download weights.")?;
  76. let dataflow = Path::new("dataflow.yml");
  77. dora_daemon::Daemon::run_dataflow(dataflow).await?;
  78. Ok(())
  79. }