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 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
39 changes: 18 additions & 21 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,23 @@ 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
run: cargo verify-project --manifest-path zefiro-core/zefiro-cwl-parser/Cargo.toml
- 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-cwl-parser library
run: |
cargo publish --manifest-path zefiro-core/zefiro-cwl-parser/Cargo.toml \
--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 --verbose
- name: Check without default features
run: cargo check --offline --no-default-features --verbose
run: cargo check --no-default-features --verbose

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

This file was deleted.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ edition = "2021"
members = [
"zefiro-cli",
"zefiro-core",
"zefiro-core/zefiro-cwl-parser",
"zefiro-ui"
]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Code**: [![codecov](https://codecov.io/gh/zefiroproj/zefiro/graph/badge.svg?token=5DgmM1KzuQ)](https://codecov.io/gh/zefiroproj/zefiro)

# Zefiro - fast, scalable and simple engine to manage workflows
4 changes: 1 addition & 3 deletions zefiro-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
name = "zefiro-core"
version = "0.1.0"
edition = "2021"
rust-version = "1.83.0"

[dependencies]
rust-version = "1.83.0"
27 changes: 27 additions & 0 deletions zefiro-core/zefiro-cwl-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[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 = ["CWL serialization", "CWL deserialization", "Common Workflow Language"]
keywords = ["CWL", "CommandLineTool", "Workflow"]
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"
tempfile = "3.15.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 = "0.1.0"
```


### 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;
Loading
Loading