diff --git a/R/cache.R b/R/cache.R index e08be5a90..1b36c7b12 100644 --- a/R/cache.R +++ b/R/cache.R @@ -1,43 +1,13 @@ -#' Check if the R cache is persistent -#' @keywords internal -has_persistent_R.cache <- function() { - temp_dirs <- path_if_exist( - fs::path_norm(fs::path_dir(tempdir())), - "/tmp", "/var/tmp" - ) - !fs::path_has_parent( - fs::path_norm(R.cache::getCacheRootPath()), # when no cache exists, it create temp cache - temp_dirs - ) %>% - any() -} - #' Issue a warning if `{R.cache}` uses temporary cache only #' -#' This function is only exported for use in hook scripts, but it's not intended -#' to be called by the end-user directly. -#' @param temp_cache_is_enough Whether a temporary cache is accepted or not. `TRUE` -#' means no warning will be issued, `FALSE` means a warning will be issued if -#' no permanent cache is available. +#' This function used to check if a permanent cache was available and issue a +#' warning if not, but since {R.cache} version `0.15.0` (release date +#' 2021-04-27), a permanent directory will be used automatically, so this check +#' if redundant. the function is kept in the package for compatibility, i.e. +#' if someone updates the R package {precommit} but not the hook revisions. +#' @param temp_cache_is_enough ignored. #' @family hook script helpers #' @export may_require_permanent_cache <- function(temp_cache_is_enough = FALSE) { - if (has_persistent_R.cache()) { - cat("Using persistent cache at", R.cache::getCacheRootPath(), "\n") - } else { - if (temp_cache_is_enough) { - cat("Using temporary cache at", R.cache::getCacheRootPath(), "\n") - } else { - cat(paste0( - "You don't have a permanent cache directory set up with {R.cache}. ", - "This means you won't get significant speedups for some hooks. ", - "Create a permanent cache in an interactive R session by \n\n1) calling ", - "`R.cache::getCachePath()` and confirm the prompt or \n\n2) ", - "non-interactively by setting the environment variable ", - "`R_CACHE_ROOTPATH` to the location you want to put the cache. \n\nYou can ", - "silent this warning with setting `args: [--no-warn-cache]` in your ", - ".pre-commit-config.yaml.\n\n" - )) - } - } + return() } diff --git a/man/has_persistent_R.cache.Rd b/man/has_persistent_R.cache.Rd deleted file mode 100644 index 3c62f1b5b..000000000 --- a/man/has_persistent_R.cache.Rd +++ /dev/null @@ -1,12 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cache.R -\name{has_persistent_R.cache} -\alias{has_persistent_R.cache} -\title{Check if the R cache is persistent} -\usage{ -has_persistent_R.cache() -} -\description{ -Check if the R cache is persistent -} -\keyword{internal} diff --git a/man/may_require_permanent_cache.Rd b/man/may_require_permanent_cache.Rd index 189bb7995..a79aac4c2 100644 --- a/man/may_require_permanent_cache.Rd +++ b/man/may_require_permanent_cache.Rd @@ -7,13 +7,14 @@ may_require_permanent_cache(temp_cache_is_enough = FALSE) } \arguments{ -\item{temp_cache_is_enough}{Whether a temporary cache is accepted or not. \code{TRUE} -means no warning will be issued, \code{FALSE} means a warning will be issued if -no permanent cache is available.} +\item{temp_cache_is_enough}{ignored.} } \description{ -This function is only exported for use in hook scripts, but it's not intended -to be called by the end-user directly. +This function used to check if a permanent cache was available and issue a +warning if not, but since {R.cache} version \verb{0.15.0} (release date +2021-04-27), a permanent directory will be used automatically, so this check +if redundant. the function is kept in the package for compatibility, i.e. +if someone updates the R package {precommit} but not the hook revisions. } \seealso{ Other hook script helpers: diff --git a/tests/testthat/test-cache.R b/tests/testthat/test-cache.R deleted file mode 100644 index ca0d193bd..000000000 --- a/tests/testthat/test-cache.R +++ /dev/null @@ -1,75 +0,0 @@ -test_that("R api works", { - withr::with_options( - list(R.cache.rootPath = fs::file_temp(".Rcache")), - { - expect_false(has_persistent_R.cache()) - } - ) - withr::with_options( - list(R.cache.rootPath = fs::file_temp(".Rcache")), - { - expect_output(may_require_permanent_cache(), "This means you") - } - ) - - withr::with_options( - list(R.cache.rootPath = fs::file_temp(".Rcache")), - { - expect_output( - may_require_permanent_cache(temp_cache_is_enough = TRUE), - "Using temporary cache at" - ) - } - ) -}) - -test_that("CLI API works for style-files", { - skip_if(is_windows(), "env not supported in system2 on Windows") - R.cache_root <- fs::path_abs(fs::file_temp("R.cacheTemp")) - fs::dir_create(R.cache_root) - run_test( - "style-files", - suffix = "-cache-success.R", - env = paste0("R_CACHE_ROOTPATH=", R.cache_root), - msg = "You can silent this" - ) - R.cache_root <- fs::path_abs(fs::dir_create("R.cachePerm")) - fs::dir_create(R.cache_root) - withr::defer(fs::dir_delete(R.cache_root)) - run_test( - "style-files", - suffix = "-cache-success.R", - env = paste0("R_CACHE_ROOTPATH=", R.cache_root), - msg = "Using persistent" - ) -}) - -test_that("CLI API works for roxygenize", { - skip_if(is_windows(), "env not supported in system2 on Windows") - R.cache_root <- fs::path_abs(fs::file_temp("R.cacheTemp")) - fs::dir_create(R.cache_root) - run_test( - "roxygenize", - suffix = "-cache-success.R", - env = paste0("R_CACHE_ROOTPATH=", R.cache_root), - msg = "You can silent this", - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf")), - file_transformer = function(x) { - git_init() - x - } - ) - R.cache_root <- fs::path_abs(fs::dir_create("R.cachePerm")) - fs::dir_create(R.cache_root) - withr::defer(fs::dir_delete(R.cache_root)) - run_test( - "roxygenize", - suffix = "-cache-success.R", - env = paste0("R_CACHE_ROOTPATH=", R.cache_root), - msg = "Using persistent", - file_transformer = function(x) { - git_init() - x - } - ) -}) diff --git a/vignettes/available-hooks.Rmd b/vignettes/available-hooks.Rmd index 074b0b6c9..e2d6a0594 100644 --- a/vignettes/available-hooks.Rmd +++ b/vignettes/available-hooks.Rmd @@ -83,13 +83,7 @@ In addition, the hook takes the following arguments that are not passed to args: [--style_pkg=pkg.with.style.guide, --style_fun=exported.style.function] ``` -* If no permanent `{R.cache}` cache exists, the hook emits a warning which you - can silence with `--no-warn-cache`. - -``` - id: style-files - args: [--no-warn-cache] -``` +* The argument `--no-warn-cache` is ignored but allowed for compatibility. * Argument `cache-root` is passed to `options()` to set `styler.cache_root`. @@ -177,13 +171,8 @@ should pass. A hook to run `roxygen2::roxygenize()`. Makes sure you commit your `.Rd` changes with the source changes. To take advantage of caching, you don't need to run -`roxygen2::roxygenize()` manually anymore. If no permanent `{R.cache}` cache -exists, the hook emits a warning which you can silence with -`--no-warn-cache`. -``` - id: royxgenize - args: [--no-warn-cache] -``` +`roxygen2::roxygenize()` manually anymore. The option `--no-warn-cache` is +ignored but allowed for compatibility. Because the hook will write the version of {roxygen2} to `DESCRIPTON`, you should either make sure the version you use when you call {roxygen2}