Repository navigation
docs: stop vendoring igraph.r2cdocs, put it within R/ #3007
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
Open
maelle
wants to merge
2
commits into
main
Choose a base branch
from
roclet-not-vendored
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+402
−1,919
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,23 @@ | ||
| #' @importFrom roxygen2 roclet | ||
| #' @export | ||
| # The roclet that links the C manual from the reference pages. | ||
| # The `Roxygen` field of `DESCRIPTION` names it as `docs_rd` of this package, | ||
| # in place of roxygen2's `rd`; | ||
| # roxygen2 finds it after loading the package code, so it needs no install. | ||
| # This file is `.Rbuildignore`d: the roclet serves documenting only, | ||
| # and its dependencies are in `Config/Needs/roxygen2` rather than `Imports`. | ||
| # See handbook/architecture/r-layer/documentation/. | ||
|
|
||
| docs_rd <- function() { | ||
| roclet(c("docs_rd", "rd")) | ||
| } | ||
|
|
||
| #' @importFrom roxygen2 roclet_process | ||
| #' @export | ||
|
|
||
| roclet_process.roclet_docs_rd <- function(x, blocks, env, base_path) { | ||
| NextMethod() | ||
| # Registered here rather than in `NAMESPACE`, | ||
| # which the built package, without this file, could not honor. | ||
| registerS3method( | ||
| "roclet_output", | ||
| "roclet_docs_rd", | ||
| roclet_output.roclet_docs_rd, | ||
| envir = asNamespace("roxygen2") | ||
| ) | ||
| roxygen2::roclet(c("docs_rd", "rd")) | ||
| } | ||
|
|
||
| #' @importFrom roxygen2 roclet_output | ||
| #' @export | ||
|
|
||
| roclet_output.roclet_docs_rd <- function(x, results, base_path, ...) { | ||
| # Built once per run rather than memoised across runs, | ||
| # where a second run in the same session would get the call graph | ||
|
|
@@ -206,7 +209,7 @@ r_call_graph <- function(base_path) { | |
| # as the function names (`vertices`) and the callees of each one | ||
| # (`callees`, sorted vertex indices). | ||
| # Vertices are numbered in order of first appearance, callers first, | ||
| # as igraph::graph_from_data_frame() numbers them. | ||
| # as graph_from_data_frame() numbers them. | ||
| call_graph <- function(from, to) { | ||
| vertices <- unique(c(from, to)) | ||
| callees <- split( | ||
|
|
@@ -220,7 +223,7 @@ call_graph <- function(from, to) { | |
| } | ||
|
|
||
| # The functions reachable from `start` through calls, `start` included, | ||
| # in the order igraph::subcomponent(mode = "out") returns them: | ||
| # in the order subcomponent(mode = "out") returns them: | ||
| # breadth first, and the callees of each function by ascending index. | ||
| # Empty when `start` is not a vertex. | ||
| reachable_functions <- function(call_graph, start) { | ||
|
|
@@ -264,17 +267,58 @@ c_docs_version <- function(version) { | |
| sub("-[0-9]+-g[0-9a-f]+(-dirty)?$", "", version) | ||
| } | ||
|
|
||
| # The link tables this package carries, one per release of the C manual, | ||
| # as data-raw/clinks.R writes them, named by the release. | ||
| # The releases of the C library vendored at `base_path`, | ||
| # from the headings of its changelog, such as `## [0.10.17] - 2025-09-19`. | ||
| c_releases <- function(base_path) { | ||
| lines <- readLines(file.path( | ||
| base_path, | ||
| "src", | ||
| "vendor", | ||
| "cigraph", | ||
| "CHANGELOG.md" | ||
| )) | ||
| headings <- regmatches(lines, regexec("^## \\[([0-9][^]]*)\\]", lines)) | ||
| map_chr(compact(headings), \(x) x[[2]]) | ||
| } | ||
|
|
||
| # The directory caching the link tables, one per release of the C manual. | ||
| # The tables describe the C library, so every flavor of this package shares them. | ||
| c_links_cache_dir <- function() { | ||
| file.path(tools::R_user_dir("igraph", "cache"), "clinks") | ||
| } | ||
|
|
||
| # The link tables in the cache, named by the release. | ||
| c_links_tables <- function() { | ||
| files <- dir( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused because I thought we had already switched to the user directory caching that this PR has. |
||
| system.file("clinks", package = "igraph.r2cdocs"), | ||
| pattern = "[.]csv$", | ||
| full.names = TRUE | ||
| ) | ||
| files <- dir(c_links_cache_dir(), pattern = "[.]csv$", full.names = TRUE) | ||
| set_names(files, sub("[.]csv$", "", basename(files))) | ||
| } | ||
|
|
||
| # Downloads the link table for one release of the C manual into the cache, | ||
| # from the index igraph.org publishes for that release. | ||
| # The release tarball of the C library carries the same index | ||
| # as `doc/html/ix01.html`, which `index_url` can name instead. | ||
| c_links_download <- function( | ||
| version, | ||
| index_url = sprintf("https://igraph.org/c/html/%s/ix01.html", version) | ||
| ) { | ||
| index <- xml2::read_html(index_url) | ||
| entries <- xml2::xml_find_all(index, ".//dt") | ||
| href <- map_chr(entries, \(dt) xml2::xml_attr(xml2::xml_child(dt), "href")) | ||
|
|
||
| clinks <- data.frame( | ||
| method = sub(".*#", "", href), | ||
| url = sprintf("https://igraph.org/c/html/%s/%s", version, href) | ||
| ) | ||
|
|
||
| dir <- c_links_cache_dir() | ||
| dir.create(dir, recursive = TRUE, showWarnings = FALSE) | ||
| utils::write.csv( | ||
| clinks, | ||
| file.path(dir, paste0(version, ".csv")), | ||
| row.names = FALSE | ||
| ) | ||
| } | ||
|
|
||
| # The release whose link table serves `version`: | ||
| # its own, else the newest release before it, else `NA`. | ||
| # Versions compare by their numeric part, so a pre-release comes after the | ||
|
|
@@ -294,30 +338,42 @@ c_links_release <- function(version, releases) { | |
| older[[order(core(older), is_release, decreasing = TRUE)[[1]]]] | ||
| } | ||
|
|
||
| # The link table for the version of the C library vendored at `base_path`, | ||
| # from the tables this package carries rather than from igraph.org, | ||
| # so that the links depend on the sources alone. | ||
| # The link table for the version of the C library vendored at `base_path`. | ||
| # The table of its release is downloaded once and cached; | ||
| # the links depend on the sources and that cache alone. | ||
| c_links <- function(base_path) { | ||
| engine <- igraph_c_version(base_path) | ||
| version <- c_docs_version(engine) | ||
|
|
||
| # The newest release of the C library documenting `version`, | ||
| # as the changelog vendored with it lists the releases. | ||
| target <- c_links_release(version, c_releases(base_path)) | ||
| if (!is.na(target) && !target %in% names(c_links_tables())) { | ||
| tryCatch( | ||
| c_links_download(target), | ||
| error = function(e) NULL | ||
| ) | ||
| } | ||
|
|
||
| tables <- c_links_tables() | ||
| release <- c_links_release(version, names(tables)) | ||
|
|
||
| if (is.na(release)) { | ||
| cli::cli_abort(c( | ||
| "No link table for the C manual of igraph {version} or an earlier release.", | ||
| i = "Add one with {.file data-raw/clinks.R} in {.pkg igraph.r2cdocs}." | ||
| i = "Could not download it from igraph.org; check the network access." | ||
| )) | ||
| } | ||
|
|
||
| if (release != version) { | ||
| # The links stay those of the newest release that has a table. | ||
| # The links stay those of the newest release in the cache. | ||
| # A development snapshot past that release is the normal state of a | ||
| # vendoring series; a release without a table is a table to add. | ||
| # vendoring series, whose manual is not published yet; | ||
| # a release whose manual cannot be downloaded is worth a warning. | ||
| notify <- if (engine != version) cli::cli_inform else cli::cli_warn | ||
| notify(c( | ||
| "No link table for the C manual of igraph {version}, linking the manual of {release}.", | ||
| i = "Add one with {.file data-raw/clinks.R} in {.pkg igraph.r2cdocs} once that manual is published." | ||
| i = "It is downloaded from igraph.org once that manual is published." | ||
| )) | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do wonder if we could do something simpler