From 96597bce636e5ff23a97f8914a51e3560f805cb5 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 5 Oct 2024 16:26:42 +0200 Subject: [PATCH 1/3] added functions for running flowr through docker --- NAMESPACE | 2 ++ R/{node.R => flowr_local.R} | 37 ++++++++++++++++++++++++++++++++ man/exec_docker_command.Rd | 25 +++++++++++++++++++++ man/exec_flowr.Rd | 2 +- man/exec_flowr_docker.Rd | 36 +++++++++++++++++++++++++++++++ man/exec_node_command.Rd | 2 +- man/get_default_node_base_dir.Rd | 2 +- man/install_flowr.Rd | 2 +- man/install_node.Rd | 2 +- tests/testthat/test-docker.R | 3 +++ 10 files changed, 108 insertions(+), 5 deletions(-) rename R/{node.R => flowr_local.R} (78%) create mode 100644 man/exec_docker_command.Rd create mode 100644 man/exec_flowr_docker.Rd create mode 100644 tests/testthat/test-docker.R diff --git a/NAMESPACE b/NAMESPACE index 2cdd8c1..02689e7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/node.R b/R/flowr_local.R similarity index 78% rename from R/node.R rename to R/flowr_local.R index f359e7f..20bb509 100644 --- a/R/node.R +++ b/R/flowr_local.R @@ -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()]. #' @@ -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. diff --git a/man/exec_docker_command.Rd b/man/exec_docker_command.Rd new file mode 100644 index 0000000..8c8fddf --- /dev/null +++ b/man/exec_docker_command.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/flowr_local.R +\name{exec_docker_command} +\alias{exec_docker_command} +\title{Executes the given docker command in the given directory. +This function expects docker to exist on the system.} +\usage{ +exec_docker_command(args, verbose = FALSE, cmd = "docker", background = FALSE) +} +\arguments{ +\item{args}{The arguments to pass to the docker command, as a character vector.} + +\item{verbose}{Whether to print out information about the commands being executed.} + +\item{cmd}{The command to use for docker. Defaults to "docker".} + +\item{background}{Whether the command should be executed as a background process.} +} +\value{ +The return value of the call, which is the exit code if background is false, or the pid if background is true. +} +\description{ +Executes the given docker command in the given directory. +This function expects docker to exist on the system. +} diff --git a/man/exec_flowr.Rd b/man/exec_flowr.Rd index bebdba7..5f90e24 100644 --- a/man/exec_flowr.Rd +++ b/man/exec_flowr.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/node.R +% Please edit documentation in R/flowr_local.R \name{exec_flowr} \alias{exec_flowr} \title{Executes a local version of the flowR CLI with the given arguments in the given directory. diff --git a/man/exec_flowr_docker.Rd b/man/exec_flowr_docker.Rd new file mode 100644 index 0000000..b85eac0 --- /dev/null +++ b/man/exec_flowr_docker.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/flowr_local.R +\name{exec_flowr_docker} +\alias{exec_flowr_docker} +\title{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.} +\usage{ +exec_flowr_docker( + docker_args, + flowr_ver, + flowr_args, + verbose = FALSE, + cmd = "docker", + background = FALSE +) +} +\arguments{ +\item{docker_args}{Additional arguments to pass to docker, as a character vector.} + +\item{flowr_ver}{The version of flowR to use} + +\item{flowr_args}{The arguments to pass to the flowR CLI, as a character vector.} + +\item{verbose}{Whether to print out information about the commands being executed.} + +\item{cmd}{The command to use for docker. Defaults to "docker".} + +\item{background}{Whether the command should be executed as a background process.} +} +\value{ +The return value of the \code{\link[=exec_node_command]{exec_node_command()}} call, which is the exit code if background is false, or the pid if background is true. +} +\description{ +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. +} diff --git a/man/exec_node_command.Rd b/man/exec_node_command.Rd index b9ff6ca..d4e7dff 100644 --- a/man/exec_node_command.Rd +++ b/man/exec_node_command.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/node.R +% Please edit documentation in R/flowr_local.R \name{exec_node_command} \alias{exec_node_command} \title{Executes the given Node subcommand in the given arguments in the given directory. diff --git a/man/get_default_node_base_dir.Rd b/man/get_default_node_base_dir.Rd index 07339ea..0ba6dd7 100644 --- a/man/get_default_node_base_dir.Rd +++ b/man/get_default_node_base_dir.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/node.R +% Please edit documentation in R/flowr_local.R \name{get_default_node_base_dir} \alias{get_default_node_base_dir} \title{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.} diff --git a/man/install_flowr.Rd b/man/install_flowr.Rd index bcc9140..57a4525 100644 --- a/man/install_flowr.Rd +++ b/man/install_flowr.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/node.R +% Please edit documentation in R/flowr_local.R \name{install_flowr} \alias{install_flowr} \title{Installs the given version of flowR on the local system in the given directory. diff --git a/man/install_node.Rd b/man/install_node.Rd index 8526c67..b14d261 100644 --- a/man/install_node.Rd +++ b/man/install_node.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/node.R +% Please edit documentation in R/flowr_local.R \name{install_node} \alias{install_node} \title{Installs the given version of Node.js on the local system in the given directory.} diff --git a/tests/testthat/test-docker.R b/tests/testthat/test-docker.R new file mode 100644 index 0000000..c22d0cf --- /dev/null +++ b/tests/testthat/test-docker.R @@ -0,0 +1,3 @@ +test_that("run flowr (docker)", { + expect_output(exec_flowr_docker(c(), "2.0.11", c("--version"), TRUE), paste0("flowR: ", "2.0.11")) +}) From 2cd096bd3c0e0d293eb7d03605a65781443bbf4c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 5 Oct 2024 16:31:26 +0200 Subject: [PATCH 2/3] set up docker in tests for windows & mac --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 375f526..2901439 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,8 @@ jobs: uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: devtools + - name: Install docker + uses: crazy-max/ghaction-setup-docker@v3 - name: Run devtools::check() # error on any type of notice from the check run: Rscript -e 'devtools::check(error_on = "note")' From c576be0d0fa005e83aa682d4eb06d6f35103b295 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 5 Oct 2024 16:36:56 +0200 Subject: [PATCH 3/3] skip docker tests on windows and mac --- .github/workflows/test.yml | 2 -- tests/testthat/test-docker.R | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2901439..375f526 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,8 +32,6 @@ jobs: uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: devtools - - name: Install docker - uses: crazy-max/ghaction-setup-docker@v3 - name: Run devtools::check() # error on any type of notice from the check run: Rscript -e 'devtools::check(error_on = "note")' diff --git a/tests/testthat/test-docker.R b/tests/testthat/test-docker.R index c22d0cf..0f3ec65 100644 --- a/tests/testthat/test-docker.R +++ b/tests/testthat/test-docker.R @@ -1,3 +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")) })