Skip to content

Commit

Permalink
Update dev pkgdepends
Browse files Browse the repository at this point in the history
To get a newer `scan_deps()`.
  • Loading branch information
gaborcsardi committed Dec 18, 2024
1 parent e10e20f commit da1bbe8
Show file tree
Hide file tree
Showing 37 changed files with 63,913 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/library/pkgdepends/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.3.2
NeedsCompilation: yes
Packaged: 2024-11-08 09:37:25 UTC; gaborcsardi
Packaged: 2024-12-18 17:35:36 UTC; gaborcsardi
Author: Gábor Csárdi [aut, cre],
Posit Software, PBC [cph, fnd]
Maintainer: Gábor Csárdi <csardi.gabor@gmail.com>
3 changes: 3 additions & 0 deletions src/library/pkgdepends/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method("[",pkg_resolution_result)
S3method("[",pkg_scan_deps)
S3method("[",pkg_solution_result)
S3method("[",pkg_sysreqs_check_result)
S3method("[",pkgplan_downloads)
Expand All @@ -13,6 +14,7 @@ S3method(format,pkg_name_check_sentiment)
S3method(format,pkg_name_check_urban)
S3method(format,pkg_name_check_wikipedia)
S3method(format,pkg_name_check_wiktionary)
S3method(format,pkg_scan_deps)
S3method(format,pkg_solution_failures)
S3method(format,pkg_solution_result)
S3method(format,pkg_sysreqs_check_result)
Expand All @@ -22,6 +24,7 @@ S3method(print,package_build_error)
S3method(print,package_packaging_error)
S3method(print,package_uncompress_error)
S3method(print,pkg_name_check)
S3method(print,pkg_scan_deps)
S3method(print,pkg_solution_result)
S3method(print,pkg_sysreqs_check_result)
S3method(print,pkginstall_result)
Expand Down
23 changes: 18 additions & 5 deletions src/library/pkgdepends/R/scan-deps-dep-types.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
get_dep_type_from_path <- function(paths) {
type <- rep("prod", length(paths))
type[paths == "man/roxygen/meta.R"] <- "dev"
type[startsWith(paths, "tests/") | startsWith(paths, "test/")] <- "test"
type
get_dep_type_from_path <- function(paths, orig = NULL) {
tps <- rep("prod", length(paths))
tps[paths == "man/roxygen/meta.R"] <- "dev"
tps[startsWith(paths, "tests/") | startsWith(paths, "test/")] <- "test"
if (!is.null(orig)) {
# for DESCRIPTION we detect the type from the file itself
dsc <- basename(paths) == "DESCRIPTION"
tps[dsc] <- orig[dsc]
}
tps
}

get_dep_type_from_description_field <- function(fields) {
tps <- rep("dev", length(fields))
tps[fields %in% c("Depends", "Imports", "LinkingTo")] <- "prod"
tps[fields %in% c("Suggests", "Enhanced")] <- "test"
tps[fields == "Config/Needs/coverage"] <- "test"
tps
}
45 changes: 45 additions & 0 deletions src/library/pkgdepends/R/scan-deps-print.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' @export

format.pkg_scan_deps <- function(x, ...) {
labels <- c(
prod = "Dependencies",
test = "Test dependencies",
dev = "Development dependencies",
# TODO: generic label for others
NULL
)
lns <- lapply(seq_along(labels), function(i) {
deps <- x[x$type == names(labels)[i], , drop = FALSE]
if (nrow(deps) == 0) return(NULL)
fls <- tapply(deps$path, deps$package, "c", simplify = FALSE)
fls[] <- lapply(fls, unique)
fls <- vcapply(fls, paste, collapse = ", ")
pkg <- format(names(fls))
flsw <- cli::console_width() - nchar(pkg[1]) - 5
c(
"", cli::col_yellow(paste0(labels[i], ":")),
paste0(
cli::col_grey("+ "),
cli::col_blue(pkg),
cli::col_grey(" @ "),
cli::col_silver(cli::ansi_strtrim(fls, flsw))
)
)
})

unlist(lns)
}

#' @export

print.pkg_scan_deps <- function(x, ...) {
writeLines(format(x, ...))
invisible(x)
}

#' @export

`[.pkg_scan_deps` <- function (x, i, j, drop = FALSE) {
class(x) <- setdiff(class(x), "pkg_scan_deps")
NextMethod("[")
}
55 changes: 54 additions & 1 deletion src/library/pkgdepends/R/scan-deps-queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ q_deps_rmd <- function() {
(#match? @header "^[{]")
)',
inline =
'(inline) @inline'
'(inline) @inline',
header =
'(minus_metadata) @metadata'
)
}

Expand All @@ -166,3 +168,54 @@ q_deps_rmd_inline <- function() {
(code_span_delimiter) @csd2
) @code'
}

q_deps_yaml_header <- function() {
c(shiny =
'(document (block_node (block_mapping (block_mapping_pair
key: _ @key
value: (_ [
(plain_scalar)
(block_scalar)
(single_quote_scalar)
(double_quote_scalar)
]) @value
) @code ))
(#any-of? @key "server" "\'server\'" "\\"server\\""))',
shiny =
'(document (block_node (block_mapping (block_mapping_pair
key: _ @key
value: (block_node (block_mapping (block_mapping_pair
key: _ @key2
value: (_ [
(plain_scalar)
(block_scalar)
(single_quote_scalar)
(double_quote_scalar)
]) @value
)))
) @code ))
(#any-of? @key "server" "\'server\'" "\\"server\\"")
(#any-of? @key2 "type" "\'type\'" "\\"type\\""))',
pkgstring =
'((string_scalar) @code
(#match? @code "^[a-zA-Z][.a-zA-Z0-9]+[ ]*::"))',
bslib =
'(document (block_node (block_mapping (block_mapping_pair
key: _ @key
value: (block_node (block_mapping (block_mapping_pair
key: _ @key2
value: (block_node (block_mapping (block_mapping_pair
key: _ @key3
value: _ @value
)))
)))
) @code ))
(#any-of? @key "output" "\'output\'" "\\"output\\"")
(#any-of? @key2 "html_document" "\'html_document\'" "\\"html_document\\"")
(#any-of? @key3 "theme" "\'theme\'" "\\"theme\\""))',
tag =
'((tag) @tag . _ @code
(#any-of? @tag "!r" "\'!r\'" "\\"!r\\""))',
NULL
)
}
Loading

0 comments on commit da1bbe8

Please sign in to comment.