Module Bistro.EDSL

This module provides combinators to define new workflows that execute shell commands.

include module type of Template with type Template.t := Template.t

Represents a text with special symbols

type t
val dest : t

Symbol representing the location where a workflow is expected to produce its result

val tmp : t

Symbol representing an existing empty directory that can be used as a temporary space for a workflow's execution.

val np : t

Symbol representing the number of cores allocated to the workflow

val mem : t

Symbol representing the memory size allocated to the workflow, in GB.

val exe : t

Symbol representing the path of the current executable, as specified by Sys.argv.(0)

val string : string ‑> t

A chunk of text

val int : int ‑> t

Int formatting

val float : float ‑> t

Float formatting

val path : Path.t ‑> t

Path formatting

val dep : _ Workflow.t ‑> t

dep w is interpreted as the path where to find the result of workflow w

val quote : ?⁠using:char ‑> t ‑> t

quote ~using:c t surrounds template t with character c

val option : ('a ‑> t) ‑> 'a option ‑> t

option f o is f x if o = Some x and string "" otherwise

val list : ('a ‑> t) ‑> ?⁠sep:string ‑> 'a list ‑> t

list combinator, optional value of sep is ","

val seq : ?⁠sep:string ‑> t list ‑> t

another list combinator, default value for sep is ""

val enum : ('a * string) list ‑> 'a ‑> t

combinator for enumerations

val file_dump : t ‑> t

file_dump t can be used when a command needs a configuration script: at run-time, it will generate a text using t, save it to a path, deterministically chosen as a function of t. Finally the template file_dump t is interpreted as this path.

type command
val workflow : ?⁠descr:string ‑> ?⁠mem:int ‑> ?⁠np:int ‑> ?⁠version:int ‑> command list ‑> 'a workflow

Workflow constructor, taking a list of commands in input. Other arguments are:

val input : ?⁠may_change:bool ‑> string ‑> 'a workflow

Constructs a workflow from an existing file on the filesystem. The argument may_change indicates that the file may be modified, which is detected by giving the workflow a digest of the file as an input.

val selector : Path.t ‑> ('a'bselector

Selector constructor

val (/) : _ directory workflow ‑> ('a'bselector ‑> 'b workflow

Constructs a workflow by selecting a dir or file from a directory workflow

val cmd : string ‑> ?⁠env:docker_image ‑> ?⁠stdin:Template.t ‑> ?⁠stdout:Template.t ‑> ?⁠stderr:Template.t ‑> Template.t list ‑> command

Command-line constructor, e.g. cmd "echo" ~stdout:dest [ string "foo" ] will generate a shell command like "echo foo > /some/path".

val internal_cmd : string ‑> ?⁠stdin:Template.t ‑> ?⁠stdout:Template.t ‑> ?⁠stderr:Template.t ‑> Template.t list ‑> command

Alternative command-line constructor, calling the current executable as specified by Sys.argv.(0). More precisely internal_cmd subcmd calls Sys.argv.(0) with subcommand subcmd.

val opt : string ‑> ('a ‑> Template.t) ‑> 'a ‑> Template.t

Command-line option formatting, e.g.: opt "--output" dep dest will be rendered like "--output /some/path"

val opt' : string ‑> ('a ‑> Template.t) ‑> 'a ‑> Template.t

Same as opt but renders options with an equal sign, e.g. "--output=/some/path"

val flag : ('a ‑> Template.t) ‑> 'a ‑> bool ‑> Template.t

flag f x b renders as f x if b is true

val or_list : command list ‑> command

OR-sequence of commands ( || )

val and_list : command list ‑> command

AND-sequence of commands ( && )

val pipe : command list ‑> command

Pipe of commands ( | )

val (//) : Template.t ‑> string ‑> Template.t

Similar to Filename.concat, but with other types.

Useful commands
val mkdir : Template.t ‑> command
val mkdir_p : Template.t ‑> command
val wget : ?⁠no_check_certificate:bool ‑> ?⁠user:string ‑> ?⁠password:string ‑> ?⁠dest:Template.t ‑> string ‑> command
val cd : Template.t ‑> command
val rm_rf : Template.t ‑> command
val mv : Template.t ‑> Template.t ‑> command
Docker-related
val docker_image : ?⁠tag:string ‑> ?⁠registry:string ‑> account:string ‑> name:string ‑> unit ‑> docker_image

Construct a description of a publicly available docker image

val docker : docker_image ‑> command ‑> command

docker cmd transforms cmd so that it can be executed in a Docker container.

val (%) : ('a ‑> 'b) ‑> ('b ‑> 'c) ‑> 'a ‑> 'c

Function composition