r-lib / pak

Compare 15b0b2e ... +5 ... 05dba98

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -212,98 +212,6 @@
Loading
212 212
  pkg_deps_explain(ref, deps, upgrade, dependencies)
213 213
}
214 214
215 -
#' Create a lock file for the dependencies of a package tree
216 -
#'
217 -
#' The lock file can be used later, possibly in a new R session, to carry
218 -
#' out the installation of the dependencies, with
219 -
#' [local_install_lockfile()].
220 -
#'
221 -
#' Note, since the URLs of CRAN and most CRAN-like repositories change
222 -
#' over time, in practice you cannot use the lock file _much_ later.
223 -
#' For example, binary packages of older package version
224 -
#' might be deleted from the repository, breaking the URLs in the
225 -
#' lock file.
226 -
#'
227 -
#' Currently the intended use case of lock files in on CI systems, to
228 -
#' facilitate caching. The (hash of the) lock file provides a good key
229 -
#' for caching systems.
230 -
#'
231 -
#' @param lockfile Path to the lock file.
232 -
#' @param lib Library to base the lock file on. In most cases (e.g. on a
233 -
#'   CI system, or at deployment), this is an empty library. Supply
234 -
#'   `tempfile()` to make sure the lock file is based on an empty library.
235 -
#' @inheritParams local_install
236 -
#' @family lock files
237 -
#' @export
238 -
239 -
local_create_lockfile <- function(root = ".", lockfile = "pkg.lock",
240 -
                                  lib = .libPaths()[1], upgrade = TRUE,
241 -
                                  dependencies = TRUE) {
242 -
  ret <- remote(
243 -
    function(...) {
244 -
      get("local_create_lockfile_internal", asNamespace("pak"))(...)
245 -
    },
246 -
    list(root = root, lockfile = lockfile, lib = lib, upgrade = upgrade,
247 -
         dependencies = dependencies)
248 -
  )
249 -
250 -
  invisible(ret)
251 -
}
252 -
253 -
local_create_lockfile_internal <- function(root, lockfile, lib, upgrade,
254 -
                                           dependencies) {
255 -
  root <- rprojroot::find_package_root_file(path = root)
256 -
  prop <- pkgdepends::new_pkg_installation_proposal(
257 -
    paste0("deps::", root),
258 -
    config = list(library = lib, dependencies = dependencies)
259 -
  )
260 -
  prop$set_solve_policy(if (upgrade) "upgrade" else "lazy")
261 -
  prop$solve()
262 -
  prop$stop_for_solution_error()
263 -
  prop$create_lockfile(lockfile)
264 -
  invisible()
265 -
}
266 -
267 -
#' Install packages based on a lock file
268 -
#'
269 -
#' Install a lock file that was created with [local_create_lockfile()].
270 -
#'
271 -
#' @param lockfile Path to the lock file.
272 -
#' @param lib Library to carry out the installation on.
273 -
#' @family lock files
274 -
#' @export
275 -
276 -
local_install_lockfile <- function(lockfile = "pkg.lock",
277 -
                                   lib = .libPaths()[1]) {
278 -
279 -
  start <- Sys.time()
280 -
  ret <- remote(
281 -
    function(...) {
282 -
      get("local_install_lockfile_internal", asNamespace("pak"))(...)
283 -
    },
284 -
    list(lockfile = lockfile, lib = lib, start = start)
285 -
  )
286 -
287 -
  invisible(ret)
288 -
}
289 -
290 -
local_install_lockfile_internal <- function(lockfile, lib, start) {
291 -
  config <- list(library = lib)
292 -
  plan <- pkgdepends::new_pkg_installation_plan(lockfile, config = config)
293 -
  plan$download()
294 -
  inst <- plan$install()
295 -
  attr(inst, "total_time") <- Sys.time() - start
296 -
  class(inst) <- c("pkg_install_result", class(inst))
297 -
298 -
  ## Remove some largeish columns that we don't really need any more
299 -
  inst$extra <- NULL
300 -
301 -
  ## One line summary of the install
302 -
  print_install_summary(inst)
303 -
304 -
  inst
305 -
}
306 -
307 215
## ----------------------------------------------------------------------
308 216
309 217
## Almost the same as a "regular" install, but need to set dependencies

