Batch processing

Within this project it’s possible to do all of the same things mentioned in the “Component” guide such as build a target executable with viash build and test a component with viash test. However, doing this for all components in the repository can bet quite tedious.

Luckily, Viash provides a set of commands for building, testing or inspecting all Viash components in the current namespace (ns).

Build all components

You can generate your first full development build using the viash ns build command.

viash ns build --setup cachedbuild
Output
Exporting remove_comments (demo) =docker=> /home/runner/work/website/website/guide/_viash_project_template/target/docker/demo/remove_comments
[notice] Building container 'ghcr.io/viash-io/viash_project_template/demo/remove_comments:dev' with Dockerfile
Exporting remove_comments (demo) =nextflow=> /home/runner/work/website/website/guide/_viash_project_template/target/nextflow/demo/remove_comments
Exporting combine_columns (demo) =docker=> /home/runner/work/website/website/guide/_viash_project_template/target/docker/demo/combine_columns
[notice] Building container 'ghcr.io/viash-io/viash_project_template/demo/combine_columns:dev' with Dockerfile
Exporting combine_columns (demo) =nextflow=> /home/runner/work/website/website/guide/_viash_project_template/target/nextflow/demo/combine_columns
Exporting take_column (demo) =docker=> /home/runner/work/website/website/guide/_viash_project_template/target/docker/demo/take_column
[notice] Building container 'ghcr.io/viash-io/viash_project_template/demo/take_column:dev' with Dockerfile
Exporting take_column (demo) =nextflow=> /home/runner/work/website/website/guide/_viash_project_template/target/nextflow/demo/take_column
All 6 configs built successfully

Here are some useful optional arguments:

  • --parallel: Run multiple builds in parallel.
  • --setup cachedbuild: Build Docker images using the cachedbuild strategy.
  • --query demo: Only select components that have ‘demo’ in the namespace or name.

Test all components

You can run all of the component tests using the viash ns test command.

viash ns test
Output
           namespace        functionality             platform            test_name exit_code duration               result
                demo      remove_comments               docker                start                                        
The working directory for the namespace tests is /tmp/viash_ns_test5637339606182808323
                demo      remove_comments               docker     build_executable         0        0              SUCCESS
                demo      remove_comments               docker              test.sh         0        1              SUCCESS
                demo      combine_columns               docker                start                                        
                demo      combine_columns               docker     build_executable         0        0              SUCCESS
                demo      combine_columns               docker                tests        -1        0              MISSING
no tests found
====================================================================
                demo          take_column               docker                start                                        
                demo          take_column               docker     build_executable         0        0              SUCCESS
                demo          take_column               docker                tests        -1        0              MISSING
no tests found
====================================================================
Not all configs built and tested successfully
  2/6 tests missing
  4/6 configs built and tested successfully

Listing components

You can run list all components using the viash ns list command.

viash ns list
Output
- functionality:
    name: "remove_comments"
    namespace: "demo"
    version: "dev"
    authors: []
    arguments:
    - type: "file"
All 3 configs parsed successfully
      name: "--input"
      alternatives:
      - "-i"
      example:
      - "file.tsv"
      default: []
      must_exist: true
      create_parent: true
      required: true
      direction: "input"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    - type: "file"
      name: "--output"
      alternatives:
      - "-o"
      example:
      - "file.tsv"
      default: []
      must_exist: true
      create_parent: true
      required: true
      direction: "output"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    - type: "string"
      name: "--id"
      alternatives: []
      example: []
      default:
      - "remove_comments"
      required: false
      choices: []
      direction: "input"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    argument_groups: []
    resources:
    - type: "bash_script"
      path: "script.sh"
      is_executable: true
      parent: "file:/home/runner/work/website/website/guide/_viash_project_template/src/demo/remove_comments/config.vsh.yaml"
    test_resources:
    - type: "bash_script"
      path: "test.sh"
      is_executable: true
      parent: "file:/home/runner/work/website/website/guide/_viash_project_template/src/demo/remove_comments/config.vsh.yaml"
    status: "enabled"
    requirements:
      commands: []
    set_wd_to_resources_dir: false
  platforms:
  - type: "docker"
    id: "docker"
    image: "ubuntu:20.04"
    target_organization: "viash-io/viash_project_template"
    target_registry: "ghcr.io"
    namespace_separator: "/"
    resolve_volume: "Automatic"
    chown: true
    port: []
    setup_strategy: "ifneedbepullelsecachedbuild"
    run_args: []
    target_image_source: "https://github.com/viash-io/viash_project_template"
    setup: []
    test_setup: []
  - type: "nextflow"
    id: "nextflow"
    variant: "vdsl3"
    directives:
      accelerator: {}
      conda: []
      containerOptions: []
      label: []
      module: []
      pod: []
      publishDir: []
      queue: []
      tag: "$id"
    auto:
      simplifyInput: true
      simplifyOutput: true
      transcript: false
      publish: false
    debug: false
    container: "docker"
  info:
    config: "/home/runner/work/website/website/guide/_viash_project_template/src/demo/remove_comments/config.vsh.yaml"
    viash_version: "0.7.1"
    git_commit: "ffa7b1bee3fb192bec568a772b44c6b527cd941b"
    git_remote: "https://github.com/viash-io/viash_project_template.git"
