-
Notifications
You must be signed in to change notification settings - Fork 763
Use pak::local_install_deps() in install()
#2651
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
Open
hadley
wants to merge
3
commits into
main
Choose a base branch
from
pak-local-install-deps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,23 @@ | ||
| #' Install a local development package. | ||
| #' Install a local development package | ||
| #' | ||
| #' Uses `R CMD INSTALL` to install the package. Will also try to install | ||
| #' dependencies of the package from CRAN, if they're not already installed. | ||
| #' | ||
| #' If `quick = TRUE`, installation takes place using the current package | ||
| #' directory. If you have compiled code, this means that artefacts of | ||
| #' compilation will be created in the `src/` directory. If you want to avoid | ||
| #' this, you can use `build = TRUE` to first build a package bundle and then | ||
| #' install it from a temporary directory. This is slower, but keeps the source | ||
| #' directory pristine. | ||
| #' | ||
| #' If the package is loaded, it will be reloaded after installation. This is | ||
| #' not always completely possible, see [reload()] for caveats. | ||
| #' @description | ||
| #' Uses `R CMD INSTALL` to install the package, after installing needed | ||
| #' dependencies with [pak::local_install_deps()]. | ||
| #' | ||
| #' To install a package in a non-default library, use [withr::with_libpaths()]. | ||
| #' | ||
| #' @template devtools | ||
| #' @inheritParams remotes::install_local | ||
| #' @param reload if `TRUE` (the default), will automatically reload the | ||
| #' package after installing. | ||
| #' @param reload if `TRUE` (the default), will automatically attempt reload the | ||
| #' package after installing. Reloading is always completely possible so see | ||
| #' [pkgload::unregister()] for caveats. | ||
| #' @param quick if `TRUE` skips docs, multiple-architectures, | ||
| #' demos, and vignettes, to make installation as fast as possible. | ||
| #' If `quick = TRUE`, installation takes place using the current package | ||
| #' directory. If you have compiled code, this means that artefacts of | ||
| #' compilation will be created in the `src/` directory. If you want to avoid | ||
| #' this, you can use `build = TRUE` to first build a package bundle and then | ||
| #' install it from a temporary directory. This is slower, but keeps the source | ||
| #' directory pristine. | ||
| #' @param build if `TRUE` [pkgbuild::build()]s the package first: | ||
| #' this ensures that the installation is completely clean, and prevents any | ||
| #' binary artefacts (like \file{.o}, `.so`) from appearing in your local | ||
|
|
@@ -43,118 +40,124 @@ | |
| #' @param keep_source If `TRUE` will keep the srcrefs from an installed | ||
| #' package. This is useful for debugging (especially inside of RStudio). | ||
| #' It defaults to the option `"keep.source.pkgs"`. | ||
| #' @param ... additional arguments passed to [remotes::install_deps()] | ||
| #' when installing dependencies. | ||
| #' @param quiet If `TRUE`, suppress output. | ||
| #' @param force `r lifecycle::badge("deprecated")` No longer used. | ||
| #' @family package installation | ||
| #' @seealso [update_packages()] to update installed packages from the | ||
| #' source location and [with_debug()] to install packages with | ||
| #' debugging flags set. | ||
| #' @inheritParams pak::local_install_deps | ||
| #' @seealso [with_debug()] to install packages with debugging flags set. | ||
| #' @export | ||
| install <- | ||
| function( | ||
| pkg = ".", | ||
| reload = TRUE, | ||
| quick = FALSE, | ||
| build = !quick, | ||
| args = getOption("devtools.install.args"), | ||
| quiet = FALSE, | ||
| dependencies = NA, | ||
| upgrade = "default", | ||
| build_vignettes = FALSE, | ||
| keep_source = getOption("keep.source.pkgs"), | ||
| force = FALSE, | ||
| ... | ||
| ) { | ||
| pkg <- as.package(pkg) | ||
|
|
||
| # Forcing all of the promises for the current namespace now will avoid lazy-load | ||
| # errors when the new package is installed overtop the old one. | ||
| # https://stat.ethz.ch/pipermail/r-devel/2015-December/072150.html | ||
| if (reload && is_loaded(pkg)) { | ||
| eapply(pkgload::ns_env(pkg$package), force, all.names = TRUE) | ||
| } | ||
| install <- function( | ||
| pkg = ".", | ||
| reload = TRUE, | ||
| quick = FALSE, | ||
| build = !quick, | ||
| args = getOption("devtools.install.args"), | ||
| quiet = FALSE, | ||
| dependencies = NA, | ||
| upgrade = FALSE, | ||
| build_vignettes = FALSE, | ||
| keep_source = getOption("keep.source.pkgs"), | ||
| force = deprecated() | ||
| ) { | ||
| if (!is.logical(upgrade) || length(upgrade) != 1) { | ||
| cli::cli_abort("{.arg upgrade} must be a single TRUE, FALSE, or NA") | ||
| } | ||
| if (lifecycle::is_present(force)) { | ||
| lifecycle::deprecate_warn("2.5.0", "intall(force)") | ||
| } | ||
|
|
||
| pkg <- as.package(pkg) | ||
|
|
||
| # Forcing all of the promises for the current namespace now will avoid lazy-load | ||
| # errors when the new package is installed overtop the old one. | ||
| # https://stat.ethz.ch/pipermail/r-devel/2015-December/072150.html | ||
| if (reload && is_loaded(pkg)) { | ||
| eapply(pkgload::ns_env(pkg$package), base::force, all.names = TRUE) | ||
| } | ||
|
|
||
| if (isTRUE(build_vignettes)) { | ||
| # we likely need all Suggested dependencies if building vignettes | ||
| dependencies <- TRUE | ||
| build_opts <- c("--no-resave-data", "--no-manual") | ||
| # Install dependencies | ||
| local({ | ||
| if (quiet) { | ||
| withr::local_output_sink(withr::local_tempfile()) | ||
| withr::local_message_sink(withr::local_tempfile()) | ||
| } else { | ||
| build_opts <- c("--no-resave-data", "--no-manual", "--no-build-vignettes") | ||
| cli::cat_rule("Installing dependencies", col = "cyan") | ||
| } | ||
|
|
||
| opts <- c( | ||
| if (keep_source) "--with-keep.source", | ||
| "--install-tests" | ||
| pak::local_install_deps( | ||
| pkg$path, | ||
| upgrade = upgrade, | ||
| dependencies = dependencies || isTRUE(build_vignettes) | ||
| ) | ||
| if (quick) { | ||
| opts <- c(opts, "--no-docs", "--no-multiarch", "--no-demo") | ||
| } | ||
| opts <- c(opts, args) | ||
| }) | ||
|
|
||
| check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn)) | ||
| if (isTRUE(build_vignettes)) { | ||
| build_opts <- c("--no-resave-data", "--no-manual") | ||
| } else { | ||
| build_opts <- c("--no-resave-data", "--no-manual", "--no-build-vignettes") | ||
| } | ||
| opts <- c( | ||
| if (keep_source) "--with-keep.source", | ||
| "--install-tests" | ||
| ) | ||
| if (quick) { | ||
| opts <- c(opts, "--no-docs", "--no-multiarch", "--no-demo") | ||
| } | ||
| opts <- c(opts, args) | ||
|
|
||
| remotes::install_deps( | ||
| if (build) { | ||
| install_path <- pkgbuild::build( | ||
| pkg$path, | ||
| build = build, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit hard to see in the diff, but we're no longer passing any build or install options when we install the dependencies. I think this is likely to be fine, since you'd generally except these to coming from CRAN and not built locally. |
||
| build_opts = build_opts, | ||
| INSTALL_opts = opts, | ||
| dependencies = dependencies, | ||
| quiet = quiet, | ||
| force = force, | ||
| upgrade = upgrade, | ||
| ... | ||
| dest_path = tempdir(), | ||
| args = build_opts, | ||
| quiet = quiet | ||
| ) | ||
| on.exit(file_delete(install_path), add = TRUE) | ||
| } else { | ||
| install_path <- pkg$path | ||
| } | ||
|
|
||
| if (build) { | ||
| install_path <- pkgbuild::build( | ||
| pkg$path, | ||
| dest_path = tempdir(), | ||
| args = build_opts, | ||
| quiet = quiet | ||
| ) | ||
| on.exit(file_delete(install_path), add = TRUE) | ||
| } else { | ||
| install_path <- pkg$path | ||
| } | ||
|
|
||
| was_loaded <- is_loaded(pkg) | ||
| was_attached <- is_attached(pkg) | ||
| was_loaded <- is_loaded(pkg) | ||
| was_attached <- is_attached(pkg) | ||
|
|
||
| if (reload && was_loaded) { | ||
| pkgload::unregister(pkg$package) | ||
| } | ||
| if (reload && was_loaded) { | ||
| pkgload::unregister(pkg$package) | ||
| } | ||
|
|
||
| pkgbuild::with_build_tools( | ||
| required = FALSE, | ||
| callr::rcmd( | ||
| "INSTALL", | ||
| c(install_path, opts), | ||
| echo = !quiet, | ||
| show = !quiet, | ||
| spinner = FALSE, | ||
| stderr = "2>&1", | ||
| fail_on_status = TRUE | ||
| ) | ||
| if (!quiet) { | ||
| cli::cat_rule(paste0("R CMD INSTALL"), col = "cyan") | ||
| } | ||
| pkgbuild::with_build_tools( | ||
| required = FALSE, | ||
| callr::rcmd( | ||
| "INSTALL", | ||
| c(install_path, opts), | ||
| echo = !quiet, | ||
| show = !quiet, | ||
| spinner = FALSE, | ||
| stderr = "2>&1", | ||
| fail_on_status = TRUE | ||
| ) | ||
| ) | ||
|
|
||
| if (reload && was_loaded) { | ||
| if (was_attached) { | ||
| require(pkg$package, quietly = TRUE, character.only = TRUE) | ||
| } else { | ||
| requireNamespace(pkg$package, quietly = TRUE) | ||
| } | ||
| if (reload && was_loaded) { | ||
| if (was_attached) { | ||
| require(pkg$package, quietly = TRUE, character.only = TRUE) | ||
| } else { | ||
| requireNamespace(pkg$package, quietly = TRUE) | ||
| } | ||
|
|
||
| invisible(TRUE) | ||
| } | ||
|
|
||
| invisible(TRUE) | ||
| } | ||
|
|
||
| #' Install package dependencies if needed. | ||
| #' | ||
| #' `install_deps()` will install the | ||
| #' user dependencies needed to run the package, `install_dev_deps()` will also | ||
| #' install the development dependencies needed to test and build the package. | ||
| #' @inheritParams install | ||
| #' @inherit remotes::install_deps | ||
| #' @inheritParams install | ||
| #' @param ... Additional arguments passed to [remotes::install_deps()]. | ||
| #' @export | ||
| install_deps <- function( | ||
| pkg = ".", | ||
|
|
@@ -221,5 +224,5 @@ local_install <- function(pkg = ".", quiet = TRUE, env = parent.frame()) { | |
|
|
||
| cli::cli_inform(c(i = "Installing {.pkg {pkg$package}} in temporary library")) | ||
| withr::local_temp_libpaths(.local_envir = env) | ||
| install(pkg, upgrade = "never", reload = FALSE, quick = TRUE, quiet = quiet) | ||
| install(pkg, upgrade = FALSE, reload = FALSE, quick = TRUE, quiet = quiet) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,7 @@ miniUI | |
| mnel | ||
| nchar | ||
| objs | ||
| pak | ||
| pandoc | ||
| param | ||
| params | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hack around lack of
quietargument or option for pak.