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

added functions for running flowr through docker #34

Merged
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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

export(connect)
export(disconnect)
export(exec_docker_command)
export(exec_flowr)
export(exec_flowr_docker)
export(exec_node_command)
export(get_default_node_base_dir)
export(install_flowr)
Expand Down
37 changes: 37 additions & 0 deletions R/node.R → R/flowr_local.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ exec_flowr <- function(args, verbose = FALSE, base_dir = get_default_node_base_d
exec_node_command("node", c(flowr_path, args), verbose, base_dir, background)
}

#' Executes a local version of the flowR CLI with the given arguments in the given directory.
#' This function expects docker to exist on the system.
#'
#' @param docker_args Additional arguments to pass to docker, as a character vector.
#' @param flowr_ver The version of flowR to use
#' @param flowr_args The arguments to pass to the flowR CLI, as a character vector.
#' @param verbose Whether to print out information about the commands being executed.
#' @param cmd The command to use for docker. Defaults to "docker".
#' @param background Whether the command should be executed as a background process.
#' @return The return value of the [exec_node_command()] call, which is the exit code if background is false, or the pid if background is true.
#'
#' @export
exec_flowr_docker <- function(docker_args, flowr_ver, flowr_args, verbose = FALSE, cmd = "docker", background = FALSE) {
exec_docker_command(c("run", "--rm", docker_args, paste0("eagleoutice/flowr:", flowr_ver), flowr_args), verbose, cmd, background)
}

#' Executes the given Node subcommand in the given arguments in the given directory.
#' This function expects Node to have been installed using [install_node()].
#'
Expand All @@ -104,6 +120,27 @@ exec_node_command <- function(app = c("node", "npm", "npx"), args, verbose = FAL
}
}

#' Executes the given docker command in the given directory.
#' This function expects docker to exist on the system.
#'
#' @param args The arguments to pass to the docker command, as a character vector.
#' @param verbose Whether to print out information about the commands being executed.
#' @param cmd The command to use for docker. Defaults to "docker".
#' @param background Whether the command should be executed as a background process.
#' @return The return value of the call, which is the exit code if background is false, or the pid if background is true.
#'
#' @export
exec_docker_command <- function(args, verbose = FALSE, cmd = "docker", background = FALSE) {
if (verbose) {
print(paste0("Executing ", cmd, " ", paste0(args, collapse = " ")))
}
if (background) {
return(sys::exec_background(cmd, args))
} else {
return(sys::exec_wait(cmd, args))
}
}

#' Returns the default node base directory to use when installing Node, which is the directory that the package with the given name is installed in.
#'
#' @param pkg_dir_name The name of the package to find the installation directory of. By default, this is "flowr", the name of this package.
Expand Down
25 changes: 25 additions & 0 deletions man/exec_docker_command.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/exec_flowr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions man/exec_flowr_docker.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/exec_node_command.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_default_node_base_dir.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/install_flowr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/install_node.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test-docker.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("run flowr (docker)", {
skip_on_os("windows")
skip_on_os("mac")

expect_output(exec_flowr_docker(c(), "2.0.11", c("--version"), TRUE), paste0("flowR: ", "2.0.11"))
})