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

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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-operator-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_python_path().context("Could not get pip binary")?,
  50. &["-m", "pip", "install", "--upgrade", "pip"],
  51. None,
  52. )
  53. .await
  54. .context("failed to install pip")?;
  55. run(
  56. get_pip_path().context("Could not get pip binary")?,
  57. &["install", "-r", "requirements.txt"],
  58. None,
  59. )
  60. .await
  61. .context("pip install failed")?;
  62. run(
  63. "maturin",
  64. &["develop"],
  65. Some(&root.join("apis").join("python").join("node")),
  66. )
  67. .await
  68. .context("maturin develop failed")?;
  69. let dataflow = Path::new("dataflow.yml");
  70. run_dataflow(dataflow).await?;
  71. Ok(())
  72. }
  73. async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
  74. let cargo = std::env::var("CARGO").unwrap();
  75. let mut cmd = tokio::process::Command::new(&cargo);
  76. cmd.arg("run");
  77. cmd.arg("--package").arg("dora-cli");
  78. cmd.arg("--")
  79. .arg("daemon")
  80. .arg("--run-dataflow")
  81. .arg(dataflow);
  82. if !cmd.status().await?.success() {
  83. bail!("failed to run dataflow");
  84. };
  85. Ok(())
  86. }