8000 Ensuring that install() only can run if the compiler has an equal / higher version than minVer (in jamovi/0000.yaml) by sjentsch · Pull Request #8 · jamovi/jmvtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ensuring that install() only can run if the compiler has an equal / higher version than minVer (in jamovi/0000.yaml) #8

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
95 changes: 62 additions & 33 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,42 @@ isLinux <- function() {
Sys.info()['sysname'] == 'Linux'
}

argHome <- function(home = NULL) {
if (is.null(home))
home <- getOption('jamovi_home')
if (is.null(home) && isLinux())
home <- 'flatpak'
if ( ! is.null(home) && isWindows())
home <- paste0('"', home, '"')
if ( ! is.null(home)) {
c('--home', home)
} else {
NULL
}
}

argRHome <- function() {
if ( ! isWindows()) {
c('--rpath', paste0('"', R.home(component='bin'), '"'))
} else {
NULL
}
}

checkMinVer <- function(pkg = ".") {
lines <- readLines(file.path(pkg, "jamovi", "0000.yaml"))
# if there is a minVer entry, compare it the the version of the jamovi compiler (and throw error if it is higher)
if (any(grepl("minApp:", lines))) {
pkgMinVer <- trimws(strsplit(lines[grepl("minApp:", lines)], ":")[[1]][2])
if (utils::compareVersion(jmc_version(), pkgMinVer) < 0) {
stop(sprintf("The minVer (%s) of the module (in jamovi/0000.yaml) is lower than this version of the jamovi compiler (%s).",
pkgMinVer, jmc_version(), ))
}
}

invisible(NULL)
}

#' The current version
#'
#' returns the current version of jmvtools
Expand All @@ -26,6 +62,27 @@ version <- function() {
version
}

#' The current jamovi compiler version
#'
#' returns the current version of the jamovi compiler (if not found, the version of jmvto 8000 ols is returned)
#'
#' @export
jmc_version <- function(home = NULL) {

exe <- node()
jmc <- jmcPath()
version <- version() # fallback if the compiler is not found

args <- c(jmc, '--check', argHome(home))

jmcOutput <- system2(exe, args, wait=TRUE, stdout=TRUE)

if (any(grepl("jamovi .* found", jmcOutput)))
version <- gsub("jamovi (\\d\\.\\d\\.\\d) found .*", "\\1", jmcOutput[grepl("jamovi .* found", jmcOutput)])

version
}

#' Check that jmvtools is able to find jamovi
#'
#' @param home path to a local jamovi installation
Expand All @@ -36,15 +93,7 @@ check <- function(home=NULL) {
exe <- node()
jmc <- jmcPath()

args <- c(jmc, '--check')
if (is.null(home))
home <- getOption('jamovi_home')
if (is.null(home) && isLinux())
home <- 'flatpak'
if ( ! is.null(home) && isWindows())
home <- paste0('"', home, '"')
if ( ! is.null(home))
args <- c(args, '--home', home)
args <- c(jmc, '--check', argHome(home))

system2(exe, args, wait=TRUE)
}
Expand All @@ -56,23 +105,14 @@ check <- function(home=NULL) {
#' @importFrom node node
#' @export
install <- function(pkg='.', home=NULL, debug=FALSE) {

checkMinVer(pkg)

exe <- node()
jmc <- jmcPath()
pkg <- paste0('"', pkg, '"')
rhome <- paste0('"', R.home(component='bin'), '"')

args <- c(jmc, '--install', pkg)
if (is.null(home))
home <- getOption('jamovi_home')
if (is.null(home) && isLinux())
home <- 'flatpak'
if ( ! is.null(home) && isWindows())
home <- paste0('"', home, '"')
if ( ! is.null(home))
args <- c(args, '--home', home)
if ( ! isWindows())
args <- c(args, '--rpath', rhome)
args <- c(jmc, '--install', pkg, argHome(home), argRHome())
if (debug)
args <- c(args, '--debug')

Expand All @@ -89,19 +129,8 @@ prepare <- function(pkg='.', home=NULL) {
exe <- node()
jmc <- jmcPath()
pkg <- paste0('"', pkg, '"')
rhome <- paste0('"', R.home(component='bin'), '"')

args <- c(jmc, '--prepare', pkg)
if (is.null(home))
home <- getOption('jamovi_home')
if (is.null(home) && isLinux())
home <- 'flatpak'
if ( ! is.null(home) && isWindows())
home <- paste0('"', home, '"')
if ( ! is.null(home))
args <- c(args, '--home', home)
if ( ! isWindows())
args <- c(args, '--rpath', rhome)
args <- c(jmc, '--prepare', pkg, argHome(home), argRHome())

system2(exe, args, wait=TRUE)
}
Expand Down
0