- functionality:
    name: "combine_columns"
    namespace: "demo"
    version: "dev"
    authors: []
    arguments:
    - type: "file"
      name: "--input"
      alternatives:
      - "-i"
      example: []
      default: []
      must_exist: true
      create_parent: true
      required: true
      direction: "input"
      multiple: true
      multiple_sep: ":"
      dest: "par"
    - type: "file"
      name: "--output"
      alternatives:
      - "-o"
      example: []
      default: []
      must_exist: true
      create_parent: true
      required: true
      direction: "output"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    - type: "string"
      name: "--id"
      alternatives: []
      example: []
      default:
      - "combine_columns"
      required: false
      choices: []
      direction: "input"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    argument_groups: []
    resources:
    - type: "r_script"
      path: "script.R"
      is_executable: true
      parent: "file:/home/runner/work/website/website/guide/_viash_project_template/src/demo/combine_columns/config.vsh.yaml"
    test_resources: []
    status: "enabled"
    requirements:
      commands: []
    set_wd_to_resources_dir: false
  platforms:
  - type: "docker"
    id: "docker"
    image: "eddelbuettel/r2u:22.04"
    target_organization: "viash-io/viash_project_template"
    target_registry: "ghcr.io"
    namespace_separator: "/"
    resolve_volume: "Automatic"
    chown: true
    port: []
    setup_strategy: "ifneedbepullelsecachedbuild"
    run_args: []
    target_image_source: "https://github.com/viash-io/viash_project_template"
    setup: []
    test_setup: []
  - type: "nextflow"
    id: "nextflow"
    variant: "vdsl3"
    directives:
      accelerator: {}
      conda: []
      containerOptions: []
      label: []
      module: []
      pod: []
      publishDir: []
      queue: []
      tag: "$id"
    auto:
      simplifyInput: true
      simplifyOutput: true
      transcript: false
      publish: false
    debug: false
    container: "docker"
  info:
    config: "/home/runner/work/website/website/guide/_viash_project_template/src/demo/combine_columns/config.vsh.yaml"
    viash_version: "0.7.1"
    git_commit: "ffa7b1bee3fb192bec568a772b44c6b527cd941b"
    git_remote: "https://github.com/viash-io/viash_project_template.git"
