Skip to content

Commit

Permalink
Saving progress on charts / conda environment creation
Browse files Browse the repository at this point in the history
  • Loading branch information
katieb1 committed Apr 15, 2024
1 parent 41deeab commit aa5ce6e
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 228 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ Collate:
'backup.R'
'chart.R'
'chartId.R'
'chartMapConstructor.R'
'command.R'
'condaFilepath.R'
'createCondaEnv.R'
'datasheet.R'
'datasheetSpatRaster.R'
'dateModified.R'
Expand Down
10 changes: 0 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Generated by roxygen2: do not edit by hand

S3method("+",Chart)
S3method(ssimChart_add,Criteria)
S3method(ssimChart_add,column_chart)
S3method(ssimChart_add,line_chart)
S3method(ssimChart_add,y)
export("+.Chart")
export("autogentags<-")
export("condaFilepath<-")
export("dependency<-")
Expand All @@ -27,8 +21,6 @@ export(Session)
export(SsimLibrary)
export(addPackage)
export(addRow)
export(add_ssimChart)
export(as.Chart)
export(autogentags)
export(backup)
export(chart)
Expand All @@ -48,7 +40,6 @@ export(ignoreDependencies)
export(info)
export(installConda)
export(installPackage)
export(is.Chart)
export(mergeDependencies)
export(name)
export(owner)
Expand All @@ -71,7 +62,6 @@ export(scenarioId)
export(session)
export(silent)
export(sqlStatement)
export(ssimChart_add)
export(ssimEnvironment)
export(ssimLibrary)
export(ssimUpdate)
Expand Down
5 changes: 3 additions & 2 deletions R/chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ setMethod(
#' # Create a new chart
#' myChart <- chart(myProject, chart = "New Chart")
#' }
#' @name chart
#' @name folder
#' @export
chart <- function(ssimObject = NULL, chart = NULL, create = FALSE, summary = FALSE) {
chart <- function(ssimObject = NULL, chart = NULL, create = FALSE, summary = FALSE){

if (is.character(ssimObject) && (ssimObject == SyncroSimNotFound(warn = FALSE))) {
return(SyncroSimNotFound())
}
Expand Down
2 changes: 2 additions & 0 deletions R/chartId.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ NULL
#'
#' @export
setGeneric("chartId", function(ssimObject) standardGeneric("chartId"))

#' @rdname chartId
setMethod("chartId", signature(ssimObject = "character"), function(ssimObject) {
return(SyncroSimNotFound(ssimObject))
})

#' @rdname chartId
setMethod("chartId", signature(ssimObject = "Chart"), function(ssimObject) {
return(ssimObject@chartId)
Expand Down
102 changes: 0 additions & 102 deletions R/chartMapConstructor.R

This file was deleted.

82 changes: 82 additions & 0 deletions R/createCondaEnv - bad.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright (c) 2024 Apex Resource Management Solution Ltd. (ApexRMS). All rights reserved.
# MIT License
#' @include AAAClassDefinitions.R
NULL

#' Create SyncroSim package conda environments
#'
#' Creates the conda environment for the specified SyncroSim package(s).
#'
#' @param pkgs character or list of characters.
#' @param session \code{\link{Session}} object or character (i.e. filepath to a
#' session). If \code{NULL}, \code{session()} will be used
#'
#' @return
#' Invisibly returns \code{TRUE} upon success (i.e.successful creation of the
#' conda environment(s)) or \code{FALSE} upon failure.
#'
#' @examples
#' \dontrun{
#' # Set up a SyncroSim Session
#' mySession <- session()
#'
#' # Create the conda environment for helloworldConda package
#' condaFilepath(pkgs = "helloworldConda", mySession)
#' }
#'
#' @export
setGeneric("createCondaEnv", function(pkgs, session) standardGeneric("createCondaEnv"))

#' @rdname createCondaEnv
setMethod("createCondaEnv", signature(session = "character"), function(pkgs, session) {
return(SyncroSimNotFound(session))
})

#' @rdname createCondaEnv
setMethod("createCondaEnv", signature(session = "missingOrNULL"), function(pkgs, session) {
session <- .session()
return(createCondaEnv(session))
})

#' @rdname createCondaEnv
setMethod("createCondaEnv", signature(session = "missingOrNULLOrChar"), function(pkgs, session=NULL){

if (is(session, "character")) {
session <- .session(session)
} else {
session <- .session()
}

if (is(session, "character") && is(session, SyncroSimNotFound(warn = FALSE))) {
return(SyncroSimNotFound())
}

return(createCondaEnv(pkgs, session))
})

#' @rdname createCondaEnv
setMethod("createCondaEnv", signature(session = "Session"), function(pkgs, session) {

message("Creating Conda environments. Please wait...")

# Check if environment needs to be created, create if doesn't exist yet
for (package in pkgs) {
tt <- command(list(conda = NULL, createenv = NULL, pkg = package), session)
if (length(tt) > 1){
if (!grepl("Creating Conda environments", tt[1], fixed = TRUE)){
stop(tt[1])
}
} else {
if (grepl("No Conda installation found", tt, fixed = TRUE)) {
errorMessage = "Conda must be installed to use Conda environments. See ?installConda for details."
} else {
errorMessage = tt
}

message(errorMessage)
return(invisible(TRUE))
}
}

return(invisible(TRUE))
})
64 changes: 64 additions & 0 deletions R/createCondaEnv.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (c) 2024 Apex Resource Management Solution Ltd. (ApexRMS). All rights reserved.
# MIT License
#' @include AAAClassDefinitions.R
NULL

#' Installs Miniconda
#'
#' This function installs Miniconda to the default installation path
#' within the SyncroSim installation folder. If you already have Conda
#' installed in the non-default location, you can point SyncroSim towards
#' that installation using the \code{\link{condaFilepath}} function.
#'
#' @param session \code{\link{Session}} object. If \code{NULL} (default),
#' \code{session()} will be used
#'
#' @return
#' Invisibly returns \code{TRUE} upon success (i.e.successful
#' install) and \code{FALSE} upon failure.
#'
#' @examples
#' \dontrun{
#' # Install Conda for the default SyncroSim session
#' installConda()
#' }
#'
#' @export
setGeneric("installConda", function(session) standardGeneric("installConda"))

#' @rdname installConda
setMethod("installConda", signature(session = "character"), function(session) {
return(SyncroSimNotFound(session))
})

#' @rdname installConda
setMethod("installConda", signature(session = "missingOrNULL"), function(session) {
session <- .session()
return(installConda(session))
})

#' @rdname installConda
setMethod("installConda", signature(session = "Session"), function(session) {

success <- FALSE
message("Setting Conda filepath to the default installation.")
args <- list(conda = NULL, install = NULL)

message("Running Conda Installer. Please wait...")
if (is.null(session)){
session <- .session()
}
tt <- command(args, session)

if (tt[1] == "Conda already installed at that location"){
success <- FALSE
tt <- "Conda already installed"
} else if (tt[3] == "Saved") {
success <- TRUE
tt <- paste0("Miniconda successfully installed")
}

message(tt)

return(invisible(success))
})
21 changes: 16 additions & 5 deletions R/ssimLibrary.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ NULL

setMethod(
f = "initialize", signature = "SsimLibrary",
definition = function(.Object, name = NULL, packages = NULL, session = NULL, template = NULL, forceUpdate = FALSE, overwrite = FALSE, useConda = NULL) {
definition = function(.Object, name = NULL, packages = NULL, session = NULL,
template = NULL, forceUpdate = FALSE, overwrite = FALSE,
useConda = NULL) {

enabled <- NULL

Expand Down Expand Up @@ -185,17 +187,26 @@ setMethod(
}
)

setGeneric(".ssimLibrary", function(name = NULL, packages = NULL, session = NULL, template = NULL, forceUpdate = FALSE, overwrite = FALSE, useConda = NULL) standardGeneric(".ssimLibrary"))
setGeneric(".ssimLibrary",
function(name = NULL, packages = NULL, session = NULL,
template = NULL, forceUpdate = FALSE, overwrite = FALSE,
useConda = NULL) standardGeneric(".ssimLibrary"))

setMethod(".ssimLibrary", signature(name = "missingOrNULLOrChar"), function(name, packages, session, template, forceUpdate, overwrite, useConda) {
setMethod(".ssimLibrary", signature(name = "missingOrNULLOrChar"),
function(name, packages, session, template, forceUpdate, overwrite,
useConda) {
return(new("SsimLibrary", name, packages, session, forceUpdate))
})

setMethod(".ssimLibrary", signature(name = "SsimObject"), function(name, packages, session, template, forceUpdate, overwrite, useConda) {
setMethod(".ssimLibrary", signature(name = "SsimObject"),
function(name, packages, session, template, forceUpdate, overwrite,
useConda) {
if (is(name, "SsimLibrary")) {
out <- name
} else {
out <- .ssimLibrary(name = .filepath(name), packages, session = .session(name), template, forceUpdate, overwrite, useConda)
out <- .ssimLibrary(name = .filepath(name), packages,
session = .session(name), template, forceUpdate,
overwrite, useConda)
}
return(out)
})
Expand Down
6 changes: 4 additions & 2 deletions R/useConda.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ setReplaceMethod(

if (value == FALSE) {

tt <- command(list(setprop = NULL, lib = .filepath(ssimObject), useconda = "no"), .session(ssimObject))
tt <- command(list(setprop = NULL, lib = .filepath(ssimObject),
useconda = "no"), .session(ssimObject))
if (!identical(tt, "saved")) {
stop(tt)
}
Expand All @@ -86,7 +87,8 @@ setReplaceMethod(

if (value == TRUE){

tt <- command(list(setprop = NULL, lib = .filepath(ssimObject), useconda = "yes"), .session(ssimObject))
tt <- command(list(setprop = NULL, lib = .filepath(ssimObject),
useconda = "yes"), .session(ssimObject))

currentPackages <- packages(ssimObject)$name
}
Expand Down
Loading

0 comments on commit aa5ce6e

Please sign in to comment.