@@ -0,0 +1,114 @@
Loading
1 +
2 +
#' Create a lock file
3 +
#'
4 +
#' The lock file can be used later, possibly in a new R session, to carry
5 +
#' out the installation of the dependencies, with
6 +
#' [lockfile_install()].
7 +
#'
8 +
#' Note, since the URLs of CRAN and most CRAN-like repositories change
9 +
#' over time, in practice you cannot use the lock file _much_ later.
10 +
#' For example, binary packages of older package version
11 +
#' might be deleted from the repository, breaking the URLs in the
12 +
#' lock file.
13 +
#'
14 +
#' Currently the intended use case of lock files in on CI systems, to
15 +
#' facilitate caching. The (hash of the) lock file provides a good key
16 +
#' for caching systems.
17 +
#'
18 +
#' @param lockfile Path to the lock file.
19 +
#' @inheritParams pkg_install
20 +
#'
21 +
#' @family lock files
22 +
#' @export
23 +
24 +
lockfile_create <- function(pkg = "deps::.", lockfile = "pkg.lock", lib = NULL,
25 +
                            upgrade = FALSE, dependencies = NA) {
26 +
  ret <- remote(
27 +
    function(...) {
28 +
      get("lockfile_create_internal", asNamespace("pak"))(...)
29 +
    },
30 +
    list(pkg = pkg, lockfile = lockfile, lib = lib, upgrade = upgrade,
31 +
         dependencies = dependencies)
32 +
  )
33 +
34 +
  invisible(ret)
35 +
}
36 +
37 +
lockfile_create_internal <- function(pkg, lockfile, lib, upgrade,
38 +
                                     dependencies) {
39 +
  if (is.null(lib)) {
40 +
    lib <- tempfile()
41 +
    mkdirp(lib)
42 +
    on.exit(unlink(lib, recursive = TRUE), add = TRUE)
43 +
  }
44 +
45 +
  cli::cli_progress_step(
46 +
    "Creating lockfile {.path {lockfile}}",
47 +
    msg_done = "Created lockfile {.path {lockfile}}"
48 +
  )
49 +
50 +
  prop <- pkgdepends::new_pkg_installation_proposal(
51 +
    pkg,
52 +
    config = list(library = lib, dependencies = dependencies)
53 +
  )
54 +
  prop$set_solve_policy(if (upgrade) "upgrade" else "lazy")
55 +
  prop$solve()
56 +
  prop$stop_for_solution_error()
57 +
  prop$create_lockfile(lockfile)
58 +
  invisible()
59 +
}
60 +
61 +
#' Install packages based on a lock file
62 +
#'
63 +
#' Install a lock file that was created with [lockfile_create()].
64 +
#'
65 +
#' @param lockfile Path to the lock file.
66 +
#' @param lib Library to carry out the installation on.
67 +
#' @param update Whether to online install the packages that
68 +
#'   either not installed in `lib`, or a different version is installed
69 +
#'   for them.
70 +
#'
71 +
#' @family lock files
72 +
#' @export
73 +
74 +
lockfile_install <- function(lockfile = "pkg.lock",
75 +
                             lib = .libPaths()[1], update = TRUE) {
76 +
77 +
  start <- Sys.time()
78 +
  mkdirp(lib)
79 +
  ret <- remote(
80 +
    function(...) {
81 +
      get("lockfile_install_internal", asNamespace("pak"))(...)
82 +
    },
83 +
    list(lockfile = lockfile, lib = lib, update = update, start = start,
84 +
         loaded = loaded_packages(lib))
85 +
  )
86 +
87 +
  invisible(ret)
88 +
}
89 +
90 +
lockfile_install_internal <- function(lockfile, lib, update, loaded, start) {
91 +
  cli::cli_progress_step(
92 +
     "Intalling lockfile {.path {lockfile}}",
93 +
     msg_done = "Installed lockfile {.path {lockfile}}",
94 +
  )
95 +
96 +
  config <- list(library = lib)
97 +
  plan <- pkgdepends::new_pkg_installation_plan(lockfile, config = config)
98 +
  if (update) plan$update()
99 +
100 +
  print_install_details(plan, lib, loaded)
101 +
102 +
  plan$download()
103 +
  inst <- plan$install()
104 +
  attr(inst, "total_time") <- Sys.time() - start
105 +
  class(inst) <- c("pkg_install_result", class(inst))
106 +
107 +
  ## Remove some largeish columns that we don't really need any more
108 +
  inst$extra <- NULL
109 +
110 +
  ## One line summary of the install
111 +
  print_install_summary(inst)
112 +
113 +
  inst
114 +
}