- functionality:
    name: "take_column"
    namespace: "demo"
    version: "dev"
    authors: []
    arguments:
    - type: "file"
      name: "--input"
      alternatives:
      - "-i"
      example: []
      default: []
      must_exist: true
      create_parent: true
      required: true
      direction: "input"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    - type: "file"
      name: "--output"
      alternatives:
      - "-o"
      example: []
      default: []
      must_exist: true
      create_parent: true
      required: true
      direction: "output"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    - type: "integer"
      name: "--column"
      alternatives: []
      example: []
      default:
      - 2
      required: false
      choices: []
      direction: "input"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    - type: "string"
      name: "--id"
      alternatives: []
      example: []
      default:
      - "take_column"
      required: false
      choices: []
      direction: "input"
      multiple: false
      multiple_sep: ":"
      dest: "par"
    argument_groups: []
    resources:
    - type: "python_script"
      path: "script.py"
      is_executable: true
      parent: "file:/home/runner/work/website/website/guide/_viash_project_template/src/demo/take_column/config.vsh.yaml"
    test_resources: []
    status: "enabled"
    requirements:
      commands: []
    set_wd_to_resources_dir: false
  platforms:
  - type: "docker"
    id: "docker"
    image: "python:3.10-slim"
    target_organization: "viash-io/viash_project_template"
    target_registry: "ghcr.io"
    namespace_separator: "/"
    resolve_volume: "Automatic"
    chown: true
    port: []
    setup_strategy: "ifneedbepullelsecachedbuild"
    run_args: []
    target_image_source: "https://github.com/viash-io/viash_project_template"
    setup:
    - type: "python"
      user: false
      packages:
      - "pandas"
      pip: []
      pypi: []
      git: []
      github: []
      gitlab: []
      mercurial: []
      svn: []
      bazaar: []
      url: []
      script: []
      upgrade: true
    test_setup: []
  - type: "nextflow"
    id: "nextflow"
    variant: "vdsl3"
    directives:
      accelerator: {}
      conda: []
      containerOptions: []
      label: []
      module: []
      pod: []
      publishDir: []
      queue: []
      tag: "$id"
    auto:
      simplifyInput: true
      simplifyOutput: true
      transcript: false
      publish: false
    debug: false
    container: "docker"
  info:
    config: "/home/runner/work/website/website/guide/_viash_project_template/src/demo/take_column/config.vsh.yaml"
    viash_version: "0.7.1"
    git_commit: "ffa7b1bee3fb192bec568a772b44c6b527cd941b"
    git_remote: "https://github.com/viash-io/viash_project_template.git"

Custom batch processing

The viash ns exec command can be used to run a command on every component.

viash ns exec "echo Hello {}"
Output
+ echo Hello /home/runner/work/website/website/guide/_viash_project_template/src/demo/remove_comments/config.vsh.yaml
  Exit code: 0

  Output:
+ echo Hello /home/runner/work/website/website/guide/_viash_project_template/src/demo/combine_columns/config.vsh.yaml
Hello /home/runner/work/website/website/guide/_viash_project_template/src/demo/remove_comments/config.vsh.yaml

  Exit code: 0

  Output:
+ echo Hello /home/runner/work/website/website/guide/_viash_project_template/src/demo/take_column/config.vsh.yaml
Hello /home/runner/work/website/website/guide/_viash_project_template/src/demo/combine_columns/config.vsh.yaml

  Exit code: 0

  Output:
Hello /home/runner/work/website/website/guide/_viash_project_template/src/demo/take_column/config.vsh.yaml

Tips

Parallel builds

Some commands shown above can be optimized by adding the --parallel option:

  • viash ns build --parallel will build in parallel
  • viash ns test --parallel will test in parallel

For example:

viash ns test --parallel
Output
The working directory for the namespace tests is /tmp/viash_ns_test15059123328229860176
           namespace        functionality             platform            test_name exit_code duration               result
                demo      remove_comments               docker                start                                        
                demo      combine_columns               docker                start                                        
                demo      combine_columns               docker     build_executable         0        0              SUCCESS
                demo      combine_columns               docker                tests        -1        0              MISSING
no tests found
====================================================================
                demo          take_column               docker                start                                        
                demo          take_column               docker     build_executable         0        0              SUCCESS
                demo          take_column               docker                tests        -1        0              MISSING
no tests found
====================================================================
                demo      remove_comments               docker     build_executable         0        0              SUCCESS
                demo      remove_comments               docker              test.sh         0        1              SUCCESS
Not all configs built and tested successfully
  2/6 tests missing
  4/6 configs built and tested successfully

Subset to components or namespaces

In a development context, one often needs to rebuild one or a few components rather than the full repository. For this situation, viash ns has the option to specify query arguments: --query, query_name and query_namespace. We refer to the reference documentation for details and illustrate the use using an example:

viash ns build --query "^.*columns$"
Output
Exporting combine_columns (demo) =docker=> /home/runner/work/website/website/guide/_viash_project_template/target/docker/demo/combine_columns
Exporting combine_columns (demo) =nextflow=> /home/runner/work/website/website/guide/_viash_project_template/target/nextflow/demo/combine_columns
Not all configs built successfully
  2/4 configs were disabled
  2/4 configs built successfully

As shown here, the query arguments accept regular expressions.