Skip to content
Open
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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pkglock
Title: lock and rehydrate package runtimes
Version: 0.2.0
Version: 0.2.0.9000
Authors@R:
person(given = "Devin",
family = "Pastoor",
Expand Down
66 changes: 66 additions & 0 deletions R/install_runtime.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#' install from a runtime description
#' @param .d description file
#' @param .dir directory to install pkgs from description
#' @param snapshot_sources snapshot the library source tarballs
#' @param threads threads during install
#' @param repos repositories to check for available packages
#' @details
#' .install should almost always be set to true, the time to set to false
#' is if a full install was completed, however some tweak to the snapshot
#' generation needed to be re-run.
#' @export
install_from_desc <- function(.d,
.dir = fs::path_temp(),
snapshot_sources = TRUE,
threads = parallel::detectCores(),
repos = getOption("repos")
) {
working_dir <- fs::dir_create(file.path(.dir, "pkglock_snapshot"))
pkg_dir <- fs::dir_create(file.path(working_dir, "runtime_pkg"))
pkglibs <- fs::dir_create(file.path(working_dir, "pkglib"))
.d$write(file.path(pkg_dir, "DESCRIPTION"))

pkgs_to_snapshot <- .d$get_deps()$package
callr::r(function(tmppkg, .pkgdir, pkgs_to_snapshot, snapshot_sources, threads) {
setwd(tmppkg)
packrat::init(options = list(snapshot.fields = c("Imports", "Depends", "Suggests", "LinkingTo")), restart = TRUE)
# packages needed to do devtools install
libs <- c(
"desc",
"usethis", ## needed to avoid weird bug in dev version of devtools not loading via extlib
"jsonlite",
"withr",
"devtools",
"httr",
"curl",
"git2r",
"pkgbuild",
"pkgload")
message("using ext libs: ", paste0(libs, collapse = ", "))
packrat::extlib(libs)
# if (!requireNamespace("devtools")) {
# warning("devtools not installed on the host system...installing, this could take longer to snapshot...")
# install.packages("devtools")
# }
devtools::install_deps(.pkgdir, threads = threads, force_deps = TRUE)
pkgtext <- sprintf("library(%s)", pkgs_to_snapshot)
writeLines(pkgtext, "packages.R")
snapshot <- packrat::snapshot(snapshot.sources = snapshot_sources,
prompt = FALSE,
infer.dependencies = FALSE)
return(.libPaths())
}, show = TRUE,
args = list(
tmppkg = pkglibs,
pkgs_to_snapshot = pkgs_to_snapshot,
.pkgdir = normalizePath(pkg_dir),
snapshot_sources = snapshot_sources,
threads = threads
), repos = repos)

return(list(
working_dir = normalizePath(working_dir),
pkg_dir = normalizePath(pkg_dir),
pkg_libs = normalizePath(pkglibs)
))
}
6 changes: 3 additions & 3 deletions R/resolve_pkgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ resolve_pkgs <- function(top_pkgs) {
is.na(all_pkg_data$priority), , drop = FALSE]

pkgs <- with(top_lvl_pkg_meta, {
pkgname <- package[tolower(type) == "standard"]
pkgversion <- version[tolower(type) == "standard"]
sprintf("%s (>= %s)", pkgname, pkgversion)
# pkgname <- package
# pkgversion <- version
sprintf("%s (>= %s)", package, version)
})
gh_pkgs <- with(top_lvl_pkg_meta, {
ref[tolower(type) == "github"]
Expand Down
6 changes: 6 additions & 0 deletions R/set_default_repos.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set_default_repos <- function() {
repos <- getOption("repos")
if (repos["CRAN"] == "@CRAN@") {
options(repos=list(CRAN="https://cran.rstudio.org"))
}
}
1 change: 1 addition & 0 deletions inst/pkg_resolution.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pkgs <- c(
"DBI"
)

pkgs <- c("R6", "r-lib/pillar")
install_dir <- "tmp"
#if (!fs::dir_exists(install_dir) || length(fs::dir_ls(install_dir))) {
# stop("dir missing or files/folders present in dir: ", install_dir, " aborting attempt...")
Expand Down