Skip to content

Commit 39c6bcc

Browse files
committed
Skipping .Rd files that didn't change.
1 parent 27d82c7 commit 39c6bcc

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

R/import_man.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@
162162

163163
# Skip file when frozen
164164
if (isTRUE(freeze)) {
165+
166+
freeze_output <- if (tool == "quarto_website") destination_qmd else destination_md
167+
165168
flag <- .is_frozen(
166169
input = origin_Rd,
167-
output = destination_md,
170+
output = freeze_output,
168171
hashes = hashes
169172
)
170173
if (isTRUE(flag)) {

R/render_docs.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,27 @@ render_docs <- function(
8989
function(f) basename(f) != "_freeze",
9090
docs_files
9191
)
92+
docs_files <- Filter(
93+
function(f) basename(f) != "man",
94+
docs_files
95+
)
9296
}
9397
fs::file_delete(docs_files)
98+
99+
# When freeze is on, clean up stale man-page qmds with no matching .Rd
100+
if (isTRUE(freeze)) {
101+
man_dir <- fs::path_join(c(docs_dir, "man"))
102+
if (fs::dir_exists(man_dir)) {
103+
rd_stems <- fs::path_ext_remove(basename(
104+
list.files(fs::path_join(c(path, "man")),
105+
pattern = "\\.Rd$"
106+
)
107+
))
108+
old_qmds <- fs::dir_ls(man_dir, regexp = "\\.qmd$")
109+
stale <- old_qmds[!fs::path_ext_remove(basename(old_qmds)) %in% rd_stems]
110+
if (length(stale)) fs::file_delete(stale)
111+
}
112+
}
94113
}
95114
} else {
96115
docs_dir <- fs::path_join(c(path, "docs"))
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
library(testthat)
2+
library(altdoc)
3+
4+
test_that("quarto: freeze skips man pages when unchanged", {
5+
skip_on_cran()
6+
skip_if(!.quarto_is_installed())
7+
8+
### setup: create a temp package
9+
create_local_package()
10+
fs::dir_create("man")
11+
cat(
12+
"\\name{hi}\n\\title{hi}\n\\usage{\nhi()\n}\n\\description{hi}\n",
13+
file = "man/hi.Rd"
14+
)
15+
cat(
16+
"\\name{ho}\n\\title{ho}\n\\usage{\nho()\n}\n\\description{ho}\n",
17+
file = "man/ho.Rd"
18+
)
19+
20+
setup_docs("quarto_website")
21+
22+
# First run
23+
render_docs(freeze = TRUE, verbose = FALSE)
24+
25+
expect_true(fs::file_exists("_quarto/man/ho.qmd"))
26+
expect_true(fs::file_exists("docs/man/ho.html"))
27+
expect_true(fs::file_exists("altdoc/freeze.rds"))
28+
29+
mtime1 <- fs::file_info("_quarto/man/hi.qmd")$modification_time
30+
31+
# Delete one of the .Rd files to check that cleanup works
32+
fs::file_delete("man/ho.Rd")
33+
34+
# Second run
35+
Sys.sleep(1.1) # Ensure time difference
36+
out <- capture_messages(render_docs(freeze = TRUE, verbose = FALSE))
37+
38+
# Check that stale files are removed
39+
expect_false(fs::file_exists("_quarto/man/ho.qmd"))
40+
expect_false(fs::file_exists("docs/man/ho.html"))
41+
42+
# Check that re-generation was skipped
43+
mtime2 <- fs::file_info("_quarto/man/hi.qmd")$modification_time
44+
expect_equal(mtime1, mtime2)
45+
46+
expect_match(paste(out, collapse = "\n"), "1 .Rd files skipped because they didn't change")
47+
})

0 commit comments

Comments
 (0)