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

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if std::env::var("CONDA_EXE").is_ok() {
  70. let dataflow = Path::new("dataflow.yml");
  71. run_dataflow(dataflow).await?;
  72. } else {
  73. let dataflow = Path::new("dataflow_conda.yml");
  74. run_dataflow(dataflow).await?;
  75. }
  76. Ok(())
  77. }
  78. async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
  79. let cargo = std::env::var("CARGO").unwrap();
  80. let mut cmd = tokio::process::Command::new(&cargo);
  81. cmd.arg("run");
  82. cmd.arg("--package").arg("dora-cli");
  83. cmd.arg("--")
  84. .arg("daemon")
  85. .arg("--run-dataflow")
  86. .arg(dataflow);
  87. if !cmd.status().await?.success() {
  88. bail!("failed to run dataflow");
  89. };
  90. Ok(())
  91. }