Skip to content

Commit

Permalink
Merge pull request #452 from carpentries/fix-build-location
Browse files Browse the repository at this point in the history
move markdown shortcut to `build_episode_md()`
  • Loading branch information
zkamvar authored May 5, 2023
2 parents ed786cf + b871bc3 commit 6989c39
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 27 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export(validate_lesson)
export(work_with_cache)
importFrom(assertthat,validate_that)
importFrom(rlang,is_interactive)
importFrom(tools,file_ext)
importFrom(tools,md5sum)
importFrom(utils,modifyList)
importFrom(utils,read.table)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* A failure to incrementally build the lesson with `sandpaper::serve()` has been
fixed (reported: @zkamvar, #450; fixed: @zkamvar, #451)

## MISC

* Lessons with markdown documents no longer use `callr::r()` as an intermediary
(reported: @zkamvar, #442, fixed: @zkamvar, #452)

# sandpaper 0.11.15 (2023-04-05)

## BUG FIX
Expand Down
6 changes: 6 additions & 0 deletions R/build_episode.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ build_episode_md <- function(path, hash = NULL, outdir = path_built(path),
md <- fs::path_ext_set(fs::path_file(path), "md")
outpath <- fs::path(outdir, md)

# shortcut if we have a markdown file
if (file_ext(path) == "md") {
file.copy(path, outpath, overwrite = TRUE)
return(invisible(outpath))
}

# Set up the arguments
root <- root_path(path)
prof <- fs::path(root, "renv", "profiles", profile)
Expand Down
1 change: 1 addition & 0 deletions R/sandpaper-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#' @importFrom utils modifyList
#' @importFrom utils tail
#' @importFrom tools md5sum
#' @importFrom tools file_ext
#' @importFrom rlang is_interactive
## usethis namespace: end
NULL
10 changes: 0 additions & 10 deletions R/utils-callr.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
callr_build_episode_md <- function(path, hash, workenv, outpath, workdir, root, quiet, error = TRUE) {
# Shortcut if the source is a markdown file
# Taken directly from tools::file_ext
file_ext <- function (x) {
pos <- regexpr("\\.([[:alnum:]]+)$", x)
ifelse(pos > -1L, substring(x, pos + 1L), "")
}
# Also taken directly from tools::file_path_sans_ext
file_path_sans_ext <- function (x) {
sub("([^.]+)\\.[[:alnum:]]+$", "\\1", x)
}
if (file_ext(path) == "md") {
file.copy(path, outpath, overwrite = TRUE)
return(NULL)
}
# Load required packages if it's an RMarkdown file and we know the root
# directory.
if (root != "") {
Expand Down
6 changes: 3 additions & 3 deletions man/build_episode_html.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/build_episode_md.Rd

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

13 changes: 0 additions & 13 deletions tests/testthat/test-utils-callr.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@
"RENV_CONFIG_CACHE_SYMLINKS" = renv_cache_available()))
}

test_that("callr_build_episode_md() works with normal markdown", {

expect_false(fs::file_exists(o1))
res <- callr_build_episode_md(
path = t1, hash = NULL, workenv = new.env(),
outpath = o1, workdir = fs::path_dir(o1), root = "", quiet = FALSE
)
expect_null(res)
expect_true(fs::file_exists(o1))
expect_equal(tools::md5sum(t1), tools::md5sum(o1), ignore_attr = TRUE)

})

test_that("callr_build_episode_md() works with Rmarkdown", {

expect_false(fs::file_exists(o2))
Expand Down

0 comments on commit 6989c39

Please sign in to comment.