From 0d2219f8857599276d85f9263524055417624f22 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 12 Mar 2025 16:41:07 +0100 Subject: [PATCH 1/6] ci: testing in dev too --- .github/workflows/R-CMD-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 00f6ac4..85e2ac5 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -2,9 +2,9 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: [main, master, production, test-CI] + branches: [main, master, dev, production, test-CI] pull_request: - branches: [main, master, production, test-CI] + branches: [main, master, dev, production, test-CI] name: R-CMD-check.yaml From 6602f6c52714216ea126c018166896e9bb5e4d7b Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 12 Mar 2025 16:54:18 +0100 Subject: [PATCH 2/6] feat: allow to print_pdf --- DESCRIPTION | 1 + R/compile_qmd_course.R | 15 ++++++++++++++- man/compile_qmd_course.Rd | 8 +++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b961186..180305b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,6 +29,7 @@ Imports: Suggests: ggplot2, knitr, + pagedown, rmarkdown, testthat, yesno diff --git a/R/compile_qmd_course.R b/R/compile_qmd_course.R index e86e199..c017874 100644 --- a/R/compile_qmd_course.R +++ b/R/compile_qmd_course.R @@ -18,6 +18,8 @@ #' @param debug logical. Output rendering output in user console. #' @param fix_img_path logical. If image path are present as raw html inside files, #' use this option to correctly edit their path. +#' @param render_pdf logical. If TRUE, render a pdf version of the html file +#' @param render_pdf_fun function. Function to use to render the pdf. Default to pagedown::chrome_print. The function need to take a path to a html file as input. #' #' @importFrom tools file_ext #' @importFrom htmltools htmlTemplate renderDocument save_html HTML @@ -89,7 +91,9 @@ compile_qmd_course <- function( ext_dir = NULL, quiet = FALSE, debug = FALSE, - fix_img_path = TRUE + fix_img_path = TRUE, + render_pdf = FALSE, + render_pdf_fun = pagedown::chrome_print ) { # check inputs and future settings not_all_files_are_qmd <- any( @@ -245,6 +249,15 @@ compile_qmd_course <- function( extra_dir = tmp_ext_dir ) + if (render_pdf) { + render_pdf_fun( + file.path( + output_dir, + output_html + ) + ) + } + return( file.path( output_dir, diff --git a/man/compile_qmd_course.Rd b/man/compile_qmd_course.Rd index 7c87751..de40fe3 100644 --- a/man/compile_qmd_course.Rd +++ b/man/compile_qmd_course.Rd @@ -17,7 +17,9 @@ compile_qmd_course( ext_dir = NULL, quiet = FALSE, debug = FALSE, - fix_img_path = TRUE + fix_img_path = TRUE, + render_pdf = FALSE, + render_pdf_fun = pagedown::chrome_print ) } \arguments{ @@ -49,6 +51,10 @@ If a path to a yml file is provided, metadata will be read from this file.} \item{fix_img_path}{logical. If image path are present as raw html inside files, use this option to correctly edit their path.} + +\item{render_pdf}{logical. If TRUE, render a pdf version of the html file} + +\item{render_pdf_fun}{function. Function to use to render the pdf. Default to pagedown::chrome_print. The function need to take a path to a html file as input.} } \value{ character. The path to the resulting html file From 348237b620973d2c5a675a3a84c32ff7dc465cd4 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 13 Mar 2025 14:17:51 +0100 Subject: [PATCH 3/6] test: testing pdf printing --- tests/testthat/test-compile_qmd_course.R | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tests/testthat/test-compile_qmd_course.R b/tests/testthat/test-compile_qmd_course.R index 73974af..d744540 100644 --- a/tests/testthat/test-compile_qmd_course.R +++ b/tests/testthat/test-compile_qmd_course.R @@ -362,6 +362,88 @@ test_that("compile_qmd_course account for qmd with no media output dir", { ) }) +skip_if_no_chrome <- function() { + if (!requireNamespace("pagedown", quietly = TRUE)) { + skip("pagedown not installed") + } + has_chrome <- try( + { + pagedown::find_chrome() + }, + silent = TRUE + ) + if (inherits(has_chrome, "try-error")) { + skip("chrome not installed") + } +} + +run_with_multiple_quarto <- function(expr) { + # Create a temp dir + temp_dir <- tempfile(pattern = "compile") + dir.create(temp_dir) + old_dir <- setwd(temp_dir) + for (i in 1:10) { + write( + file = sprintf("test%s.qmd", i), + sprintf("--- +title: 'test%s' +--- + +## Quarto + +Quarto enables you to weave together content and executable code into a finished presentation. To learn more about Quarto presentations see . +", i) + ) + } + on.exit({ + unlink(temp_dir, recursive = TRUE) + setwd(old_dir) + }) + force(expr) +} + +test_that( + "print pdf works", + { + skip_if_no_chrome() + + run_with_multiple_quarto({ + # This is a temporary solution while + # https://github.com/ThinkR-open/squash/issues/11 is not solved + output_dir <- tempfile(pattern = "output_dir") + dir.create(output_dir) + on.exit( + { + unlink(output_dir, recursive = TRUE) + }, + add = TRUE + ) + list.files(pattern = "\\.qmd$", full.names = TRUE) |> + compile_qmd_course( + output_dir = output_dir, + output_html = "complete_course.html", + render_pdf = TRUE + ) + expect_true( + file.exists( + file.path( + output_dir, + "complete_course.html" + ) + ) + ) + expect_true( + file.exists( + file.path( + output_dir, + "complete_course.pdf" + ) + ) + ) + }) + } +) + # clean up unlink(temp_dir, recursive = TRUE) unlink(tmp_course_path, recursive = TRUE) From 87624131073514d51d53ed621dfb98d178f3f4a2 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Tue, 1 Apr 2025 09:19:15 +0200 Subject: [PATCH 4/6] Allow to print pdf (#20) * ci: testing in dev too * feat: allow to print_pdf * test: testing pdf printing * chore: version bump & news * Update NEWS.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- DESCRIPTION | 2 +- NEWS.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 180305b..ede8248 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: squash Title: Several Quarto As Single HTML -Version: 1.0.0 +Version: 1.1.0 Authors@R: c( person("Antoine", "Languillaume", , "antoine@thinkr.fr", role = c("aut", "cre")), person("Colin", "Fay", , "colin@thinkr.fr", role = "aut"), diff --git a/NEWS.md b/NEWS.md index bfaf4c7..580c52f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# squash 1.1.0 + +* You can now print the output to pdf (#18) # squash 1.0.0 * Official stable release From 71eb0b9a5380740ab3073b691ca938998c3f9c55 Mon Sep 17 00:00:00 2001 From: Colin Fay Date: Tue, 22 Apr 2025 16:29:42 +0200 Subject: [PATCH 5/6] feat: retry the quarto rendering with purrr::insistently (#21) * feat: retry the quarto rendering with purrr::insistently * fix: rule number 1 * feat: pass param for insistently * fix: future settings are by default sequential * test: fixing the tests for fetch_future_settings --- R/compile_qmd_course.R | 10 ++++++++-- R/fetch_future_settings.R | 5 ++--- R/render_single_qmd.R | 14 ++++++++++++-- man/compile_qmd_course.Rd | 6 +++++- man/render_single_qmd.Rd | 5 ++++- tests/testthat/test-fetch_future_settings.R | 19 +++++++------------ 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/R/compile_qmd_course.R b/R/compile_qmd_course.R index c017874..2b74729 100644 --- a/R/compile_qmd_course.R +++ b/R/compile_qmd_course.R @@ -20,6 +20,7 @@ #' use this option to correctly edit their path. #' @param render_pdf logical. If TRUE, render a pdf version of the html file #' @param render_pdf_fun function. Function to use to render the pdf. Default to pagedown::chrome_print. The function need to take a path to a html file as input. +#' @param render_qmd_purrr_insistently_rate_backoff function. Function to use to retry rendering qmd files in case of failure. Should be a purrr::rate_backoff function. #' #' @importFrom tools file_ext #' @importFrom htmltools htmlTemplate renderDocument save_html HTML @@ -93,7 +94,11 @@ compile_qmd_course <- function( debug = FALSE, fix_img_path = TRUE, render_pdf = FALSE, - render_pdf_fun = pagedown::chrome_print + render_pdf_fun = pagedown::chrome_print, + render_qmd_purrr_insistently_rate_backoff = purrr::rate_backoff( + pause_base = 0.1, + max_times = 5 + ) ) { # check inputs and future settings not_all_files_are_qmd <- any( @@ -157,7 +162,8 @@ compile_qmd_course <- function( img_root_dir = img_root_dir, output_format = output_format, metadata = metadata_qmd, - quiet = !debug + quiet = !debug, + purrr_insistently_rate_backoff = render_qmd_purrr_insistently_rate_backoff ) }, # make random number generation reproducible diff --git a/R/fetch_future_settings.R b/R/fetch_future_settings.R index 4db58fd..6ee6621 100644 --- a/R/fetch_future_settings.R +++ b/R/fetch_future_settings.R @@ -10,8 +10,7 @@ #' @noRd #' @examples #' fetch_future_settings(vec_qmd_path = qmd, quiet = FALSE) -fetch_future_settings <- function( - quiet = TRUE) { +fetch_future_settings <- function(quiet = TRUE) { # look for future settings (e.g. parallel, sequential, default) future_setting <- attr(plan(), "call") future_setting <- ifelse( @@ -20,7 +19,7 @@ fetch_future_settings <- function( no = deparse(future_setting) ) - if (isFALSE(quiet) && !grepl("default", future_setting)) { + if (isFALSE(quiet) && !grepl("sequential", future_setting)) { cli_alert_info(paste( "{{future}} is using {future_setting},", "to modify this use {.code future::plan()}" diff --git a/R/render_single_qmd.R b/R/render_single_qmd.R index bb31764..7f947ca 100644 --- a/R/render_single_qmd.R +++ b/R/render_single_qmd.R @@ -5,6 +5,7 @@ #' @param qmd character. Path to the qmd file to render #' @param img_root_dir character. Path to the main image folder to extract media to #' @param metadata list. List of metadata to be used for rendering single qmd file +#' @param purrr_insistently_rate_backoff function. Function to use to retry rendering qmd files in case of failure. Should be a purrr::rate_backoff function. #' #' @inheritParams compile_qmd_course #' @@ -46,7 +47,11 @@ render_single_qmd <- function( img_root_dir = "img", output_format = "revealjs", metadata = NULL, - quiet = TRUE + quiet = TRUE, + purrr_insistently_rate_backoff = purrr::rate_backoff( + pause_base = 0.1, + max_times = 5 + ) ) { # set image sub-folder name chapter <- dirname(qmd) @@ -56,10 +61,15 @@ render_single_qmd <- function( paste0(basename(chapter), "_img") ) + quarto_render_insistently <- purrr::insistently( + quarto_render, + rate = purrr_insistently_rate_backoff + ) + # try rendering qmd and warn user if successful / fail tryCatch( expr = { - quarto_render( + quarto_render_insistently( input = qmd, metadata = c(metadata, list(`extract-media` = img_dir)), output_format = output_format, diff --git a/man/compile_qmd_course.Rd b/man/compile_qmd_course.Rd index de40fe3..16e1874 100644 --- a/man/compile_qmd_course.Rd +++ b/man/compile_qmd_course.Rd @@ -19,7 +19,9 @@ compile_qmd_course( debug = FALSE, fix_img_path = TRUE, render_pdf = FALSE, - render_pdf_fun = pagedown::chrome_print + render_pdf_fun = pagedown::chrome_print, + render_qmd_purrr_insistently_rate_backoff = purrr::rate_backoff(pause_base = 0.1, + max_times = 5) ) } \arguments{ @@ -55,6 +57,8 @@ use this option to correctly edit their path.} \item{render_pdf}{logical. If TRUE, render a pdf version of the html file} \item{render_pdf_fun}{function. Function to use to render the pdf. Default to pagedown::chrome_print. The function need to take a path to a html file as input.} + +\item{render_qmd_purrr_insistently_rate_backoff}{function. Function to use to retry rendering qmd files in case of failure. Should be a purrr::rate_backoff function.} } \value{ character. The path to the resulting html file diff --git a/man/render_single_qmd.Rd b/man/render_single_qmd.Rd index c7c0154..1d17d00 100644 --- a/man/render_single_qmd.Rd +++ b/man/render_single_qmd.Rd @@ -9,7 +9,8 @@ render_single_qmd( img_root_dir = "img", output_format = "revealjs", metadata = NULL, - quiet = TRUE + quiet = TRUE, + purrr_insistently_rate_backoff = purrr::rate_backoff(pause_base = 0.1, max_times = 5) ) } \arguments{ @@ -22,6 +23,8 @@ render_single_qmd( \item{metadata}{list. List of metadata to be used for rendering single qmd file} \item{quiet}{logical. Output info in user console} + +\item{purrr_insistently_rate_backoff}{function. Function to use to retry rendering qmd files in case of failure. Should be a purrr::rate_backoff function.} } \value{ logical. TRUE if rendering succeeded, FALSE otherwise. Side effect : render qmd as html diff --git a/tests/testthat/test-fetch_future_settings.R b/tests/testthat/test-fetch_future_settings.R index 8f47039..8933a08 100644 --- a/tests/testthat/test-fetch_future_settings.R +++ b/tests/testthat/test-fetch_future_settings.R @@ -1,26 +1,21 @@ -test_that("future settings does not speak for default behaviour", { - # set to default - plan("default") - +test_that("fetch_future_settings quiet TRUE vs FALSE", { + oplan <- plan("default") + on.exit(plan(oplan), add = TRUE) expect_message( object = { - fetch_future_settings(quiet = FALSE) + fetch_future_settings(FALSE) }, regexp = NA ) }) -test_that("future settings does not speak for default behaviour", { - # set a multisession with one worker - plan(future::multisession, workers = 1) - +test_that("fetch_future_settings speak when future::multisession", { + oplan <- plan(future::multisession, workers = 1) + on.exit(plan(oplan), add = TRUE) expect_message( object = { fetch_future_settings(quiet = FALSE) }, regexp = "\\{future\\} is using plan\\(future::multisession, workers = 1\\)" ) - - # reset to default - plan("default") }) From 1c998c54223a7b07e759cb979c0d04c0ab10c54e Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 22 Apr 2025 16:44:55 +0200 Subject: [PATCH 6/6] chore: version bump & changelog --- DESCRIPTION | 8 ++++---- NEWS.md | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ede8248..00f9dc6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: squash Title: Several Quarto As Single HTML -Version: 1.1.0 +Version: 1.2.0 Authors@R: c( person("Antoine", "Languillaume", , "antoine@thinkr.fr", role = c("aut", "cre")), person("Colin", "Fay", , "colin@thinkr.fr", role = "aut"), @@ -11,7 +11,7 @@ Description: Compile n .qmd (under format revealjs) to one single html License: MIT + file LICENSE URL: https://thinkr-open.github.io/squash/, https://github.com/ThinkR-open/squash -Imports: +Imports: cli, dplyr, fs, @@ -26,14 +26,14 @@ Imports: tools, utils, yaml -Suggests: +Suggests: ggplot2, knitr, pagedown, rmarkdown, testthat, yesno -VignetteBuilder: +VignetteBuilder: knitr Config/fusen/version: 0.6.0 Config/testthat/edition: 3 diff --git a/NEWS.md b/NEWS.md index 580c52f..d2741be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ +# squash 1.2.0 + +* The rendering of the Qmd is now performed insistently with purrr::insistently(), and can be configured in the rendering functions. + # squash 1.1.0 * You can now print the output to pdf (#18) + # squash 1.0.0 * Official stable release