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

provide exported functions for interacting with lockfiles #1438

Merged
merged 6 commits into from
Jun 13, 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
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export(init)
export(install)
export(isolate)
export(load)
export(lockfile_create)
export(lockfile_modify)
export(lockfile_read)
export(lockfile_write)
export(migrate)
export(modify)
export(paths)
Expand Down
150 changes: 0 additions & 150 deletions R/lockfile-api.R

This file was deleted.

83 changes: 81 additions & 2 deletions R/lockfiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,86 @@
#' Note that the `Name` field may be empty. In that case, a project-local Python
#' environment will be used instead (when not directly using a system copy of Python).
#'
#' # Caveats
#'
#' These functions are primarily intended for expert users -- in most cases,
#' [snapshot()] and [restore()] are the primariy tools you will need when
#' creating and using lockfiles.
#'
#' @inheritParams snapshot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest adding a "for expert use only" caution somewhere.

#' @inheritParams renv-params
#'
#' @param lockfile An `renv` lockfile; typically created by either
#' `lockfile_create()` or `lockfile_read()`.
#'
#' @param file A file path, or \R connection.
#'
#' @family reproducibility
#' @name lockfiles
#' @rdname lockfiles
#' @name lockfile
#' @rdname lockfile
NULL

#' @param libpaths The library paths to be used when generating the lockfile.
#' @rdname lockfile
#' @export
lockfile_create <- function(type = settings$snapshot.type(project = project),
libpaths = .libPaths(),
packages = NULL,
exclude = NULL,
...,
project = NULL)
{
project <- renv_project_resolve(project)

renv_lockfile_create(
project = project,
libpaths = libpaths,
type = type,
packages = packages,
exclude = exclude
)
}

#' @rdname lockfile
#' @export
lockfile_read <- function(file = NULL, ..., project = NULL) {
project <- renv_project_resolve(project)
file <- file %||% renv_paths_lockfile(project = project)
renv_lockfile_read(file = file)
}

#' @rdname lockfile
#' @export
lockfile_write <- function(lockfile, file = NULL, ..., project = NULL) {
project <- renv_project_resolve(project)
file <- file %||% renv_paths_lockfile(project = project)
renv_lockfile_write(lockfile, file = file)
}

#' @param remotes A named \R list, mapping package names to the remote
#' specifications to be recorded in the lockfile.
#'
#' @param repos A named vector, mapping \R repository names to their URLs.
#'
#' @rdname lockfile
#' @export
lockfile_modify <- function(lockfile,
...,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used internally, but I thought this might be useful for end users (e.g. a way to explicitly set the repositories in a lockfile)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I meant the ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry. That's there intentionally so we can:

  1. Force some arguments to be named,
  2. Add new arguments (in any order) in a backwards compatible way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(but maybe I should add renv_dots_check() to warn about unused arguments)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think if you use ... for this purpose, you need to error if there's anything in them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok; I made that change on main.

remotes = NULL,
repos = NULL)
{
if (!is.null(repos)) {
lockfile$R$Repositories <- as.list(repos)
}

if (!is.null(remotes)) {
remotes <- renv_records_resolve(remotes)
enumerate(remotes, function(package, remote) {
record <- renv_remotes_resolve(remote)
renv_lockfile_records(lockfile)[[package]] <<- record
})
}

lockfile

}
2 changes: 1 addition & 1 deletion R/paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ renv_paths_root_default_tempdir <- function() {
#' \code{RENV_PATHS_LIBRARY_ROOT} \tab The parent path for project libraries. \cr
#' \code{RENV_PATHS_LIBRARY_STAGING} \tab The parent path used for staged package installs. \cr
#' \code{RENV_PATHS_SANDBOX} \tab The path to the sandboxed \R system library. \cr
#' \code{RENV_PATHS_LOCKFILE} \tab The path to the [lockfile][lockfiles]. \cr
#' \code{RENV_PATHS_LOCKFILE} \tab The path to the [lockfile]. \cr
#' \code{RENV_PATHS_CELLAR} \tab The path to the cellar, containing local package binaries and sources. \cr
#' \code{RENV_PATHS_SOURCE} \tab The path containing downloaded package sources. \cr
#' \code{RENV_PATHS_BINARY} \tab The path containing downloaded package binaries. \cr
Expand Down
1 change: 0 additions & 1 deletion R/r.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ r_exec_error <- function(package, output, label, extra) {
message = sprintf("%s of package '%s' failed [%s]", label, package, extra),
detail = all
)
stop(error)

}

Expand Down
1 change: 0 additions & 1 deletion R/repair.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ repair <- function(library = NULL,
renv_repair_records <- function(packages, lockfile, project) {

lockfile <- lockfile %||% renv_paths_lockfile(project = project)
lockfile <- renv_lockfile_resolve(lockfile)
if (is.null(lockfile))
return(packages)

Expand Down
1 change: 0 additions & 1 deletion R/restore.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ restore <- function(project = NULL,
# resolve library, lockfile arguments
libpaths <- renv_libpaths_resolve(library)
lockfile <- lockfile %||% renv_lockfile_load(project = project)
lockfile <- renv_lockfile_resolve(lockfile)

# activate the requested library (place at front of library paths)
library <- nth(libpaths, 1L)
Expand Down
2 changes: 1 addition & 1 deletion R/scaffold.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' - Create `.Rbuildignore`, if the project is also a package. This tells
#' `R CMD build` to ignore the renv infrastructure,
#'
#' - Write a (bare) [lockfile][lockfiles], `renv.lock`.
#' - Write a (bare) [lockfile], `renv.lock`.
#'
#' @inheritParams renv-params
#'
Expand Down
6 changes: 3 additions & 3 deletions R/snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#' Record current state of the project library in the lockfile
#'
#' @description
#' Call `renv::snapshot()` to update a [lockfile][lockfiles] with the current
#' state of dependencies in the project library. The lockfile can be used to
#' later [restore] these dependencies as required.
#' Call `renv::snapshot()` to update a [lockfile] with the current state of
#' dependencies in the project library. The lockfile can be used to later
#' [restore] these dependencies as required.
#'
#' It's also possible to call `renv::snapshot()` with a non-renv project,
#' in which case it will record the current state of dependencies in the
Expand Down
2 changes: 1 addition & 1 deletion inst/resources/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ local({
on.exit(do.call(base::options, saved), add = TRUE)
}

catf("* Downloading from GitHub ... ", appendLF = FALSE)
catf("* Downloading version %s from GitHub ... ", version, appendLF = FALSE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious diff?


url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version)
name <- sprintf("renv_%s.tar.gz", version)
Expand Down
Loading