boB Rudis
6 years ago
8 changed files with 261 additions and 0 deletions
@ -0,0 +1,141 @@ |
|||
#' Install gepetto |
|||
#' |
|||
#' This function verifies you have what you need to install `gepetto` then |
|||
#' does so (globally). Ideally, you'll have `Node.js` and `npm` already on your |
|||
#' system (since this function will not install them). |
|||
#' |
|||
#' While you _can_ try to install gepetto this way, it is highly recommended that |
|||
#' you follow the instructions (<https://gitlab.com/hrbrmstr/gepetto>) manually |
|||
#' since many Node.js/npm installations have permissions issues due to errant |
|||
#' historical use of `sudo`. |
|||
#' |
|||
#' @md |
|||
#' @export |
|||
install_gepetto <- function() { |
|||
|
|||
node <- Sys.which("node") |
|||
npm <- Sys.which("npm") |
|||
|
|||
if (node == "") { |
|||
message( |
|||
"Could not locate Node.js. Please visit <https://nodejs.org/en/download/package-manager/> ", |
|||
"and obtain it via one of the methods described there then try installing gepetto from ", |
|||
"a fresh R session.", sep="" |
|||
) |
|||
return() |
|||
} |
|||
|
|||
if (npm == "") { |
|||
message( |
|||
"Could not local npm. Please visit <https://www.npmjs.com/get-npm> to ensure ", |
|||
"you have installed both Node.js and npm correctly, then try installing gepetto ", |
|||
"from a fresh R session.", sep="" |
|||
) |
|||
return() |
|||
} |
|||
|
|||
res <- processx::run(node, "--version", error_on_status = FALSE) |
|||
if (res$status != 0) { |
|||
message( |
|||
"An error occurred while trying to determine the version of Node.js that is ", |
|||
"installed on the system. Please ensure you have it installed correctly and ", |
|||
"try installing gepetto again from a fresh R session.", sep="" |
|||
) |
|||
return() |
|||
} |
|||
|
|||
node_vers <- unlist(strsplit(res$stdout, "\\."))[1] |
|||
if (!(node_vers %in% c("v10", "v9"))) { |
|||
message( |
|||
"You have a very old installation of Node.js. Please update it and try installing ", |
|||
"gepetto again from a fresh R session.", sep="" |
|||
) |
|||
return() |
|||
} |
|||
|
|||
res <- processx::run(npm, "--version", error_on_status = FALSE) |
|||
if (res$status != 0) { |
|||
message( |
|||
"An error occurred while trying to determine the version of npm that is ", |
|||
"installed on the system. Please ensure you have it installed correctly and ", |
|||
"try installing gepetto again from a fresh R session.", sep="" |
|||
) |
|||
return() |
|||
} |
|||
|
|||
npm_vers <- unlist(strsplit(res$stdout, "\\."))[1] |
|||
if (!(npm_vers %in% c("6"))) { |
|||
message( |
|||
"You have an old installation of npm. Please update it and try installing ", |
|||
"gepetto again from a fresh R session.", sep="" |
|||
) |
|||
return() |
|||
} |
|||
|
|||
message("Attemping to install gepetto") |
|||
|
|||
processx::run( |
|||
command = "npm", |
|||
args = c("install", "https://gitlab.com/hrbrmstr/gepetto.git", "--global"), |
|||
error_on_status = FALSE, |
|||
echo_cmd = TRUE, |
|||
echo = TRUE |
|||
) -> res |
|||
|
|||
if (res$status == 0) { |
|||
message("gepetto has been installed.") |
|||
} else { |
|||
message( |
|||
"There was an error installing gepetto. Check the error log and make sure ", |
|||
"permissions are set correctly or for other errors that occurred which ", |
|||
"prevented the installation frombeing successful and try again or follow the ", |
|||
"manual instructions at <https://gitlab.com/hrbrmstr/gepetto>.", sep="" |
|||
) |
|||
} |
|||
|
|||
} |
|||
|
|||
#' Start/stop gepetto |
|||
#' |
|||
#' These functions can help start/stop gepetto instances. You must remember to |
|||
#' save the object returned by [start_gepetto()]. |
|||
#' |
|||
#' Note that [stop_gepetto()] kills the process. You can/should consider using |
|||
#' [gep_stop()] instead. |
|||
#' |
|||
#' @md |
|||
#' @param host IP/host to use instead of `localhost` |
|||
#' @param port port to use besides the default (`8080`) |
|||
#' @param pxobj the `processx` object of a running gepetto instance generated by [start_gepetto()] |
|||
#' @return [start_gepetto()] returns a `processx` object |
|||
#' @export |
|||
#' @examples \dontrun{ |
|||
#' pid <- start_gepetto() |
|||
#' # ... do stuff |
|||
#' stop_gepetto(pid) |
|||
#' } |
|||
start_gepetto <- function(host = "localhost", port = 8080) { |
|||
|
|||
gep <- Sys.which("gepetto") |
|||
if (gep == "") stop("gepetto not found.", call.=FALSE) |
|||
|
|||
HOST <- Sys.getenv("HOST") |
|||
on.exit(Sys.setenv(HOST=HOST), add=TRUE) |
|||
PORT <- Sys.getenv("PORT") |
|||
on.exit(Sys.setenv(PORT=PORT), add=TRUE) |
|||
|
|||
Sys.setenv(HOST=host) |
|||
Sys.setenv(PORT=port) |
|||
processx::process$new( |
|||
command = "gepetto", stdout = "|", stderr = "|" |
|||
) -> res |
|||
|
|||
res |
|||
|
|||
} |
|||
|
|||
#' @rdname start_gepetto |
|||
#' @export |
|||
stop_gepetto <- function(pxobj) { |
|||
pxobj$kill() |
|||
} |
@ -0,0 +1,20 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/gepetto.R |
|||
\name{gep_stop} |
|||
\alias{gep_stop} |
|||
\title{Gracefully stop a gepetto instance} |
|||
\usage{ |
|||
gep_stop(gep) |
|||
} |
|||
\arguments{ |
|||
\item{gep}{a gepetto connection object} |
|||
} |
|||
\description{ |
|||
Gracefully stop a gepetto instance |
|||
} |
|||
\examples{ |
|||
\dontrun{ |
|||
gepetto() \%>\% |
|||
gep_stop() |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/gepetto-helpers.R |
|||
\name{install_gepetto} |
|||
\alias{install_gepetto} |
|||
\title{Install gepetto} |
|||
\usage{ |
|||
install_gepetto() |
|||
} |
|||
\description{ |
|||
This function verifies you have what you need to install \code{gepetto} then |
|||
does so (globally). Ideally, you'll have \code{Node.js} and \code{npm} already on your |
|||
system (since this function will not install them). |
|||
} |
|||
\details{ |
|||
While you \emph{can} try to install gepetto this way, it is highly recommended that |
|||
you follow the instructions (\url{https://gitlab.com/hrbrmstr/gepetto}) manually |
|||
since many Node.js/npm installations have permissions issues due to errant |
|||
historical use of \code{sudo}. |
|||
} |
@ -0,0 +1,36 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/gepetto-helpers.R |
|||
\name{start_gepetto} |
|||
\alias{start_gepetto} |
|||
\alias{stop_gepetto} |
|||
\title{Start/stop gepetto} |
|||
\usage{ |
|||
start_gepetto(host = "localhost", port = 8080) |
|||
|
|||
stop_gepetto(pxobj) |
|||
} |
|||
\arguments{ |
|||
\item{host}{IP/host to use instead of \code{localhost}} |
|||
|
|||
\item{port}{port to use besides the default (\code{8080})} |
|||
|
|||
\item{pxobj}{the \code{processx} object of a running gepetto instance generated by \code{\link[=start_gepetto]{start_gepetto()}}} |
|||
} |
|||
\value{ |
|||
\code{\link[=start_gepetto]{start_gepetto()}} returns a \code{processx} object |
|||
} |
|||
\description{ |
|||
These functions can help start/stop gepetto instances. You must remember to |
|||
save the object returned by \code{\link[=start_gepetto]{start_gepetto()}}. |
|||
} |
|||
\details{ |
|||
Note that \code{\link[=stop_gepetto]{stop_gepetto()}} kills the process. You can/should consider using |
|||
\code{\link[=gep_stop]{gep_stop()}} instead. |
|||
} |
|||
\examples{ |
|||
\dontrun{ |
|||
pid <- start_gepetto() |
|||
# ... do stuff |
|||
stop_gepetto(pid) |
|||
} |
|||
} |
Loading…
Reference in new issue