Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format the codebase via rustfmt #263

Merged
merged 2 commits into from
Jul 18, 2023
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
18 changes: 18 additions & 0 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ on: [push, pull_request, merge_group]
name: Cargo

jobs:
fmt:
name: Fmt
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/[email protected]

- name: Install toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: 1.65.0 # MSRV
components: rustfmt

- name: Run cargo fmt
run: cargo fmt --check

check:
name: Check
runs-on: ubuntu-latest
Expand Down Expand Up @@ -112,6 +129,7 @@ jobs:
if: ${{ always() }}
runs-on: ubuntu-latest
needs:
- fmt
- check
- test
- deny
Expand Down
15 changes: 7 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use anyhow::Result;
use vergen::EmitBuilder;
use std::error::Error;

use vergen::EmitBuilder;

fn main() -> Result<(), Box<dyn Error>> {
EmitBuilder::builder()
.build_timestamp()
.cargo_debug()
.git_sha(false)
.git_commit_timestamp()
.git_describe(true, true, None)
.emit()?;
.build_timestamp()
.cargo_debug()
.git_sha(false)
.git_commit_timestamp()
.git_describe(true, true, None)
.emit()?;
Ok(())
}
22 changes: 15 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use std::path::PathBuf;
use std::str::FromStr;

use clap::crate_authors;
use clap::Command;
use clap::Arg;
use clap::ArgAction;
use clap::ArgGroup;
use clap::Command;

use tracing::{debug, error};

