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

Release 1.6.2 #842

Merged
merged 12 commits into from
Sep 25, 2021
32 changes: 28 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ repos:
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
exclude: 'tests/testthat/.*/.*\.R'
exclude: >
(?x)^(
tests/testthat/.*/.*\.R(md)?|
vignettes/customizing_styler\.Rmd|
tests/testthat/public-api/xyzfile-rnw/random4\.Rnw|
)$
- id: roxygenize
- id: use-tidy-description
- id: spell-check
exclude: >
(?x)^(
data/.*|
\.github/.*\.yaml|
data/.*|
tests/testthat/.*|
touchstone/config\.json|
(.*/|)\.Rprofile|
(.*/|)\.Renviron|
Expand All @@ -38,13 +44,31 @@ repos:
)$
- id: readme-rmd-rendered
- id: parsable-R
exclude: >
(?x)^(
tests/testthat/public-api/xyzaddin/addin_region-.*|
tests/testmanual/addins/r-invalid\.R|
tests/testthat/escaping/basic-escape-out\.R|
tests/testthat/indention_operators/base_pipe_and_assignment-.*|
tests/testthat/exception_handling/parser-error.R|
)$
- id: no-browser-statement
exclude: >
(?x)^(
tests/testthat/public-api/xyzaddin/addin_region-.*|
tests/testmanual/addins/r-invalid\.R|
tests/testthat/escaping/basic-escape-out\.R|
tests/testthat/indention_operators/base_pipe_and_assignment-.*|
tests/testthat/exception_handling/parser-error.R|
)$
- id: deps-in-desc
exclude: >
(?x)^(
touchstone/.*|
tests/testthat/.*-in\.R(md)?|
tests/testthat/.*-out\.R(md)?
tests/testmanual/addins/r-invalid\.R|
tests/testthat/escaping/basic-escape-out\.R|
tests/testthat/rnw/011-conditional-eval-out\.Rnw|
tests/testthat/.*\.R(md)?
)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: styler
Title: Non-Invasive Pretty Printing of R Code
Version: 1.6.1.9000
Version: 1.6.2
Authors@R:
c(person(given = "Kirill",
family = "Müller",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# styler 1.2

* clean up cache files older than one week (#842).

# styler 1.6.1

* Files with `.Rmarkdown` extension are now recognized as an R markdown files in
Expand Down
2 changes: 1 addition & 1 deletion R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ drop_cached_children <- function(pd) {
#' @details
#' Note that top-level comments **above** code have negative parents
#' (the negative value of the parent of the code expression that follows after,
#' a nother comment might be in the way though), all comments that are not top
#' another comment might be in the way though), all comments that are not top
#' level have positive ids. All comments for which no code follows afterwards
#' have parent 0.
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/utils-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ cache_dir_default <- function() {

#' Create more specs
#'
#' Syntactic suggar for creating more specs. This is useful when we want to add
#' Syntactic sugar for creating more specs. This is useful when we want to add
#' more arguments (because we can search for this function in the source code).
#' @keywords internal
cache_more_specs <- function(include_roxygen_examples, base_indention) {
Expand Down
63 changes: 20 additions & 43 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,31 @@
styler.ignore_start = "# styler: off",
styler.ignore_stop = "# styler: on",
styler.quiet = FALSE,
styler.test_dir_writable = TRUE,
styler.interactive_ask_remove_old_caches = TRUE
styler.test_dir_writable = TRUE
)
toset <- !(names(op.styler) %in% names(op))
if (any(toset)) options(op.styler[toset])
remind_removing_old_cache()
remove_cache_old_versions()
remove_old_cache_files()
invisible()
}

#' Ask people to remove the cache
#'
#' The way RStudio Startup works does not allow o read the prompt for some
#' reasons (https://stackoverflow.com/questions/55772436/readline-does-not-prompt-user-input-from-rprofile-site-in-rstudio)
#' So we better don't use the prompt and issue a message only.
#' @keywords internal
remind_removing_old_cache <- function() {
if (interactive() && getOption("styler.interactive_ask_remove_old_caches", TRUE)) {
dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE)
if (length(dirs) < 1) {
return()
}
dirs <- dirs[unname(sapply(dirs, function(x) length(list.files(x)) > 0))]
package_versions <- package_version(basename(dirs), strict = FALSE)
package_versions <- package_versions[!is.na(package_versions)]
old_package_versions <- package_versions[package_versions < styler_version]
if (length(old_package_versions) < 1) {
return()
}
remove_old_cache_files <- function() {
all_cached <- list.files(
R.cache::getCachePath(c("styler", styler_version)),
full.names = TRUE, recursive = TRUE
)
date_boundary <- Sys.time() - 60 * 60 * 24 * 6
file.remove(
all_cached[file.info(all_cached)$mtime < date_boundary]
)
}


cmd <- glue::glue("styler::cache_clear(\"{basename(dirs)}\", ask = FALSE)") %>%
paste0(collapse = "\n")
cli::cli_alert_info(paste0(
"You are using {{styler}} version {styler_version} but we found ",
"caches for older versions of {{styler}}.\n",
"You can delete them with the following commands:"
))
cat("\n")
cli::cli_code(cmd)
cat("\n")
cli::cli_alert_info(
paste(
"We'll remind you every time you update {{styler}}.",
"To suppress this prompt in the future:"
)
)
cat("\n")
cli::cli_code(
'options("styler.interactive_ask_remove_old_caches" = FALSE)'
)
}
remove_cache_old_versions <- function() {
dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE)
old_package_dirs <- dirs[basename(dirs) != as.character(styler_version)]
purrr::walk(old_package_dirs, function(dir) {
unlink(dir, recursive = TRUE, force = TRUE)
})
}
8 changes: 5 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
This is a submission to fix a problem with persistent caching, reported by
Prof Ripley on 07.09.2021, and invalid URLs, based on an email from Uwe Ligges
on 17.09.2021.
This is a re-submission to fix a problem with persistent caching. Note that
all cached files are of size 0 and this is by design to keep the cache small.
Hence, the cache will still have files of size 0, but we remove all files older
than a week and remove all caches for versions of styler other than the one
running as requested.

## Test environments

Expand Down
2 changes: 1 addition & 1 deletion man/cache_more_specs.Rd

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

2 changes: 1 addition & 1 deletion man/find_pos_id_to_keep.Rd

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

14 changes: 0 additions & 14 deletions man/remind_removing_old_cache.Rd

This file was deleted.

3 changes: 1 addition & 2 deletions tests/testmanual/tests
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Addins

* set style:
- test setting a valid stlye
- test setting a valid style
- test setting an invalid style
* style active file:
- saved .R file (valid and invalid code)
Expand All @@ -23,4 +23,3 @@
- unsaved .Rnw file
- saved non-R file
- unsaved R file