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.7 kB

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