@@ -41,7 +41,8 @@
Loading
41 41
}
42 42
43 43
show_extra <- function() {
44 -
  !isTRUE(getOption("pak.no_extra_messages", FALSE))
44 +
  Sys.getenv("CI") != "true" &&
45 +
    !isTRUE(getOption("pak.no_extra_messages", FALSE))
45 46
}
46 47
47 48
hash <- function(obj) {

@@ -41,26 +41,48 @@
Loading
41 41
}
42 42
43 43
print_install_summary <- function(x) {
44 -
  direct <- sum(x$direct)
44 +
  direct <- sum(x$direct & x$type != "deps")
45 45
  deps <- sum(! x$direct)
46 46
47 -
  newly <- sum(x$lib_status == "new")
48 -
  upd   <- sum(x$lib_status == "update")
49 -
  curr  <- sum(x$lib_status == "current")
47 +
  newly <- sum(x$lib_status == "new" & x$type != "deps")
48 +
  upd   <- sum(x$lib_status == "update" & ! x$type %in% c("installed", "deps"))
49 +
  curr  <- sum(x$lib_status == "current" & x$type != "deps")
50 +
  # Not used currently. The packages we could have updated but did not
50 51
  noupd <- sum(x$lib_status == "no-update")
51 52
52 53
  downloaded <- sum(x$download_status == "Got")
53 54
  cached <- sum(x$download_status == "Had" &
54 55
                ! x$type %in% c("installed", "deps"))
55 56
  dlbytes <- sum(x$file_size[x$download_status == "Got"])
56 -
  build_time <- sum(unlist(x$build_time), na.rm = TRUE)
57 -
  inst_time <- sum(unlist(x$install_time), na.rm = TRUE)
58 -
  total_time <- prettyunits::pretty_dt(attr(x, "total_time")) %||% "???s"
57 +
  total_time <- prettyunits::pretty_dt(attr(x, "total_time")) %||% ""
59 58
60 -
  if (upd + newly == 0) cli::cli_alert_success("No changes are needed")
61 -
  cli::cli_alert_success(paste0(
62 -
    direct, " + ", deps, " pkgs | ",
63 -
    "kept ", curr, ", updated ", upd, ", new ", newly, " | ",
64 -
    "downloaded ", downloaded, " (", prettyunits::pretty_bytes(dlbytes), ")",
65 -
    " {.timestamp {total_time}}"))
59 +
  pkgsum <- paste0(
60 +
    if (direct > 0) "{direct} pkg{?s}",
61 +
    if (direct > 0 && deps > 0) " + ",
62 +
    if (deps > 0) "{deps} dep{?s}"
63 +
  )
64 +
  updsum <- paste0(c(
65 +
    if (curr > 0) "kept {curr}",
66 +
    if (upd > 0) "upd {upd}",
67 +
    if (newly > 0) "added {newly}"
68 +
  ), collapse = ", ")
69 +
70 +
  dlsum <- if (downloaded > 0) {
71 +
    bytes <- prettyunits::pretty_bytes(dlbytes)
72 +
    paste0(
73 +
      ", dld {downloaded}",
74 +
      if (!is.na(bytes) && bytes != 0) " ({bytes})"
75 +
    )
76 +
  } else {
77 +
    ""
78 +
  }
79 +
  ts <- if (nzchar(total_time)) " {.timestamp {total_time}}" else ""
80 +
81 +
  cli::cli_alert_success(c(
82 +
    pkgsum,
83 +
    ": ",
84 +
    updsum,
85 +
    dlsum,
86 +
    ts
87 +
  ))
66 88
}

@@ -1,7 +1,7 @@
Loading
1 1
2 2
#' Check if an R package name is available
3 3
#'
4 -
#' @inherit pkgdepends::pkg_name_check
4 +
#' @inherit pkgdepends::pkg_name_check description details return
5 5
#'
6 6
#' @inheritParams pkgdepends::pkg_name_check
7 7
#'

Learn more Showing 1 files with coverage changes found.

New file R/lockfile.R
New
Loading file...
Files Coverage
R +1.65% 17.44%
Project Totals (28 files) 17.44%
Loading