Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reformat crates
Browse files Browse the repository at this point in the history
nsyzrantsev committed Jan 8, 2025
1 parent 56d196d commit 772b527
Showing 23 changed files with 28 additions and 55 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@ edition = "2021"
[workspace]
members = [
"zefiro-cli",
"zefiro-pipeline",
"zefiro-pipeline/zefiro-cwl-parser",
"zefiro-pipeline-engine",
"zefiro-pipeline-engine/zefiro-cwl-parser",
"zefiro-pipeline-engine/zefiro-cwl-js-exec",
"zefiro-ui"
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "zefiro-core"
name = "zefiro-pipeline-engine"
version = "0.1.0"
edition = "2021"
rust-version = "1.83.0"
File renamed without changes.
12 changes: 12 additions & 0 deletions zefiro-pipeline-engine/zefiro-cwl-js-exec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "zefiro-cwl-js-exec"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.95"
deno_core = "0.329.0"
serde_json = "1.0.135"

[dev-dependencies]
rstest = "0.24.0"
3 changes: 3 additions & 0 deletions zefiro-pipeline-engine/zefiro-cwl-js-exec/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod exec;

pub use crate::exec::JsExecutor;
Original file line number Diff line number Diff line change
@@ -18,9 +18,7 @@ rust-version = "1.83.0"

[dependencies]
anyhow = "1.0.95"
deno_core = "0.328.0"
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.134"
serde_with = "3.12.0"
serde_yaml = "0.9.34"
sha1 = "0.10.6"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#[doc = include_str!("../README.md")]
pub mod js;
pub mod schema;
pub mod values;

pub use crate::js::exec::JsExecutor;
pub use crate::schema::document::CwlSchema;
pub use crate::values::document::CwlValues;
Original file line number Diff line number Diff line change
@@ -96,10 +96,6 @@ impl CwlValues {
pub fn to_yaml<W: Write>(&self, writer: W) -> Result<()> {
serde_yaml::to_writer(writer, self).map_err(Into::into)
}

pub fn to_json(&self) -> Result<serde_json::Value, Error> {
Ok(serde_json::to_value(self)?)
}
}

#[cfg(test)]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use serde::{Deserialize, Deserializer, Serialize};
use serde::{Deserialize, Serialize};
use sha1::{Digest, Sha1};
use std::fs;
use std::io;
use std::path::Path;

/// Represents a `File` object in CWL
#[derive(Clone, Debug, Serialize, Default)]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct CwlFile {
/// Full path to the file, e.g., "/path/to/file.txt".
pub location: String,
@@ -36,83 +36,49 @@ impl CwlFile {
self.location.clone()
}

fn calculate_checksum(path: &str) -> io::Result<String> {
pub fn calculate_checksum(path: &str) -> io::Result<String> {
let mut file = fs::File::open(path)?;
let mut hasher = Sha1::new();
io::copy(&mut file, &mut hasher)?;
Ok(format!("{:x}", hasher.finalize()))
}

fn extract_path_info<F, T>(path: &str, provided: Option<T>, extractor: F) -> Option<T>
pub fn extract_path_info<F, T>(path: &str, provided: Option<T>, extractor: F) -> Option<T>
where
F: Fn(&Path) -> Option<T>,
{
provided.or_else(|| extractor(Path::new(path)))
}

fn basename(path: &str, provided_basename: Option<String>) -> Option<String> {
pub fn basename(path: &str, provided_basename: Option<String>) -> Option<String> {
Self::extract_path_info(path, provided_basename, |p| {
p.file_name()
.and_then(|name| name.to_str().map(String::from))
})
}

fn nameroot(path: &str, provided_nameroot: Option<String>) -> Option<String> {
pub fn nameroot(path: &str, provided_nameroot: Option<String>) -> Option<String> {
Self::extract_path_info(path, provided_nameroot, |p| {
p.file_stem()
.and_then(|stem| stem.to_str().map(String::from))
})
}

fn nameext(path: &str, provided_nameext: Option<String>) -> Option<String> {
pub fn nameext(path: &str, provided_nameext: Option<String>) -> Option<String> {
Self::extract_path_info(path, provided_nameext, |p| {
p.extension().and_then(|ext| ext.to_str().map(String::from))
})
}

fn size(path: &str, provided_size: Option<u64>) -> Option<u64> {
pub fn size(path: &str, provided_size: Option<u64>) -> Option<u64> {
provided_size.or_else(|| fs::metadata(path).ok().map(|m| m.len()))
}

fn checksum(path: &str, provided_checksum: Option<String>) -> Option<String> {
pub fn checksum(path: &str, provided_checksum: Option<String>) -> Option<String> {
provided_checksum.or_else(|| Self::calculate_checksum(path).ok())
}
}

impl<'de> Deserialize<'de> for CwlFile {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Helper {
location: String,
#[serde(default)]
basename: Option<String>,
#[serde(default)]
nameroot: Option<String>,
#[serde(default)]
nameext: Option<String>,
#[serde(default)]
size: Option<u64>,
#[serde(default)]
checksum: Option<String>,
}

let helper = Helper::deserialize(deserializer)?;
let path = &helper.location;

Ok(Self {
location: helper.location.clone(),
basename: Self::basename(path, helper.basename),
nameroot: Self::nameroot(path, helper.nameroot),
nameext: Self::nameext(path, helper.nameext),
size: Self::size(path, helper.size),
checksum: Self::checksum(path, helper.checksum),
})
}
}

/// Represents a `Directory` object in CWL
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CwlDirectory {
1 change: 0 additions & 1 deletion zefiro-pipeline/zefiro-cwl-parser/src/js/mod.rs

This file was deleted.

0 comments on commit 772b527

Please sign in to comment.