Skip to content
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

Experiment with loading deps into the same process #561

Merged
merged 7 commits into from
Nov 21, 2023
Merged
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
26 changes: 5 additions & 21 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,16 @@ Authors@R: c(
person("Posit Software, PBC", role = c("cph", "fnd")),
person("Winston", "Chang", role = "ctb", comment = "R6, callr, processx"),
person("Mango Solutions", role = c("cph", "fnd"), comment = "callr, processx"),
person("Hadley", "Wickham", role = c("ctb", "cph"), comment = "cli, curl, pkgbuild, rappdirs"),
person("Brodie", "Gaslam", role = "ctb", comment = "crayon"),
person("Hadley", "Wickham", role = c("ctb", "cph"), comment = "cli, curl, pkgbuild"),
person("Jeroen", "Ooms", role = "ctb", comment = "curl, jsonlite"),
person("Kirill", "Müller", role = "ctb", comment = "cli, desc, rprojroot"),
person("Maëlle", "Salmon", role = "ctb", comment = "desc, pkgsearch"),
person("Jennifer", "Bryan", role = "ctb", comment = "glue"),
person("Duncan", "Temple Lang", role = "ctb", comment = "jsonlite"),
person("Lloyd", "Hilaiel", role = "cph", comment = "jsonlite"),
person("Michel Berkelaar and lpSolve authors", role = "ctb", comment = "lpSolve"),
person("Linus", "Torvalds", role = "ctb", comment = "parsedate"),
person("R Consortium", role = "fnd", comment = "pkgsearch"),
person("Bill", "Denney", role = "ctb", comment = "prettyunits"),
person("Christophe", "Regouby", role = "ctb", comment = "prettyunits"),
person("Jay", "Loden", role = "ctb", comment = "ps"),
person("Dave", "Daeschler", role = "ctb", comment = "ps"),
person("Giampaolo", "Rodola'", role = "ctb", comment = "ps"),
person("Sridhar", "Ratnakumar", role = "ctb", comment = "rappdirs"),
person("Trent", "Mick", role = "ctb", comment = "rappdirs"),
person("ActiveState", role = "cph", comment = "rappdirs"),
person("Eddy", "Petrisor", role = "ctb", comment = "rappdirs"),
person("Trevor", "Davis", role = "ctb", comment = "rappdirs"),
person("Gregory", "Jefferis", role = "ctb", comment = "rappdirs"),
person("Kuba", "Podgórski", role = "ctb", comment = "zip"),
person("Rich", "Geldreich", role = "ctb", comment = "zip")
)
Expand Down Expand Up @@ -63,30 +51,26 @@ Suggests:
pkgcache (>= 2.0.4),
pkgdepends (>= 0.5.0.9001),
pkgsearch (>= 3.1.0),
prettyunits,
processx (>= 3.8.1),
ps (>= 1.6.0),
rprojroot (>= 2.0.2),
rstudioapi,
testthat (>= 3.2.0),
withr
ByteCompile: true
Config/build/extra-sources: configure*
Config/needs/dependencies:
callr,
desc,
r-lib/desc,
cli,
curl,
filelock,
glue,
jsonlite,
pkgcache,
r-lib/pkgbuild,
r-lib/pkgcache,
r-lib/pkgdepends,
pkgsearch,
prettyunits,
r-hub/pkgsearch,
processx,
ps,
rprojroot
Config/Needs/website:
r-lib/asciicast,
rmarkdown,
Expand Down
4 changes: 2 additions & 2 deletions R/confirmation.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ print_install_details <- function(prop, lib, loaded) {
n_dl <- sum(w_dl, na.rm = TRUE)
u_dl <- sum(is.na(sol$filesize[w_dl]))
n_ch <- sum(w_ch, na.rm = TRUE)
b_dl <- prettyunits::pretty_bytes(sum(sol$filesize[w_dl], na.rm = TRUE))
b_ch <- prettyunits::pretty_bytes(sum(sol$filesize[w_ch], na.rm = TRUE))
b_dl <- format_bytes$pretty_bytes(sum(sol$filesize[w_dl], na.rm = TRUE))
b_ch <- format_bytes$pretty_bytes(sum(sol$filesize[w_ch], na.rm = TRUE))

any_unk <- length(u_dl) > 0

Expand Down
1 change: 1 addition & 0 deletions R/embed.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ embed <- local({
rimraf(file.path(lib, pkg, ".aspell"))
rimraf(file.path(lib, pkg, "inst", "CITATION"))
rimraf(file.path(lib, pkg, "MD5"))
rimraf(file.path(lib, pkg, "README.md"))
}
}

Expand Down
29 changes: 29 additions & 0 deletions R/find-package-root.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
find_package_root <- function(path = ".") {
is_root <- function(path) {
identical(
normalizePath(path, winslash = "/"),
normalizePath(dirname(path), winslash = "/")
)
}

if (!file.exists(path)) {
stop("Path does not exist: ", path)
}
cur_path <- normalizePath(path, winslash = "/")
errmsg <- paste0(
"Could not find R package in `",
path,
"` or its parent directories."
)
max_depth <- 100
for (i in 1:max_depth) {
if (file.exists(file.path(cur_path, "DESCRIPTION"))) {
return(cur_path)
} else if (is_root(cur_path)) {
stop(errmsg)
} else {
cur_path <- dirname(cur_path)
}
}
stop(errmsg, " Checked ", max_depth, " parent directories.") # nocov
}
17 changes: 17 additions & 0 deletions R/load-all-private.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load_all_private <- function() {
load_private_cli()
load_private_package("R6")
load_private_package("curl")
load_private_package("distro")
load_private_package("filelock")
load_private_package("jsonlite")
load_private_package("lpSolve")
load_private_package("ps")
load_private_package("zip")
load_private_package("processx", "c_")
load_private_package("callr")
load_private_package("desc")
load_private_package("pkgbuild")
load_private_package("pkgsearch")
load_private_package("pkgdepends")
}
4 changes: 2 additions & 2 deletions R/local.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ local_install <- function(root = ".", lib = .libPaths()[1], upgrade = TRUE,

local_install_make_plan <- function(type, root, lib, upgrade, ask, start,
dependencies, loaded) {
root <- rprojroot::find_package_root_file(path = root)
root <- find_package_root(path = root)
pkg <- paste0(type, "::", root)
pkg_install_make_plan(pkg, lib, upgrade, ask, start, dependencies, loaded)
}
Expand Down Expand Up @@ -213,7 +213,7 @@ local_dev_deps_explain <- function(deps, root = ".", upgrade = TRUE,

local_install_dev_deps_make_plan <- function(root, lib, upgrade, start,
dependencies, loaded) {
root <- rprojroot::find_package_root_file(path = root)
root <- find_package_root(path = root)
prop <- pkgdepends::new_pkg_installation_proposal(
paste0("deps::", root),
config = list(library = lib, dependencies = dependencies)
Expand Down
4 changes: 2 additions & 2 deletions R/pak-cleanup.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pak_cleanup_package_cache <- function(force) {

pak_cleanup_package_cache_print <- function() {
sum <- pkgcache::pkg_cache_summary()
size <- prettyunits::pretty_bytes(sum$size)
size <- format_bytes$pretty_bytes(sum$size)
cli::cli_alert(
"{.emph Package cache} is in {.path {sum$cachepath}} ({size})")
}
Expand Down Expand Up @@ -79,7 +79,7 @@ pak_cleanup_metadata_cache <- function(force) {

pak_cleanup_metadata_cache_print <- function() {
sum <- pkgcache::meta_cache_summary()
size <- prettyunits::pretty_bytes(sum$size)
size <- format_bytes$pretty_bytes(sum$size)
cli::cli_alert(
"{.emph Metadata cache} is in {.path {sum$cachepath}} ({size})")
}
Expand Down
4 changes: 2 additions & 2 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ print_install_summary <- function(x) {
cached <- sum(x$download_status == "Had" &
! x$type %in% c("installed", "deps"))
dlbytes <- sum(x$file_size[x$download_status == "Got"])
total_time <- prettyunits::pretty_dt(attr(x, "total_time")) %||% ""
total_time <- format_time$pretty_dt(attr(x, "total_time")) %||% ""

pkgsum <- paste0(
if (direct > 0) "{direct} pkg{?s}",
Expand All @@ -68,7 +68,7 @@ print_install_summary <- function(x) {
), collapse = ", ")

dlsum <- if (downloaded > 0) {
bytes <- prettyunits::pretty_bytes(dlbytes)
bytes <- format_bytes$pretty_bytes(dlbytes)
paste0(
", dld {downloaded}",
if (!is.na(bytes) && bytes != 0) " ({bytes})"
Expand Down
2 changes: 1 addition & 1 deletion R/search.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pkg_search <- function(query, ...) {

pkg_search_internal <- function(query, ...) {
res <- pkgsearch::pkg_search(query, ...)
res$ago <- prettyunits::time_ago(res$date)
res$ago <- format_time_ago$time_ago(res$date)
class(res) <- c("pak_search_result", class(res))
res
}
Expand Down
File renamed without changes.
8 changes: 0 additions & 8 deletions R/subprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ load_private_cli <- function() {
if (!is.null(pkg_data$ns$cli)) {
return(pkg_data$ns$cli)
}
load_private_package("glue")
old <- Sys.getenv("CLI_NO_THREAD", NA_character_)
Sys.setenv(CLI_NO_THREAD = "1")
on.exit(
Expand All @@ -203,7 +202,6 @@ load_private_cli <- function() {
}

load_private_packages <- function() {
load_private_package("glue")
load_private_cli()
load_private_package("ps")
load_private_package("processx", "c_")
Expand Down Expand Up @@ -293,11 +291,6 @@ load_private_package <- function(package, reg_prefix = "",
)
}

# Hack to avoid S3 dispatch
if (package == "glue") {
pkg_env$as_glue <- pkg_env$as_glue.character
}

## Load shared library
dll_file <- file.path(
pkg_dir, "libs", .Platform$r_arch,
Expand Down Expand Up @@ -392,7 +385,6 @@ set_function_envs <- function(within, new) {
## This is a workaround for R CMD check

r_cmd_check_fix <- function() {
glue::glue
callr::r
cli::rule
filelock::lock
Expand Down
File renamed without changes.
10 changes: 2 additions & 8 deletions src/library/prettyunits/R/time.R → R/time.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

format_time <- local({

assert_diff_time <- function(x) {
stopifnot(inherits(x, "difftime"))
}
Expand All @@ -18,10 +16,9 @@ format_time <- local({

first_positive <- function(x) which(x > 0)[1]

trim <- function (x) gsub("^\\s+|\\s+$", "", x)
trim <- function(x) gsub("^\\s+|\\s+$", "", x)

pretty_ms <- function(ms, compact = FALSE) {

stopifnot(is.numeric(ms))

parsed <- t(parse_ms(ms))
Expand All @@ -39,11 +36,9 @@ format_time <- local({
# handle NAs
tmp[is.na(parsed2[idx])] <- NA_character_
tmp

} else {

## Exact for small ones
exact <- paste0(ceiling(ms), "ms")
exact <- paste0(ceiling(ms), "ms")
exact[is.na(ms)] <- NA_character_

## Approximate for others, in seconds
Expand Down Expand Up @@ -72,7 +67,6 @@ format_time <- local({
}

pretty_dt <- function(dt, compact = FALSE) {

assert_diff_time(dt)

units(dt) <- "secs"
Expand Down
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ is_verbose <- function() {
}
}

backtick <- function (x) {
encodeString(x, quote = "`", na.encode = FALSE)
}

format_items <- function (x) {
paste0(glue::glue_collapse(glue::backtick(x), sep = ", ", last = " and "))
paste0(cli::ansi_collapse(backtick(x), sep = ", ", last = " and "))
}

str_trim <- function (x) {
Expand Down
8 changes: 4 additions & 4 deletions R/warn-loaded.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ warn_for_loaded_packages_locked_none <- function(current) {

warn_for_loaded_packages_none_locked <- function(others) {
pcs <- others$users[!duplicated(others$users$pid), , drop = FALSE]
sess <- glue::glue("{pcs$name} ({pcs$pid})")
sess <- sprintf("%s %s", pcs$name, pcs$pid)
apps <- ifelse(
pcs$pid == pcs$app_pid,
"",
glue::glue(" in {pcs$app_name} ({pcs$app_pid})")
sprintf(" in %s (%s)", pcs$app_name, pcs$app_pid)
)
sess <- paste0(sess, apps)
cli::cli_alert_warning(
Expand Down Expand Up @@ -158,11 +158,11 @@ warn_for_loaded_packages_loaded_locked <- function(current, others) {

warn_for_loaded_packages_locked_locked <- function(current, others) {
pcs <- others$users[!duplicated(others$users$pid), , drop = FALSE]
sess <- glue::glue("{pcs$name} ({pcs$pid})")
sess <- sprintf("%s (%s)", pcs$name, pcs$pid)
apps <- ifelse(
pcs$pid == pcs$app_pid,
"",
glue::glue(", in {pcs$app_name} ({pcs$app_pid})")
sprintf(", in %s (%s)", pcs$app_name, pcs$app_pid)
)
sess <- paste0(sess, apps)
if (identical(sort(current$locked), sort(others$locked))) {
Expand Down
14 changes: 1 addition & 13 deletions man/pak-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 8 additions & 11 deletions src/install-embedded.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,21 @@ install_order <- function() {
## TODO: look up the correct order
pkgs <- c(
# no deps
"R6", "cli", "crayon", "curl", "filelock", "glue", "jsonlite",
"lpSolve", "parsedate", "prettyunits", "ps", "rappdirs", "rprojroot",
"zip",
"R6", "cli", "curl", "filelock", "jsonlite", "lpSolve", "ps", "zip",
# ps, R6
"processx",
# processx, R6
"callr",
# cli, R6, rprojroot
# cli, R6
"desc",
# callr, cli, crayon, desc, prettyunits, processx, R6, rprojroot
# callr, cli, desc, processx, R6
"pkgbuild",
# callr, cli, curl, filelock, jsonlite, prettyunis, processx, R6, rappdirs
# callr, cli, curl, filelock, jsonlite, prettyunis, processx, R6
"pkgcache",
# curl, jsonlite, parsedate, prettyunits
# curl, jsonlite
"pkgsearch",
# callr, cli, curl, desc, filelock, glue, jsonlite, lpSolve, pkgbuild,
# pkgcache, prettyunits, processx, ps, R6, rprojroot, zip
# callr, cli, curl, desc, filelock, jsonlite, lpSolve, pkgbuild,
# pkgcache, processx, ps, R6, zip
"pkgdepends"
)

Expand Down Expand Up @@ -202,8 +200,7 @@ install_embedded_main <- function() {

# From load_all()'s ./configure call, do nothing
if (Sys.getenv("DEVTOOLS_LOAD") == "pak") {
# TODO: we could do this here, if we get rid of rappdirs and
# write our on code to determine the user cache directory.
# TODO: we could do this here, now that we don't use rappdirs.
cat("Delayed embedding dependencies in `pkgload::load_all()`.\n")
file.create("DONE")
return(invisible())
Expand Down
Loading
Loading