Skip to content

Commit

Permalink
update root criteria
Browse files Browse the repository at this point in the history
This will address carpentries/workbench#65
by adding fallbacks to the episodes directory criteria. I've added the
other directories we expect so that when the episodes directory does not
exist (in the case of overview pages), then we can check that the site
directory or any of the other directories exists.

I had initially attempted this by setting the config.yaml as the
criteria, but I forgot that I had also copied the config.yaml over to
the site/built folder, so there were a lot of failures from this one
change because it was getting confused where the root of the project.

Another tactic I considered was to check if `.git/` was a directory, but
then I realized this wouldn't work for submodules.
  • Loading branch information
zkamvar committed Aug 8, 2023
1 parent c2061ef commit a1fb322
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion R/utils-paths.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
root_path <- function(path) {
rprojroot::find_root(rprojroot::has_file("config.yaml", contents = "carpentry:"), path)
criteria <- rprojroot::has_dir("episodes") |
rprojroot::has_dir("site") |
rprojroot::has_dir("learners") |
rprojroot::has_dir("instructors") |
rprojroot::has_dir("profiles")

rprojroot::find_root(criteria, path)
}

no_readme <- function() "(?<![/]README)([.]md)$"
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper-hash.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ expect_hashed <- function(path, file) {
expected_hash <- tools::md5sum(fs::path(path_episodes(path), file))
md <- fs::path_ext_set(file, "md")
actual_hash <- get_hash(fs::path(path_built(path), md))
expect_equal(expected_hash, actual_hash, ignore_attr = TRUE)
expect_equal(actual_hash, expected_hash, ignore_attr = TRUE)
}
26 changes: 26 additions & 0 deletions tests/testthat/test-utils-paths.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
res <- restore_fixture()


test_that("root path will find the root of the lesson locally", {

here <- as.character(res)
expect_identical(root_path(here), here)

there <- fs::path(res, "episodes")
expect_identical(root_path(there), here)

there <- fs::path(res, "learners", "setup.md")
expect_identical(root_path(there), here)

# if we insert a config.yaml file into the built folder, it will not cause a
# problem
there <- fs::path(res, "site", "built")
fs::file_copy(fs::path(res, "config.yaml"), there)
expect_identical(root_path(there), here)

# removing the episodes folder does not invalidate the lesson
fs::dir_delete(fs::path(here, "episodes"))
expect_identical(root_path(there), here)

})

0 comments on commit a1fb322

Please sign in to comment.