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

feat: develop a crate to parse cwl documents #4

Merged
merged 21 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
41 changes: 20 additions & 21 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@ jobs:
uses: orhun/git-cliff-action@v4
id: git-cliff
- name: Run git-cliff to generate changelog
run: git-cliff -vv --latest --no-exec --github-repo ${{ github.repository }} --config cliff.toml
id: changelog
run: git-cliff -vv --latest --no-exec --github-repo ${{ github.repository }} --config cliff.toml

publish-crates-io:
name: Publish on crates.io
runs-on: ubuntu-22.04
needs: generate-changelog
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Verify package
run: cargo verify-project
- name: Run tests
run: cargo test --all-features
- name: Set the release version
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> "$GITHUB_ENV"
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
# - name: Publish the zefiro-core library
# run: |
# cargo publish --manifest-path zefiro-core/Cargo.toml \
# --locked --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish-crates-io:
name: Publish on crates.io
runs-on: ubuntu-22.04
needs: generate-changelog
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Verify package
nsyzrantsev marked this conversation as resolved.
Show resolved Hide resolved
run: cargo verify-project
- name: Run tests
nsyzrantsev marked this conversation as resolved.
Show resolved Hide resolved
run: cargo test --all-features
- name: Set the release version
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> "$GITHUB_ENV"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
# - name: Publish the zefiro-core library
# run: |
# cargo publish --manifest-path zefiro-core/Cargo.toml \
nsyzrantsev marked this conversation as resolved.
Show resolved Hide resolved
# --locked --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Check
run: cargo check --offline --verbose
run: cargo check --locked --verbose
- name: Check without default features
run: cargo check --offline --no-default-features --verbose
run: cargo check --locked --no-default-features --verbose

typos:
name: Typos
Expand Down
19 changes: 0 additions & 19 deletions Cargo.lock

This file was deleted.

5 changes: 4 additions & 1 deletion zefiro-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ version = "0.1.0"
edition = "2021"
rust-version = "1.83.0"

[dependencies]
[workspace]
members = [
"zefiro-cwl-parser"
]
nsyzrantsev marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 additions & 0 deletions zefiro-core/zefiro-cwl-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "zefiro-cwl-parser"
version = "0.1.0"
description = """
"The Common Workflow Language (CWL) object model that used in `zefiro`.
"""
authors = [
"Nikita Syzrantsev <[email protected]>"
]
categories = ["Common Workflow Language", "CWL"]
keywords = ["CWL", "CommanLineTool", "Workflow"]
nsyzrantsev marked this conversation as resolved.
Show resolved Hide resolved
edition = "2021"
homepage = "https://github.com/zefiroproj/zefiro"
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/zefiroproj/zefiro"
rust-version = "1.83.0"

[dependencies]
anyhow = "1.0.95"
serde = { version = "1.0.216", features = ["derive"] }
serde_with = "3.12.0"
serde_yaml = "0.9.34"

[dev-dependencies]
rstest = "0.24.0"
77 changes: 77 additions & 0 deletions zefiro-core/zefiro-cwl-parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# zefiro-cwl-parser

A Rust library for parsing and working with Common Workflow Language (CWL) documents.

## Overview

