From f352c032c3600bed13d2f506bc9f2599c07e01ad Mon Sep 17 00:00:00 2001 From: Peter Heringer Date: Mon, 14 Oct 2024 15:33:34 +0200 Subject: [PATCH 1/3] Add version + commit to table and html output --- build.rs | 7 +++++++ src/html.rs | 2 +- src/io.rs | 28 +++++++++++----------------- 3 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..97dd262 --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +use std::process::Command; +fn main() { + // note: add error checking yourself. + let output = Command::new("git").args(&["describe", "--tags"]).output().unwrap(); + let git_hash = String::from_utf8(output.stdout).unwrap(); + println!("cargo:rustc-env=GIT_HASH={}", git_hash); +} diff --git a/src/html.rs b/src/html.rs index ee8856b..c8d0193 100644 --- a/src/html.rs +++ b/src/html.rs @@ -58,7 +58,7 @@ pub fn populate_constants(vars: &mut HashMap<&str, String>) { "symbols_svg", String::from_utf8_lossy(SYMBOLS_SVG).into_owned(), ); - vars.insert("version", env!("CARGO_PKG_VERSION").to_string()); + vars.insert("version", option_env!("GIT_HASH").unwrap_or(env!("CARGO_PKG_VERSION")).to_string()); let now = OffsetDateTime::now_utc(); vars.insert( diff --git a/src/io.rs b/src/io.rs index 1e1bf84..c384721 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1210,11 +1210,7 @@ pub fn write_ordered_table( pub fn write_hist_table(hists: &[Hist], out: &mut BufWriter) -> Result<(), Error> { log::info!("reporting hist table"); - writeln!( - out, - "# {}", - std::env::args().collect::>().join(" ") - )?; + write_metadata_comments(out)?; let mut header_cols = vec![vec![ "panacus".to_string(), @@ -1241,11 +1237,7 @@ pub fn write_histgrowth_table( hist_aux: &HistAuxilliary, out: &mut BufWriter, ) -> Result<(), Error> { - writeln!( - out, - "# {}", - std::env::args().collect::>().join(" ") - )?; + write_metadata_comments(out)?; let mut header_cols = vec![vec![ "panacus".to_string(), @@ -1282,13 +1274,19 @@ pub fn write_histgrowth_table( write_table(&header_cols, &output_columns, out) } -pub fn write_info(info: Info, out: &mut BufWriter) -> Result<(), Error> { - log::info!("reporting graph info table"); +fn write_metadata_comments(out: &mut BufWriter) -> Result<(), Error> { writeln!( out, "# {}", std::env::args().collect::>().join(" ") )?; + let version = option_env!("GIT_HASH").unwrap_or(env!("CARGO_PKG_VERSION")); + writeln!(out, "# version {}", version) +} + +pub fn write_info(info: Info, out: &mut BufWriter) -> Result<(), Error> { + log::info!("reporting graph info table"); + write_metadata_comments(out)?; writeln!(out, "{}", info) } @@ -1298,11 +1296,7 @@ pub fn write_ordered_histgrowth_table( out: &mut BufWriter, ) -> Result<(), Error> { log::info!("reporting ordered-growth table"); - writeln!( - out, - "# {}", - std::env::args().collect::>().join(" ") - )?; + write_metadata_comments(out)?; let mut output_columns: Vec> = hist_aux .coverage From dfae4ef4893279c1423383a93fbf774a4ce860fe Mon Sep 17 00:00:00 2001 From: Peter Heringer Date: Mon, 14 Oct 2024 15:37:32 +0200 Subject: [PATCH 2/3] cargo fmt --- build.rs | 5 ++++- src/cli.rs | 12 +++--------- src/html.rs | 7 ++++++- src/io.rs | 22 +++++++++++----------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/build.rs b/build.rs index 97dd262..1052f82 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,10 @@ use std::process::Command; fn main() { // note: add error checking yourself. - let output = Command::new("git").args(&["describe", "--tags"]).output().unwrap(); + let output = Command::new("git") + .args(&["describe", "--tags"]) + .output() + .unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap(); println!("cargo:rustc-env=GIT_HASH={}", git_hash); } diff --git a/src/cli.rs b/src/cli.rs index 6676fec..0508ffd 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -748,7 +748,7 @@ pub fn run(params: Params, out: &mut BufWriter) -> Result<(), Error let hists = Vec::new(); write_histgrowth_table(&hists, &growths, &hist_aux, out)? } - }, + } OutputFormat::Html => { if hist { write_histgrowth_html( @@ -762,16 +762,10 @@ pub fn run(params: Params, out: &mut BufWriter) -> Result<(), Error )? } else { write_histgrowth_html( - &None, - &growths, - &hist_aux, - filename, - None, - None, - out, + &None, &growths, &hist_aux, filename, None, None, out, )? } - }, + } }; } Params::Info { diff --git a/src/html.rs b/src/html.rs index c8d0193..0ce1eab 100644 --- a/src/html.rs +++ b/src/html.rs @@ -58,7 +58,12 @@ pub fn populate_constants(vars: &mut HashMap<&str, String>) { "symbols_svg", String::from_utf8_lossy(SYMBOLS_SVG).into_owned(), ); - vars.insert("version", option_env!("GIT_HASH").unwrap_or(env!("CARGO_PKG_VERSION")).to_string()); + vars.insert( + "version", + option_env!("GIT_HASH") + .unwrap_or(env!("CARGO_PKG_VERSION")) + .to_string(), + ); let now = OffsetDateTime::now_utc(); vars.insert( diff --git a/src/io.rs b/src/io.rs index c384721..c7745e3 100644 --- a/src/io.rs +++ b/src/io.rs @@ -170,16 +170,12 @@ pub fn parse_tsv( let mut is_header = true; for (i, row) in reader.enumerate() { - let row = row - .map_err(|_| { - let msg = format!("unable to parse row {}", i); - log::error!("{}", &msg); - Error::new(ErrorKind::Other, msg) - })?; - let row: Vec> = row - .bytes_columns() - .map(|x| x.to_vec()) - .collect(); + let row = row.map_err(|_| { + let msg = format!("unable to parse row {}", i); + log::error!("{}", &msg); + Error::new(ErrorKind::Other, msg) + })?; + let row: Vec> = row.bytes_columns().map(|x| x.to_vec()).collect(); if row.is_empty() { log::info!("Empty row, skipping"); continue; @@ -193,7 +189,11 @@ pub fn parse_tsv( } comments.push(c); // Skip empty lines (still need to have appropriate amount of tabs) - } else if row.iter().map(|x| x.is_empty()).fold(true, |acc, x| acc && x) { + } else if row + .iter() + .map(|x| x.is_empty()) + .fold(true, |acc, x| acc && x) + { log::debug!("Skipping empty line"); continue; // Handle comments From e71f4c216808909ed22ec165e0be275e0fbe17c6 Mon Sep 17 00:00:00 2001 From: Peter Heringer Date: Mon, 14 Oct 2024 15:46:13 +0200 Subject: [PATCH 3/3] Fix warning --- src/cli.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli.rs b/src/cli.rs index 0508ffd..8000b1a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -481,6 +481,7 @@ pub enum Params { } impl Params { + #[allow(dead_code)] pub fn test_default_histgrowth() -> Self { Params::Histgrowth { gfa_file: String::new(),