Expand Down Expand Up @@ -1246,7 +1246,8 @@ fn arg_older_than_date(about: &str) -> Arg {
.long("older-than")
.value_name("DATE")
.help(about.to_owned())
.long_help(r#"
.long_help(
r#"
DATE can be a freeform date, for example '2h'
It can also be a exact date: '2020-01-01 00:12:45'
If the hour-minute-second part is omitted, " 00:00:00" is appended automatically.
Expand All @@ -1264,7 +1265,8 @@ fn arg_older_than_date(about: &str) -> Arg {
months, month, M -- defined as 30.44 days
years, year, y -- defined as 365.25 days

"#)
"#,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't ideal... :(

.value_parser(parse_date_from_string)
}

Expand All @@ -1274,7 +1276,8 @@ fn arg_newer_than_date(about: &str) -> Arg {
.long("newer-than")
.value_name("DATE")
.help(about.to_owned())
.long_help(r#"
.long_help(
r#"
DATE can be a freeform date, for example '2h'
It can also be a exact date: '2020-01-01 00:12:45'
If the hour-minute-second part is omitted, " 00:00:00" is appended automatically.
Expand All @@ -1292,7 +1295,8 @@ fn arg_newer_than_date(about: &str) -> Arg {
months, month, M -- defined as 30.44 days
years, year, y -- defined as 365.25 days

"#)
"#,
)
.value_parser(parse_date_from_string)
}

Expand All @@ -1315,11 +1319,15 @@ fn parse_date_from_string(s: &str) -> std::result::Result<String, String> {
}

fn parse_usize(s: &str) -> std::result::Result<String, String> {
usize::from_str(s) .map_err(|e| e.to_string()).map(|_| s.to_owned())
usize::from_str(s)
.map_err(|e| e.to_string())
.map(|_| s.to_owned())
}

fn parse_u64(s: &str) -> std::result::Result<String, String> {
u64::from_str(s).map_err(|e| e.to_string()).map(|_| s.to_owned())
u64::from_str(s)
.map_err(|e| e.to_string())
.map(|_| s.to_owned())
}

#[cfg(test)]
Expand Down
82 changes: 60 additions & 22 deletions src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ use anyhow::Error;
use anyhow::Result;
use clap::ArgMatches;
use colored::Colorize;
use diesel::r2d2::ConnectionManager;
use diesel::r2d2::Pool;
use diesel::ExpressionMethods;
use diesel::PgConnection;
use diesel::QueryDsl;
use diesel::RunQueryDsl;
use diesel::r2d2::ConnectionManager;
use diesel::r2d2::Pool;
use itertools::Itertools;
use tracing::{debug, info, trace, warn};
use tokio::sync::RwLock;
use tokio_stream::StreamExt;
use tracing::{debug, info, trace, warn};
use uuid::Uuid;

use crate::config::*;
use crate::filestore::path::StoreRoot;
use crate::filestore::ReleaseStore;
use crate::filestore::StagingStore;
use crate::filestore::path::StoreRoot;
use crate::job::JobResource;
use crate::log::LogItem;
use crate::orchestrator::OrchestratorSetup;
use crate::package::condition::ConditionData;
use crate::package::Dag;
use crate::package::PackageName;
use crate::package::PackageVersion;
use crate::package::Shebang;
use crate::package::condition::ConditionData;
use crate::repository::Repository;
use crate::schema;
use crate::source::SourceCache;
use crate::util::EnvironmentVariableName;
use crate::util::docker::ImageName;
use crate::util::progress::ProgressBars;
use crate::util::EnvironmentVariableName;

/// Implementation of the "build" subcommand
#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -91,9 +91,20 @@ pub async fn build(
.any(|img| image_name == img.name)
{
return Err(anyhow!(
"Requested build image {} is not in the configured images", image_name
"Requested build image {} is not in the configured images",
image_name
))
.with_context(|| anyhow!("Available images: {}", config.docker().images().iter().map(|img| img.name.clone()).join(", ")))
.with_context(|| {
anyhow!(
"Available images: {}",
config
.docker()
.images()
.iter()
.map(|img| img.name.clone())
.join(", ")
)
})
.with_context(|| anyhow!("Image present verification failed"))
.map_err(Error::from);
}
Expand All @@ -111,7 +122,14 @@ pub async fn build(
crate::endpoint::EndpointConfiguration::builder()
.endpoint_name(ep_name.clone())
.endpoint(ep_cfg.clone())
.required_images(config.docker().images().iter().map(|img| img.name.clone()).collect::<Vec<_>>())
.required_images(
config
.docker()
.images()
.iter()
.map(|img| img.name.clone())
.collect::<Vec<_>>(),
)
.required_docker_versions(config.docker().docker_versions().clone())
.required_docker_api_versions(config.docker().docker_api_versions().clone())
.build()
Expand Down Expand Up @@ -145,7 +163,10 @@ pub async fn build(
.collect::<Result<Vec<(EnvironmentVariableName, String)>>>()?;

let packages = if let Some(pvers) = pvers {
debug!("Searching for package with version: '{}' '{}'", pname, pvers);
debug!(
"Searching for package with version: '{}' '{}'",
pname, pvers
);
repo.find(&pname, &pvers)
} else {
debug!("Searching for package by name: '{}'", pname);
Expand Down Expand Up @@ -176,9 +197,11 @@ pub async fn build(
debug!("Loading release directory: {}", p_str);
let r = ReleaseStore::load(StoreRoot::new(p.clone())?, &bar_release_loading);
if r.is_ok() {
bar_release_loading.finish_with_message(format!("Loaded releases in {p_str} successfully"));
bar_release_loading
.finish_with_message(format!("Loaded releases in {p_str} successfully"));
} else {
bar_release_loading.finish_with_message(format!("Failed to load releases in {p_str}"));
bar_release_loading
.finish_with_message(format!("Failed to load releases in {p_str}"));
}
r.map(Arc::new)
})
Expand All @@ -187,13 +210,16 @@ pub async fn build(
let (staging_store, staging_dir, submit_id) = {
let bar_staging_loading = progressbars.bar()?;

let (submit_id, p) = if let Some(staging_dir) = matches.get_one::<String>("staging_dir").map(PathBuf::from) {
let (submit_id, p) = if let Some(staging_dir) =
matches.get_one::<String>("staging_dir").map(PathBuf::from)
{
info!(
"Setting staging dir to {} for this run",
staging_dir.display()
);

let uuid = staging_dir.file_name()
let uuid = staging_dir
.file_name()
.ok_or_else(|| anyhow!("Seems not to be a directory: {}", staging_dir.display()))?
.to_owned()
.into_string()
Expand Down Expand Up @@ -224,7 +250,9 @@ pub async fn build(
} else {
bar_staging_loading.finish_with_message("Failed to load staging");
}
r.map(RwLock::new).map(Arc::new).map(|store| (store, p, submit_id))?
r.map(RwLock::new)
.map(Arc::new)
.map(|store| (store, p, submit_id))?
};

let dag = {
Expand All @@ -234,7 +262,12 @@ pub async fn build(
env: &additional_env,
};

let dag = Dag::for_root_package(package.clone(), &repo, Some(&bar_tree_building), &condition_data)?;
let dag = Dag::for_root_package(
package.clone(),
&repo,
Some(&bar_tree_building),
&condition_data,
)?;
bar_tree_building.finish_with_message("Finished loading Dag");
dag
};
Expand Down Expand Up @@ -298,7 +331,8 @@ pub async fn build(

trace!("Setting up database jobs for Package, GitHash, Image");
let db_package = async { Package::create_or_fetch(&mut database_pool.get().unwrap(), package) };
let db_githash = async { GitHash::create_or_fetch(&mut database_pool.get().unwrap(), &hash_str) };
let db_githash =
async { GitHash::create_or_fetch(&mut database_pool.get().unwrap(), &hash_str) };
let db_image = async { Image::create_or_fetch(&mut database_pool.get().unwrap(), &image_name) };
let db_envs = async {
additional_env
Expand Down Expand Up @@ -347,15 +381,19 @@ pub async fn build(
writeln!(outlock, "Starting submit: {}", mkgreen(&submit_id))?;
writeln!(outlock, "Started at: {}", mkgreen(&now))?;
writeln!(outlock, "On Image: {}", mkgreen(&db_image.name))?;
writeln!(outlock, "For Package: {p} {v}",
writeln!(
outlock,
"For Package: {p} {v}",
p = mkgreen(&db_package.name),
v = mkgreen(&db_package.version))?;
v = mkgreen(&db_package.version)
)?;
Comment on lines -350 to +389
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This destroys the manual formatting but IMO it's fine

writeln!(outlock, "On repo hash: {}", mkgreen(&db_githash.hash))?;
}

trace!("Setting up job sets");
let resources: Vec<JobResource> = additional_env.into_iter().map(JobResource::from).collect();
let jobdag = crate::job::Dag::from_package_dag(dag, shebang, image_name, phases.clone(), resources);
let jobdag =
crate::job::Dag::from_package_dag(dag, shebang, image_name, phases.clone(), resources);
trace!("Setting up job sets finished successfully");

trace!("Setting up Orchestrator");
Expand Down Expand Up @@ -408,7 +446,8 @@ pub async fn build(
writeln!(
outlock,
"Last {} lines of Job {}",
number_log_lines, job_uuid.to_string().red()
number_log_lines,
job_uuid.to_string().red()
)?;
writeln!(
outlock,
Expand All @@ -432,7 +471,6 @@ pub async fn build(
error_catched = true;
}


line_item.display().map(|d| d.to_string())
})
.collect::<Result<Vec<_>>>()?;
Expand Down
Loading