Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ repos:
rev: 24.10.0
hooks:
- id: black
language_version: python3.9
language_version: python3.9
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
4 changes: 2 additions & 2 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions crates/tower-cmd/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions crates/tower-cmd/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,10 @@ async fn monitor_local_status(app: Arc<Mutex<LocalApp>>) -> 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.
Expand Down
4 changes: 2 additions & 2 deletions crates/tower-cmd/src/util/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
)
Expand Down
13 changes: 9 additions & 4 deletions crates/tower-package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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
Expand Down Expand Up @@ -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<String, Error> {
let mut next = Vec::new();

for component in path.components() {
match component {
Component::Prefix(_) | Component::RootDir => {
Expand Down Expand Up @@ -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");
}
Expand Down
32 changes: 24 additions & 8 deletions crates/tower-runtime/tests/local_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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 {
Expand Down Expand Up @@ -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!"));
Expand All @@ -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");
Expand Down
10 changes: 7 additions & 3 deletions crates/tower-uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn normalize_env_vars(env_vars: &HashMap<String, String>) -> HashMap<String, Str
// Apparently, according to some random person on Stack Overflow, sometimes the var can be
// TEMP and sometimes it can be TMP. So uh...let's just grab both just in case.
let tmp = std::env::var("TMP").unwrap_or_default();
env_vars.insert("TMP".to_string(), tmp);
env_vars.insert("TMP".to_string(), tmp);
}

env_vars
Expand Down Expand Up @@ -109,7 +109,11 @@ impl Uv {
match install::find_or_setup_uv().await {
Ok(uv_path) => {
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);
Expand Down Expand Up @@ -241,7 +245,7 @@ impl Uv {
.arg("--no-progress")
.arg("run")
.arg(program);

#[cfg(unix)]
{
cmd.process_group(0);
Expand Down
4 changes: 3 additions & 1 deletion crates/tower-uv/tests/install_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}