Commit 9a400caa authored by Wohlgemuth, Jason's avatar Wohlgemuth, Jason
Browse files

feat: Final steps to run remote binary modules

parent 764b2d4f
Loading
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -14,7 +14,31 @@ Parallel Integration & Processing Engine
> **UNDER CONSTRUCTION**

## Documentation
> Read the code docs at https://pipe.code.ornl and/or explore the [Wiki](https://code.ornl.gov/groups/GSHS/common/pipe/-/wikis/home)
> **TIP** Read the code docs at https://pipe.code.ornl and/or explore the [Wiki](https://code.ornl.gov/groups/GSHS/common/pipe/-/wikis/home)

Print the help with `pipe help` or save the configuration below to `config.json` and use `pipe run`

```json
{
    "version": "0.0.1",
    "description": "Print PIPE help",
    "requirements": [],
    "modules": [
        {
            "name": "Meta Module",
            "type": "binary",
            "uri": "https://code.ornl.gov/api/v4/projects/15383/packages/generic/x86_64-unknown-linux-gnu/v0.0.3/pipe",
            "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
            "template": {
                "command": "pipe",
                "arguments": [
                    "help"
                ]
            }
        }
    ]
}
```

### Architecture
> See [ARCHITECTURE.md](./ARCHITECTURE.md)
+4 −7
Original line number Diff line number Diff line
@@ -3,11 +3,10 @@ use color_eyre::eyre::Report;
use exitcode;
use nanoid::nanoid;
use pipe_lib::{
    download_binary, get_checksum, get_parent, Command, Config, EnvironmentValue, Label, ModuleLanguage, ModuleType, ModuleUri, Script,
    download_binary, get_checksum, Command, Config, EnvironmentValue, Label, ModuleLanguage, ModuleType, ModuleUri, Script,
    ScriptTemplate, TemplateAttribute,
};
use rayon::prelude::*;
use std::convert::TryFrom;
use std::env;
use std::fs;
#[cfg(any(unix, target_os = "wasi", target_os = "redox"))]
@@ -15,7 +14,6 @@ use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
use tracing::{debug, error, info, warn};
use uriparse::Scheme;
use uriparse::URI;

const DEFAULT_CONFIG_NAME: &str = "config.json";

@@ -262,12 +260,11 @@ pub fn run(
            });
            // Run workflow
            cfg.modules.iter().for_each(|module| match &module.module_type {
                | ModuleType::Binary { ref uri, .. } => {
                | ModuleType::Binary { .. } => {
                    let envs = EnvironmentValue::get_from_config(&cfg, Some(module.clone()));
                    let parent = get_parent(PathBuf::from(uri)).to_string_lossy().to_string();
                    let working_dir = URI::try_from(parent.as_str()).unwrap().clone().path().to_string();
                    let working_dir = root.clone().into_os_string().into_string().unwrap();
                    let loaded = Script::from_module(module.clone(), Some(PathBuf::from(working_dir.clone())));
                    let script = loaded.expand_arguments_from(envs).with_current_dir(working_dir);
                    let script = loaded.ensure_relative().expand_arguments_from(envs).with_current_dir(working_dir);
                    if dry_run {
                        EnvironmentValue::print_all();
                        info!(
+5 −0
Original line number Diff line number Diff line
@@ -755,6 +755,11 @@ impl SemanticVersion {
    }
}
impl Script {
    pub fn ensure_relative(mut self) -> Script {
        let path = PathBuf::from(self.command.name);
        self.command.name = add_dot_slash(path).to_str().unwrap().to_string();
        self
    }
    /// Expand environment variables in the script arguments from environment
    ///
    /// This method does not set environment variables, but only interpolates the values within the script arguments
+12 −0
Original line number Diff line number Diff line
@@ -246,6 +246,18 @@ fn test_script() {
    assert_eq!(script.envs, None);
}

#[test]
fn test_script_ensure_relative() {
    let command = Command::init().name("pipe".to_string()).build();
    let script = Script::init().command(command).build();
    assert_eq!(script.command.name, "pipe".to_string());
    let expected = "./pipe".to_string();
    // Should add ./ to command name
    assert_eq!(script.clone().ensure_relative().command.name, expected);
    // Should not add ./ to command name if already relative
    assert_eq!(script.ensure_relative().ensure_relative().command.name, expected);
}

#[test]
fn test_script_expand_arguments() {
    set_var("_PIPE_INPUT_DIRECTORY", "/path/to/input");