Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude lockfile packages from hydration #533

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sandpaper
Title: Create and Curate Carpentries Lessons
Version: 0.14.0
Version: 0.14.1
Authors@R: c(
person(given = "Zhian N.",
family = "Kamvar",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# sandpaper 0.14.1 (2023-11-09)

## BUG FIX

* `mailto:` links are no longer prepended with the URL (reported: @apirogov,
#538; fixed: @zkamvar, #539)

# sandpaper 0.14.0 (2023-10-02)

## NEW FEATURES
Expand Down
6 changes: 6 additions & 0 deletions R/utils-renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ callr_manage_deps <- function(path, repos, snapshot, lockfile_exists) {
deps <- unique(renv::dependencies(path = path, root = path, dev = TRUE)$Package)
pkgs <- setdiff(deps, installed)
needs_hydration <- length(pkgs) > 0
if (packageVersion("renv") >= "1.0.0") {
# We only need to hydrate the packages that do not exist in the lockfile
# and that are not installed
lock <- renv::lockfile_read(renv_lock)
pkgs <- setdiff(pkgs, names(lock$Packages))
}
} else {
# If there is not a lockfile, we need to run a fully hydration
pkgs <- NULL
Expand Down
9 changes: 6 additions & 3 deletions R/utils-xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ use_instructor <- function(nodes = NULL) {
if (length(nodes) == 0) return(nodes)
copy <- xml2::read_html(as.character(nodes))
# find all local links and transform non-html and nested links ---------
lnk <- xml2::xml_find_all(copy,
".//a[@href][not(contains(@href, '://')) and not(starts-with(@href, '#'))]"
)
no_external <- "not(contains(@href, '://'))"
no_anchors <- "not(starts-with(@href, '#'))"
no_mail <- "not(starts-with(@href, 'mailto:'))"
predicate <- paste(c(no_external, no_anchors, no_mail), collapse = " and ")
XPath <- sprintf(".//a[@href][%s]", predicate)
lnk <- xml2::xml_find_all(copy, XPath)
lnk_hrefs <- xml2::xml_attr(lnk, "href")
lnk_paths <- xml2::url_parse(lnk_hrefs)$path
# links without HTML extension
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/_snaps/utils-xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
xml2::xml_find_all(html_test, ".//a[@href]")
Output
{xml_nodeset (10)}
{xml_nodeset (11)}
[1] <a href="index.html">a</a>
[2] <a href="./index.html">b</a>
[3] <a href="fig/thing.png">c</a>
Expand All @@ -14,13 +14,14 @@
[8] <a href="#what-the">h</a>
[9] <a href="other-page.html#section">i</a>
[10] <a href="other-page">j</a>
[11] <a href="mailto:[email protected]?subject='no'">k</a>

---

Code
xml2::xml_find_all(res, ".//a[@href]")
Output
{xml_nodeset (10)}
{xml_nodeset (11)}
[1] <a href="index.html">a</a>
[2] <a href="./index.html">b</a>
[3] <a href="../fig/thing.png">c</a>
Expand All @@ -31,4 +32,5 @@
[8] <a href="#what-the">h</a>
[9] <a href="other-page.html#section">i</a>
[10] <a href="other-page">j</a>
[11] <a href="mailto:[email protected]?subject='no'">k</a>

5 changes: 3 additions & 2 deletions tests/testthat/test-utils-xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ test_that("paths in instructor view that are nested or not HTML get diverted", {
"[g](files/confirmation.html)", # asset
"[h](#what-the)",
"[i](other-page.html#section)",
"[j](other-page)"
"[j](other-page)",
"[k](mailto:[email protected]?subject='no')"
)))
res <- xml2::read_html(use_instructor(html_test))
# refs are transformed according to our rules
refs <- xml2::xml_text(xml2::xml_find_all(res, ".//@href"))
expect_equal(startsWith(refs, "../"),
c(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE))
c(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE))
expect_snapshot(xml2::xml_find_all(html_test, ".//a[@href]"))
expect_snapshot(xml2::xml_find_all(res, ".//a[@href]"))
})
Expand Down
Loading