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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. use dora_core::{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("pip", &["install", "maturin"], Some(venv))
  49. .await
  50. .context("pip install maturin failed")?;
  51. run(
  52. "maturin",
  53. &["develop"],
  54. Some(&root.join("apis").join("python").join("node")),
  55. )
  56. .await
  57. .context("maturin develop failed")?;
  58. let dataflow = Path::new("dataflow.yml");
  59. run_dataflow(dataflow).await?;
  60. Ok(())
  61. }
  62. async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
  63. let cargo = std::env::var("CARGO").unwrap();
  64. // First build the dataflow (install requirements)
  65. let mut cmd = tokio::process::Command::new(&cargo);
  66. cmd.arg("run");
  67. cmd.arg("--package").arg("dora-cli");
  68. cmd.arg("--").arg("build").arg(dataflow);
  69. if !cmd.status().await?.success() {
  70. bail!("failed to run dataflow");
  71. };
  72. let mut cmd = tokio::process::Command::new(&cargo);
  73. cmd.arg("run");
  74. cmd.arg("--package").arg("dora-cli");
  75. cmd.arg("--")
  76. .arg("daemon")
  77. .arg("--run-dataflow")
  78. .arg(dataflow);
  79. if !cmd.status().await?.success() {
  80. bail!("failed to run dataflow");
  81. };
  82. Ok(())
  83. }