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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. use dora_core::get_python_path;
  2. use eyre::{ContextCompat, WrapErr};
  3. use std::path::Path;
  4. use tracing_subscriber::{
  5. filter::{FilterExt, LevelFilter},
  6. prelude::*,
  7. EnvFilter, Registry,
  8. };
  9. #[tokio::main]
  10. async fn main() -> eyre::Result<()> {
  11. set_up_tracing()?;
  12. let root = Path::new(env!("CARGO_MANIFEST_DIR"));
  13. std::env::set_current_dir(root.join(file!()).parent().unwrap())
  14. .wrap_err("failed to set working dir")?;
  15. run(
  16. &[
  17. get_python_path()
  18. .context("Could not get python binary")?
  19. .to_str()
  20. .context("Could not convert python path to string")?,
  21. "-m",
  22. "venv",
  23. "../.env",
  24. ],
  25. None,
  26. )
  27. .await
  28. .context("failed to create venv")?;
  29. let venv = &root.join("examples").join(".env");
  30. std::env::set_var(
  31. "VIRTUAL_ENV",
  32. venv.to_str().context("venv path not valid unicode")?,
  33. );
  34. let orig_path = std::env::var("PATH")?;
  35. let venv_bin = venv.join("bin");
  36. std::env::set_var(
  37. "PATH",
  38. format!(
  39. "{}:{orig_path}",
  40. venv_bin.to_str().context("venv path not valid unicode")?
  41. ),
  42. );
  43. run(&["pip", "install", "--upgrade", "pip"], None)
  44. .await
  45. .context("failed to install pip")?;
  46. run(&["pip", "install", "-r", "requirements.txt"], None)
  47. .await
  48. .context("pip install failed")?;
  49. run(
  50. &["maturin", "develop"],
  51. Some(&root.join("apis").join("python").join("node")),
  52. )
  53. .await
  54. .context("maturin develop failed")?;
  55. let dataflow = Path::new("dataflow.yml");
  56. dora_daemon::Daemon::run_dataflow(dataflow).await?;
  57. Ok(())
  58. }
  59. async fn run(cmd: &[&str], pwd: Option<&Path>) -> eyre::Result<()> {
  60. let mut run = tokio::process::Command::new(cmd[0]);
  61. run.args(&cmd[1..]);
  62. if let Some(pwd) = pwd {
  63. run.current_dir(pwd);
  64. }
  65. if !run.status().await?.success() {
  66. eyre::bail!("failed to run {cmd:?}");
  67. };
  68. Ok(())
  69. }
  70. pub fn set_up_tracing() -> eyre::Result<()> {
  71. // Filter log using `RUST_LOG`. More useful for CLI.
  72. let filter = EnvFilter::from_default_env().or(LevelFilter::DEBUG);
  73. let stdout_log = tracing_subscriber::fmt::layer()
  74. .pretty()
  75. .with_filter(filter);
  76. let registry = Registry::default().with(stdout_log);
  77. tracing::subscriber::set_global_default(registry)
  78. .context("failed to set tracing global subscriber")
  79. }