Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion R/import_man.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,12 @@

# Skip file when frozen
if (isTRUE(freeze)) {

freeze_output <- if (tool == "quarto_website") destination_qmd else destination_md

flag <- .is_frozen(
input = origin_Rd,
output = destination_md,
output = freeze_output,
hashes = hashes
)
if (isTRUE(flag)) {
Expand Down
19 changes: 19 additions & 0 deletions R/render_docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,27 @@ render_docs <- function(
function(f) basename(f) != "_freeze",
docs_files
)
docs_files <- Filter(
function(f) basename(f) != "man",
docs_files
)
}
fs::file_delete(docs_files)

# When freeze is on, clean up stale man-page qmds with no matching .Rd
if (isTRUE(freeze)) {
man_dir <- fs::path_join(c(docs_dir, "man"))
if (fs::dir_exists(man_dir)) {
rd_stems <- fs::path_ext_remove(basename(
list.files(fs::path_join(c(path, "man")),
pattern = "\\.Rd$"
)
Comment on lines +103 to +106
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract an intermediate object from this? It's quite hard to read as-is.

))
old_qmds <- fs::dir_ls(man_dir, regexp = "\\.qmd$")
stale <- old_qmds[!fs::path_ext_remove(basename(old_qmds)) %in% rd_stems]
if (length(stale)) fs::file_delete(stale)
}
}
}
} else {
docs_dir <- fs::path_join(c(path, "docs"))
Expand Down
47 changes: 47 additions & 0 deletions tests/testthat/test-freeze-quarto.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
library(testthat)
library(altdoc)

test_that("quarto: freeze skips man pages when unchanged", {
skip_on_cran()
skip_if(!.quarto_is_installed())

### setup: create a temp package
create_local_package()
fs::dir_create("man")
cat(
"\\name{hi}\n\\title{hi}\n\\usage{\nhi()\n}\n\\description{hi}\n",
file = "man/hi.Rd"
)
cat(
"\\name{ho}\n\\title{ho}\n\\usage{\nho()\n}\n\\description{ho}\n",
file = "man/ho.Rd"
)

setup_docs("quarto_website")

# First run
render_docs(freeze = TRUE, verbose = FALSE)

expect_true(fs::file_exists("_quarto/man/ho.qmd"))
expect_true(fs::file_exists("docs/man/ho.html"))
expect_true(fs::file_exists("altdoc/freeze.rds"))

mtime1 <- fs::file_info("_quarto/man/hi.qmd")$modification_time

# Delete one of the .Rd files to check that cleanup works
fs::file_delete("man/ho.Rd")

# Second run
Sys.sleep(1.1) # Ensure time difference
out <- capture_messages(render_docs(freeze = TRUE, verbose = FALSE))

# Check that stale files are removed
expect_false(fs::file_exists("_quarto/man/ho.qmd"))
expect_false(fs::file_exists("docs/man/ho.html"))

# Check that re-generation was skipped
mtime2 <- fs::file_info("_quarto/man/hi.qmd")$modification_time
expect_equal(mtime1, mtime2)

Check warning on line 44 in tests/testthat/test-freeze-quarto.R

View workflow job for this annotation

GitHub Actions / flir

file=/Users/runner/work/altdoc/altdoc/tests/testthat/test-freeze-quarto.R,line=44,col=5,[expect_equal(mtime1, mtime2)] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.

expect_match(paste(out, collapse = "\n"), "1 .Rd files skipped because they didn't change")
})
Loading