* Supports only some fields of CWL v1.2 specification (see description of structures in the code)
* Can serialize and deserialize [CommandLineTool](https://www.commonwl.org/v1.2/CommandLineTool.html) and [Workflow](https://www.commonwl.org/v1.2/Workflow.html) documents

## Usage

Add this to your `Cargo.toml`:

```toml
[dependencies]
zefiro-cwl-parser = <zefiro-cwl-parser>
nsyzrantsev marked this conversation as resolved.
Show resolved Hide resolved
```


### Parsing CWL Schema Documents

```rust
use zefiro_cwl_parser::CwlSchema;

// Parse from file
let schema = CwlSchema::from_path("workflow.yml")?;

// Parse from string
let yaml_str = r#"
cwlVersion: v1.2
class: CommandLineTool
id: step
inputs:
- id: in_file
type: File
inputBinding:
prefix: --in-file
- id: out_file
type: string
default: "output.txt"
inputBinding:
prefix: --out-file
- id: output_location_subdir
type: string
default: output/
outputs:
- id: out_file
type: File
outputBinding:
glob: $(inputs.out_file)
outputEval: ${self[0].location += inputs.output_location_subdir; return self[0]}
requirements:
- class: DockerRequirement
dockerPull: step-image-uri:1.0
- class: InlineJavascriptRequirement
"#;
let schema = CwlSchema::from_string(yaml_str)?;
```


### Parsing CWL Values Documents

```rust
use zefiro_cwl_parser::CwlValues;

// Parse input values from file
let values = CwlValues::from_path("values.yml")?;

// Create values from string
let yaml_input = r#"
input_file:
class: File
location: 's3://bucket/input.txt'
output_file: 'output.txt'
"#;
let values = CwlValues::from_string(yaml_input)?;
```
32 changes: 32 additions & 0 deletions zefiro-core/zefiro-cwl-parser/examples/data/clt-step-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cwlVersion: v1.2
class: CommandLineTool
id: step
inputs:
- id: in_file
type: File
inputBinding:
prefix: --in-file
- id: out_file
type: string
default: "output.txt"
inputBinding:
prefix: --out-file
- id: output_location_subdir
type: string
default: output/
outputs:
- id: out_file
type: File
outputBinding:
glob: $(inputs.out_file)
outputEval: ${self[0].location += inputs.output_location_subdir; return self[0]}
nsyzrantsev marked this conversation as resolved.
Show resolved Hide resolved
requirements:
- class: DockerRequirement
dockerPull: step-image-uri:1.0
- class: ResourceRequirement
coresMin: 2
outdirMin: 1000
ramMin: 1024
- class: InlineJavascriptRequirement
- class: ToolTimeLimit
timelimit: $(60*60*1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
in_file:
class: File
location: '{{ inputLocation }}/output/input-{{ readgroup }}.txt'
out_file: 'output.txt'
64 changes: 64 additions & 0 deletions zefiro-core/zefiro-cwl-parser/examples/data/wf-step-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class: Workflow
cwlVersion: v1.2
id: step
inputs:
- id: step__in_file
type:
type: array
items: File
- id: step__out_file
type: string
outputs:
- id: step__out_file
type: File
outputSource: step/out_file
requirements:
- class: InlineJavascriptRequirement
- class: ScatterFeatureRequirement
steps:
- id: step
in:
- id: in_file
source: step__in_file
- id: out_file
source: step__out_file
out:
- id: out_file
run:
cwlVersion: v1.2
class: CommandLineTool
id: step1
inputs:
- id: in_file
type: File
inputBinding:
prefix: --in-file
- id: out_file
type: string
default: output.txt
inputBinding:
prefix: --out-file
- id: output_location_subdir
type: string
default: output/
outputs:
- id: out_file
type: File
outputBinding:
glob: $(inputs.out_file)
outputEval: ${self[0].location += inputs.output_location_subdir; return self[0]}
nsyzrantsev marked this conversation as resolved.
Show resolved Hide resolved
requirements:
- class: DockerRequirement
dockerPull: step1-image:1.0
- class: ResourceRequirement
coresMin: 2
outdirMin: 1000
ramMin: 1024
- class: InlineJavascriptRequirement
- class: ToolTimeLimit
timelimit: $(60*60*1)
- class: WorkReuse
enableReuse: true
scatter:
- in_file
scatterMethod: dotproduct
5 changes: 5 additions & 0 deletions zefiro-core/zefiro-cwl-parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod schema;
pub mod values;

pub use crate::schema::document::CwlSchema;
pub use crate::values::document::CwlValues;
20 changes: 20 additions & 0 deletions zefiro-core/zefiro-cwl-parser/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use zefiro_cwl_parser::values::{document::CwlValues, types::CwlValueType};
use zefiro_cwl_parser::schema::document::CwlSchema;

fn main() {
let file_path = "examples/data/clt-step-values.yml";
let values = CwlValues::from_path(file_path).expect("Failed to deserialize CWL values document");
for (key, value) in values.iter() {
match value {
CwlValueType::File(value) => println!("{} {:?} {:?}", key, value, value.get_location()),
_ => println!("{} {:?}", key, value)
}
}

let file_path = "examples/data/wf-step-schema.yml";
let schema = CwlSchema::from_path(file_path).expect("Failed to deserialize CWL values document");
println!("{:?}", schema);
// for (key, value) in schema.iter() {
// println!("{:?}", value);
// }
}
Loading
Loading