Skip to content

Commit

Permalink
fix: wdl run should join input paths correctly. (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhuene authored Jan 21, 2025
1 parent a4c78eb commit 424f69f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
4 changes: 4 additions & 0 deletions wdl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

* Fixed `wdl run` not correctly updating file/directory paths in an inputs file ([#302](https://github.com/stjude-rust-labs/wdl/pull/302)).

## 0.11.0 - 01-17-2025

### Added
Expand Down
45 changes: 28 additions & 17 deletions wdl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,51 @@ pub async fn analyze(

let results = analyzer.analyze(bar.clone()).await?;

anyhow::Ok(results)
Ok(results)
}

/// Parses the inputs for a task or workflow.
///
/// Returns the absolute path to the inputs file (if a path was provided), the
/// name of the workflow or task referenced by the inputs, and the inputs to the
/// workflow or task.
pub fn parse_inputs(
document: &Document,
name: Option<&str>,
inputs: Option<&Path>,
) -> Result<(Option<PathBuf>, String, Inputs)> {
let (path, name, inputs) = if let Some(path) = inputs {
let abs_path = absolute(path).with_context(|| {
format!(
"failed to determine the absolute path of `{path}`",
path = path.display()
)
})?;
match Inputs::parse(document, &abs_path)? {
Some((name, inputs)) => (Some(path.to_path_buf()), name, inputs),
if let Some(path) = inputs {
// If a inputs file path was provided, parse the inputs from the file
match Inputs::parse(document, path)? {
Some((name, inputs)) => {
// Make the inputs file path absolute so that we treat any file/directory inputs
// in the file as relative to the inputs file itself
let path = absolute(path).with_context(|| {
format!(
"failed to determine the absolute path of `{path}`",
path = path.display()
)
})?;
Ok((Some(path), name, inputs))
}
None => bail!("inputs file `{path}` is empty", path = path.display()),
}
} else if let Some(name) = name {
// Otherwise, if a name was provided, look for a task or workflow with that
// name
if document.task_by_name(name).is_some() {
(None, name.to_string(), Inputs::Task(Default::default()))
Ok((None, name.to_string(), Inputs::Task(Default::default())))
} else if document.workflow().is_some() {
if name != document.workflow().unwrap().name() {
bail!("document does not contain a workflow named `{name}`");
}
(None, name.to_string(), Inputs::Workflow(Default::default()))
Ok((None, name.to_string(), Inputs::Workflow(Default::default())))
} else {
bail!("document does not contain a task or workflow named `{name}`");
}
} else {
// Neither a inputs file or name was provided, look for a single task or
// workflow in the document
let mut iter = document.tasks();
let (name, inputs) = iter
.next()
Expand All @@ -156,10 +169,8 @@ pub fn parse_inputs(
bail!("inputs file is empty and the WDL document contains more than one task");
}

(None, name, inputs)
};

anyhow::Ok((path, name, inputs))
Ok((None, name, inputs))
}
}

/// Validates the inputs for a task or workflow.
Expand All @@ -186,7 +197,7 @@ pub async fn validate_inputs(document: &str, inputs: &Path) -> Result<Option<Dia
}
}

anyhow::Ok(None)
Ok(None)
}

/// Run a WDL task or workflow.
Expand Down

0 comments on commit 424f69f

Please sign in to comment.