diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3e33492a..7e7fc25f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,4 +3,8 @@ repos: rev: 24.10.0 hooks: - id: black - language_version: python3.9 \ No newline at end of file + language_version: python3.9 + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: fmt \ No newline at end of file diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 4d8a9b18..5890e72a 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -1,5 +1,5 @@ -use std::path::PathBuf; use serde::{Deserialize, Serialize}; +use std::path::PathBuf; use tower_api::apis::configuration::Configuration; use url::Url; @@ -208,7 +208,7 @@ impl From<&Config> for Configuration { } } -// default_cache_dir gets the path the default cache location for dependencies, etc. Note +// default_cache_dir gets the path the default cache location for dependencies, etc. Note // that you don't have to create underlying directory, uv will do that automagically for us. pub fn default_cache_dir() -> PathBuf { let dir = dirs::data_local_dir().unwrap(); diff --git a/crates/tower-cmd/src/api.rs b/crates/tower-cmd/src/api.rs index 7bc900d4..8a49b4a3 100644 --- a/crates/tower-cmd/src/api.rs +++ b/crates/tower-cmd/src/api.rs @@ -131,7 +131,7 @@ pub async fn describe_run_logs( let params = tower_api::apis::default_api::DescribeRunLogsParams { name: name.to_string(), seq, - start_at: None + start_at: None, }; unwrap_api_response(tower_api::apis::default_api::describe_run_logs( @@ -743,7 +743,10 @@ pub async fn list_environments( page_size: Some(1000), }; - unwrap_api_response(tower_api::apis::default_api::list_environments(api_config, params)).await + unwrap_api_response(tower_api::apis::default_api::list_environments( + api_config, params, + )) + .await } pub async fn create_environment( diff --git a/crates/tower-cmd/src/run.rs b/crates/tower-cmd/src/run.rs index f40517d0..ff9f5b62 100644 --- a/crates/tower-cmd/src/run.rs +++ b/crates/tower-cmd/src/run.rs @@ -599,10 +599,10 @@ async fn monitor_local_status(app: Arc>) -> Status { err_count += 1; // If we get five errors in a row, we abandon monitoring. - if err_count >= 5{ + if err_count >= 5 { debug!("Failed to get app status after 5 attempts, giving up"); output::error("An error occured while monitoring your local run status!"); - return tower_runtime::Status::Crashed { code: -1 } + return tower_runtime::Status::Crashed { code: -1 }; } // Otherwise, keep on keepin' on. diff --git a/crates/tower-cmd/src/util/apps.rs b/crates/tower-cmd/src/util/apps.rs index 494d650e..69b57aed 100644 --- a/crates/tower-cmd/src/util/apps.rs +++ b/crates/tower-cmd/src/util/apps.rs @@ -74,8 +74,8 @@ pub async fn ensure_app_exists( name: app_name.to_string(), short_description: Some(description.to_string()), slug: None, - is_externally_accessible: None, - subdomain: None + is_externally_accessible: None, + subdomain: None, }, }, ) diff --git a/crates/tower-package/src/lib.rs b/crates/tower-package/src/lib.rs index cd4644c5..b2a8f6a1 100644 --- a/crates/tower-package/src/lib.rs +++ b/crates/tower-package/src/lib.rs @@ -3,7 +3,7 @@ use glob::glob; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::collections::{HashMap, VecDeque}; -use std::path::{Path, PathBuf, Component}; +use std::path::{Component, Path, PathBuf}; use std::pin::Pin; use tmpdir::TmpDir; use tokio::{ @@ -22,7 +22,7 @@ pub use error::Error; // current version of the package format. we keep a version history here just in case anyone has // questions. will probably promote this to proper docs at some point. -// +// // Version History: // 1 - Initial version // 2 - Add app_dir, modules_dir, and checksum @@ -549,7 +549,7 @@ fn should_ignore_file(p: &PathBuf) -> bool { // normalize_path converts a Path to a normalized string with forward slashes as separators. fn normalize_path(path: &Path) -> Result { let mut next = Vec::new(); - + for component in path.components() { match component { Component::Prefix(_) | Component::RootDir => { @@ -642,7 +642,12 @@ mod test { #[tokio::test] async fn test_normalize_path() { - let path = PathBuf::from(".").join("some").join("nested").join("path").join("to").join("file.txt"); + let path = PathBuf::from(".") + .join("some") + .join("nested") + .join("path") + .join("to") + .join("file.txt"); let normalized = normalize_path(&path).unwrap(); assert_eq!(normalized, "some/nested/path/to/file.txt"); } diff --git a/crates/tower-runtime/tests/local_test.rs b/crates/tower-runtime/tests/local_test.rs index 65b6a24b..ed41c18c 100644 --- a/crates/tower-runtime/tests/local_test.rs +++ b/crates/tower-runtime/tests/local_test.rs @@ -56,7 +56,7 @@ async fn test_running_hello_world() { secrets: HashMap::new(), parameters: HashMap::new(), env_vars: HashMap::new(), - cache_dir: Some(config::default_cache_dir()) + cache_dir: Some(config::default_cache_dir()), }; // Start the app using the LocalApp runtime @@ -153,7 +153,7 @@ async fn test_running_legacy_app() { secrets: HashMap::new(), parameters: HashMap::new(), env_vars: HashMap::new(), - cache_dir: Some(config::default_cache_dir()) + cache_dir: Some(config::default_cache_dir()), }; // Start the app using the LocalApp runtime @@ -189,10 +189,13 @@ async fn test_running_legacy_app() { #[tokio::test] async fn test_running_app_with_secret() { debug!("Running 04-app-with-secret"); - + // We set a few environment variables that will be used to test the inherritance and override // behavior of child apps - std::env::set_var("PARENT_ENVIRONMENT_VARIABLE", "Something that should not get sent to the child"); + std::env::set_var( + "PARENT_ENVIRONMENT_VARIABLE", + "Something that should not get sent to the child", + ); std::env::set_var("OVERRIDDEN_ENVIRONMENT_VARIABLE", "The initial value"); let app_dir = get_example_app_dir("04-app-with-secret"); @@ -201,7 +204,10 @@ async fn test_running_app_with_secret() { let mut secrets = HashMap::new(); secrets.insert("MY_SECRET".to_string(), "It's in the sauce!".to_string()); - secrets.insert("OVERRIDDEN_ENVIRONMENT_VARIABLE".to_string(), "I reset it!".to_string()); + secrets.insert( + "OVERRIDDEN_ENVIRONMENT_VARIABLE".to_string(), + "I reset it!".to_string(), + ); // We need to create the package, which will load the app let opts = StartOptions { @@ -241,13 +247,19 @@ async fn test_running_app_with_secret() { assert!(output.line.ends_with("It's in the sauce!")); } - if output.line.starts_with("The parent environment variable is:") { + if output + .line + .starts_with("The parent environment variable is:") + { // Indicate that we found this line too. count_stdout += 1; assert!(output.line.ends_with("default_value")); } - if output.line.starts_with("The overridden environment variable is:") { + if output + .line + .starts_with("The overridden environment variable is:") + { // Indicate that we found the last line. count_stdout += 1; assert!(output.line.ends_with("I reset it!")); @@ -257,7 +269,11 @@ async fn test_running_app_with_secret() { } assert!(count_setup > 0, "There should be some setup output"); - assert!(count_stdout == 3, "should be three output lines from the program, there were {}", count_stdout); + assert!( + count_stdout == 3, + "should be three output lines from the program, there were {}", + count_stdout + ); // check the status once more, should be done. let status = app.status().await.expect("Failed to get app status"); diff --git a/crates/tower-uv/src/lib.rs b/crates/tower-uv/src/lib.rs index f625307f..6afe6e3a 100644 --- a/crates/tower-uv/src/lib.rs +++ b/crates/tower-uv/src/lib.rs @@ -68,7 +68,7 @@ fn normalize_env_vars(env_vars: &HashMap) -> HashMap { test_uv_path(&uv_path).await?; - Ok(Uv { uv_path, cache_dir, protected_mode }) + Ok(Uv { + uv_path, + cache_dir, + protected_mode, + }) } Err(e) => { debug!("Error setting up UV: {:?}", e); @@ -241,7 +245,7 @@ impl Uv { .arg("--no-progress") .arg("run") .arg(program); - + #[cfg(unix)] { cmd.process_group(0); diff --git a/crates/tower-uv/tests/install_test.rs b/crates/tower-uv/tests/install_test.rs index 1cb036d7..9e9bdf4a 100644 --- a/crates/tower-uv/tests/install_test.rs +++ b/crates/tower-uv/tests/install_test.rs @@ -7,6 +7,8 @@ async fn test_installing_uv() { let _ = tokio::fs::remove_dir_all(&default_uv_bin_dir).await; // Now if we instantiate a Uv instance, it should install the `uv` binary. - let uv = Uv::new(None, false).await.expect("Failed to create a Uv instance"); + let uv = Uv::new(None, false) + .await + .expect("Failed to create a Uv instance"); assert!(uv.is_valid().await); }