diff --git a/NAMESPACE b/NAMESPACE index 1793595..b7f940e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -59,6 +59,7 @@ importFrom(utils, Stangle, capture.output, data, + file_test, getParseData, globalVariables, head, diff --git a/NEWS b/NEWS index f22dc0c..9d0d489 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,11 @@ BUG FIXES AND MINOR IMPROVEMENTS package status file cannot be downloaded. It uses the cached copy when one exists and otherwise skips the check with a message (@LiNk-NY, #273). + o `checkNEWS()` looks only for the NEWS files that `news()` reads + (`inst/NEWS.Rd`, `NEWS.md`, `inst/NEWS.md`, `NEWS`, `inst/NEWS`), in + that order. Files elsewhere whose names end in `NEWS`, such as + `vignettes/NEWS.Rmd`, no longer count or raise a 'More than one NEWS + file' NOTE (@LiNk-NY, #276). CHANGES IN VERSION 1.50.0 ----------------------- diff --git a/R/checks.R b/R/checks.R index 2d0318d..409939c 100644 --- a/R/checks.R +++ b/R/checks.R @@ -1,6 +1,6 @@ #' @importFrom tools file_path_sans_ext file_ext parse_Rd Rd2ex #' @importFrom utils capture.output data getParseData head packageDescription -#' @importFrom utils packageVersion globalVariables readCitationFile +#' @importFrom utils packageVersion globalVariables readCitationFile file_test #' @importFrom stringdist stringdistmatrix #' @importFrom knitr purl #' @importFrom BiocManager available install repositories version @@ -499,28 +499,33 @@ checkFunctionLengths <- function(parsedCode, pkgname) } } +## NEWS files that news() can read once the package is installed, in the +## order it looks for them: NEWS.Rd, then NEWS.md, then NEWS +.NEWS_FILES <- c( + file.path("inst", "NEWS.Rd"), + "NEWS.md", file.path("inst", "NEWS.md"), + "NEWS", file.path("inst", "NEWS") +) + checkNEWS <- function(pkgdir) { - newsFnd <- list.files( - path = pkgdir, pattern = "NEWS[\\.Rd|\\.md]*$", - recursive = TRUE, full.names = TRUE, include.dirs = FALSE - ) + newsFnd <- .NEWS_FILES[file_test("-f", file.path(pkgdir, .NEWS_FILES))] if (!length(newsFnd)) { handleNote( "Consider adding a NEWS file, so your package news will be ", "included in Bioconductor release announcements.") return() } - newsPath <- file.path(basename(dirname(newsFnd)), basename(newsFnd)) if (length(newsFnd) > 1L) { handleNote( "More than one NEWS file found.", "See ?news for recognition ordering.", help_text = "Please remove one of the following: ", - messages = newsPath + messages = newsFnd ) } - news <- head(newsFnd, 1L) + newsPath <- head(newsFnd, 1L) + news <- file.path(pkgdir, newsPath) newsext <- tools::file_ext(news) newsextract <- switch( newsext, diff --git a/inst/tinytest/test_BiocCheck.R b/inst/tinytest/test_BiocCheck.R index 485a73c..a178b10 100644 --- a/inst/tinytest/test_BiocCheck.R +++ b/inst/tinytest/test_BiocCheck.R @@ -1187,6 +1187,30 @@ expect_equivalent(1, .BiocCheck$getNum("warning")) ## remove the NEWS files so a rerun in the same session starts clean unlink(file.path(UNIT_TEST_TEMPDIR, c("NEWS.md", file.path("inst", "NEWS.Rd")))) +## only the files that news() reads count, wherever else 'NEWS' appears +news_dir <- tempfile() +dir.create(file.path(news_dir, "inst"), recursive = TRUE) +dir.create(file.path(news_dir, "vignettes")) +dir.create(file.path(news_dir, "tests", "fixtures"), recursive = TRUE) +cat("lalala", file = file.path(news_dir, "NEWS")) +cat("lalala", file = file.path(news_dir, "vignettes", "NEWS.Rmd")) +cat("lalala", file = file.path(news_dir, "tests", "fixtures", "oldNEWS")) +cat("lalala", file = file.path(news_dir, "inst", "NEWS.txt")) +BiocCheck:::checkNEWS(news_dir) +expect_true(stillZero()) +## inst/NEWS.Rd is read before NEWS, so its parse failure is reported +cat("lalala", file = file.path(news_dir, "inst", "NEWS.Rd")) +BiocCheck:::checkNEWS(news_dir) +notes <- unlist(.BiocCheck$get("note"), use.names = FALSE) +warns <- unlist(.BiocCheck$get("warning"), use.names = FALSE) +expect_true(any(grepl("More than one NEWS file", notes, fixed = TRUE))) +expect_identical(sum(c("inst/NEWS.Rd", "NEWS") %in% notes), 2L) +expect_false(any(grepl("NEWS.Rmd|oldNEWS|NEWS.txt", notes))) +expect_identical(length(warns), 1L) +expect_true(grepl("inst/NEWS.Rd", warns, fixed = TRUE)) +.BiocCheck$zero() +unlink(news_dir, recursive = TRUE) + # checkFormatting --------------------------------------------------------- cli::cli_h3("checkFormatting")