From 20c91afe55c6ded68cc096bef805f6cd645c0852 Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:57:55 +0200 Subject: [PATCH 01/13] add extra_deps argument --- R/check.R | 12 ++-- R/deps_installation_proposal.R | 11 ++++ R/desc_utils.R | 94 +++++++++++++++++++++++++++---- man/deparse_dep_str.Rd | 22 ++++++++ man/deparse_ver_str.Rd | 21 +++++++ man/deps_check.Rd | 8 +++ man/deps_installation_proposal.Rd | 28 +++++++-- man/desc_add_extra_deps.Rd | 27 +++++++++ man/version_from_desc.Rd | 2 +- 9 files changed, 205 insertions(+), 20 deletions(-) create mode 100644 man/deparse_dep_str.Rd create mode 100644 man/deparse_ver_str.Rd create mode 100644 man/desc_add_extra_deps.Rd diff --git a/R/check.R b/R/check.R index ef4442bf..13f6c3b9 100644 --- a/R/check.R +++ b/R/check.R @@ -19,11 +19,12 @@ #' x$ip #' x$check max_deps_check <- function(path, + extra_deps = character(), config = list(), build_args = character(), check_args = character(), ...) { - ip <- new_max_deps_installation_proposal(path, config) + ip <- new_max_deps_installation_proposal(path, extra_deps, config) execute_ip(ip, path, check_args, build_args, ...) } @@ -35,11 +36,12 @@ max_deps_check <- function(path, #' x$ip #' x$check release_deps_check <- function(path, + extra_deps = character(), config = list(), build_args = character(), check_args = character(), ...) { - ip <- new_release_deps_installation_proposal(path, config) + ip <- new_release_deps_installation_proposal(path, extra_deps, config) execute_ip(ip, path, check_args, build_args, ...) } @@ -51,11 +53,12 @@ release_deps_check <- function(path, #' x$ip #' x$check min_cohort_deps_check <- function(path, + extra_deps = character(), config = list(), build_args = character(), check_args = character(), ...) { - ip <- new_min_cohort_deps_installation_proposal(path, config) + ip <- new_min_cohort_deps_installation_proposal(path, extra_deps, config) execute_ip(ip, path, check_args, build_args, ...) } @@ -67,11 +70,12 @@ min_cohort_deps_check <- function(path, #' x$ip #' x$check min_isolated_deps_check <- function(path, + extra_deps = character(), config = list(), build_args = character(), check_args = character(), ...) { - ip <- new_min_isolated_deps_installation_proposal(path, config) + ip <- new_min_isolated_deps_installation_proposal(path, extra_deps, config) execute_ip(ip, path, check_args, build_args, ...) } diff --git a/R/deps_installation_proposal.R b/R/deps_installation_proposal.R index 3cde74a6..793bb875 100644 --- a/R/deps_installation_proposal.R +++ b/R/deps_installation_proposal.R @@ -39,6 +39,9 @@ #' Please see also [`pkgdepends::pkg_config`] and [`pak::pak-config`] for other configuration possibilities. #' #' @param path (`string`) path to the package sources +#' @param extra_deps (`character(1)`) Extra dependencies specified similarly to the `DESCRIPTION` file, i.e. +#' `" ( )"` where both `` and `` are optional. +#' Multiple entries are possible separated by `";"`. #' @param config (`list`) configuration options. See [`pkgdepends::pkg_config`] for details. #' `"dependencies"` and `"library"` elements are overwritten by package level defaults. #' @@ -54,6 +57,7 @@ #' x$solve() #' x$get_solution() new_max_deps_installation_proposal <- function(path, # nolint + extra_deps = character(0L), config = list()) { path <- normalizePath(path) config <- append_config(default_config(), config) @@ -71,6 +75,7 @@ new_max_deps_installation_proposal <- function(path, # nolint new_refs_str <- map_key_character(new_refs, "ref") d <- desc_cond_set_refs(d, new_refs_str) + d <- desc_add_extra_deps(d, extra_deps) res <- desc_to_ip(d, config) class(res) <- c("max_deps_installation_proposal", "deps_installation_proposal", class(res)) @@ -85,6 +90,7 @@ new_max_deps_installation_proposal <- function(path, # nolint #' x$solve() #' x$get_solution() new_release_deps_installation_proposal <- function(path, # nolint + extra_deps = character(0L), config = list()) { path <- normalizePath(path) config <- append_config(default_config(), config) @@ -102,6 +108,7 @@ new_release_deps_installation_proposal <- function(path, # nolint new_refs_str <- map_key_character(new_refs, "ref") d <- desc_cond_set_refs(d, new_refs_str) + d <- desc_add_extra_deps(d, extra_deps) d <- desc_remotes_cleanup(d) res <- desc_to_ip(d, config) @@ -118,6 +125,7 @@ new_release_deps_installation_proposal <- function(path, # nolint #' solve_ip(x) #' x$get_solution() new_min_cohort_deps_installation_proposal <- function(path, # nolint + extra_deps = character(0L), config = list()) { path <- normalizePath(path) config <- append_config(default_config(), config) @@ -155,6 +163,7 @@ new_min_cohort_deps_installation_proposal <- function(path, # nolint ) new_refs_str <- map_key_character(new_refs, "ref") d <- desc_cond_set_refs(d, new_refs_str) + d <- desc_add_extra_deps(d, extra_deps) d <- desc_remotes_cleanup(d) # find PPM snapshot @@ -222,6 +231,7 @@ new_min_cohort_deps_installation_proposal <- function(path, # nolint #' solve_ip(x) #' x$get_solution() new_min_isolated_deps_installation_proposal <- function(path, # nolint + extra_deps = character(0L), config = list()) { path <- normalizePath(path) config <- append_config(default_config(), config) @@ -262,6 +272,7 @@ new_min_isolated_deps_installation_proposal <- function(path, # nolint new_refs_str <- map_key_character(new_refs, "ref") d <- desc_cond_set_refs(d, new_refs_str) + d <- desc_add_extra_deps(d, extra_deps) d <- desc_remotes_cleanup(d) res <- desc_to_ip(d, config) diff --git a/R/desc_utils.R b/R/desc_utils.R index dcfc43fc..28d0e5f9 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -122,6 +122,78 @@ desc_cond_set_refs <- function(d, refs) { return(invisible(d)) } +#' Adds extra dependencies to the `desc` object. +#' +#' This will add dependencies to the `Imports` field. +#' +#' @param d (`desc`) DESCRIPTION object from [desc::desc] +#' @param x (`character(1)`) Extra dependencies specified similarly to the `DESCRIPTION` file, i.e. +#' `" ( )"` where both `` and `` are optional. +#' Multiple entries are possible separated by `";"`. +#' +#' @return `desc` object with added dependencies. +#' +#' @keywords internal +#' +#' @examples +#' d <- desc::desc(cmd = "!new") +#' d <- verdepcheck:::desc_add_extra_deps(d, "foo (>= 1.2.3); bar (== 2.3.4)") +#' d$get_deps() +desc_add_extra_deps <- function(d, x) { + if (length(x)) { + for (x_i in strsplit(x, ";")[[1]]) { + x_i_deparsed <- deparse_dep_str(trimws(x_i)) + d$set_dep(x_i_deparsed$package, "Imports", x_i_deparsed$ver_str) + } + } + return(invisible(d)) +} + +#' Deparse a dependency string +#' +#' @param x (`character`) Dependency string in form of ` ( )`. See examples. +#' +#' @return `list` with `package`, `op`, `op_ver` and `ver_str` fields. +#' +#' @keywords internal +#' +#' @examples +#' verdepcheck:::deparse_dep_str("foo") +#' verdepcheck:::deparse_dep_str("foo (>= 1.2.3)") +deparse_dep_str <- function(x) { + x <- trimws(strsplit(x, "\\(")[[1]]) + package <- x[1] + ver_str <- gsub("\\)$", "", x[2]) + ver_str_deparsed <- deparse_ver_str(ver_str) + list( + package = x[1], + op = ver_str_deparsed$op, + op_ver = ver_str_deparsed$op_ver, + ver_str = ver_str + ) +} +#' Deparse a version string +#' +#' @param x (`character`) Version string in form of ` `. See examples. +#' +#' @return `list` with `op` and `op_ver` fields. +#' +#' @keywords internal +#' +#' @examples +#' verdepcheck:::deparse_ver_str(">= 1.2.3") +deparse_ver_str <- function(x) { + x <- trimws(x) + if (x == "*" || x == "") { + return(list(op = "", op_ver = "")) + } + split_vec <- strsplit(x, " ")[[1]] + list( + op = split_vec[1], + op_ver = split_vec[2] + ) +} + #' Create `installation_plan` object from `desc` object #' @importFrom pkgdepends new_pkg_installation_proposal #' @keywords internal @@ -137,7 +209,7 @@ desc_to_ip <- function(d, config) { } #' Get package version from description -#' @param d (`desc`) DESCRIPTION object from [desc::description] +#' @param d (`desc`) DESCRIPTION object from [desc::desc] #' @param pkg_name (`character`) Package name #' @keywords internal #' @@ -152,20 +224,20 @@ desc_to_ip <- function(d, config) { version_from_desc <- function(d, pkg_name) { all_deps <- d$get_deps() - version <- (all_deps$version[all_deps$package == pkg_name])[[1]] - result <- list( + ver_str <- (all_deps$version[all_deps$package == pkg_name])[[1]] + + res <- list( package = pkg_name, - version_str = version, + ver_str = ver_str, op = "", op_ver = "" ) - if (version == "*" || trimws(version) == "") { - return(result) - } - split_vec <- strsplit(version, " ")[[1]] - result$op <- split_vec[1] - result$op_ver <- split_vec[2] - result + + ver_str_deparsed <- deparse_ver_str(ver_str) + res$op <- ver_str_deparsed$op + res$op_ver <- ver_str_deparsed$op_ver + + res } #' Filter for package versions that comply with an operator and version diff --git a/man/deparse_dep_str.Rd b/man/deparse_dep_str.Rd new file mode 100644 index 00000000..b8065a13 --- /dev/null +++ b/man/deparse_dep_str.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/desc_utils.R +\name{deparse_dep_str} +\alias{deparse_dep_str} +\title{Deparse a dependency string} +\usage{ +deparse_dep_str(x) +} +\arguments{ +\item{x}{(\code{character}) Dependency string in form of \verb{ ( )}. See examples.} +} +\value{ +\code{list} with \code{package}, \code{op}, \code{op_ver} and \code{ver_str} fields. +} +\description{ +Deparse a dependency string +} +\examples{ +verdepcheck:::deparse_dep_str("foo") +verdepcheck:::deparse_dep_str("foo (>= 1.2.3)") +} +\keyword{internal} diff --git a/man/deparse_ver_str.Rd b/man/deparse_ver_str.Rd new file mode 100644 index 00000000..cc8c3559 --- /dev/null +++ b/man/deparse_ver_str.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/desc_utils.R +\name{deparse_ver_str} +\alias{deparse_ver_str} +\title{Deparse a version string} +\usage{ +deparse_ver_str(x) +} +\arguments{ +\item{x}{(\code{character}) Version string in form of \verb{ }. See examples.} +} +\value{ +\code{list} with \code{op} and \code{op_ver} fields. +} +\description{ +Deparse a version string +} +\examples{ +verdepcheck:::deparse_ver_str(">= 1.2.3") +} +\keyword{internal} diff --git a/man/deps_check.Rd b/man/deps_check.Rd index 2d450648..c4b119e2 100644 --- a/man/deps_check.Rd +++ b/man/deps_check.Rd @@ -9,6 +9,7 @@ \usage{ max_deps_check( path, + extra_deps = character(), config = list(), build_args = character(), check_args = character(), @@ -17,6 +18,7 @@ max_deps_check( release_deps_check( path, + extra_deps = character(), config = list(), build_args = character(), check_args = character(), @@ -25,6 +27,7 @@ release_deps_check( min_cohort_deps_check( path, + extra_deps = character(), config = list(), build_args = character(), check_args = character(), @@ -33,6 +36,7 @@ min_cohort_deps_check( min_isolated_deps_check( path, + extra_deps = character(), config = list(), build_args = character(), check_args = character(), @@ -42,6 +46,10 @@ min_isolated_deps_check( \arguments{ \item{path}{(\code{string}) path to the package sources} +\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, e.g. +\code{" ( )"} where both \code{operator} and \code{version} are optional. +Multiple entries are possible separated by \code{";"}.} + \item{config}{(\code{list}) configuration options. See \code{\link[pkgdepends:pkg_config]{pkgdepends::pkg_config}} for details. \code{"dependencies"} and \code{"library"} elements are overwritten by package level defaults.} diff --git a/man/deps_installation_proposal.Rd b/man/deps_installation_proposal.Rd index b468b30f..ed7033d3 100644 --- a/man/deps_installation_proposal.Rd +++ b/man/deps_installation_proposal.Rd @@ -8,17 +8,37 @@ \alias{new_min_isolated_deps_installation_proposal} \title{Create installation proposal using various dependency strategies} \usage{ -new_max_deps_installation_proposal(path, config = list()) +new_max_deps_installation_proposal( + path, + extra_deps = character(0L), + config = list() +) -new_release_deps_installation_proposal(path, config = list()) +new_release_deps_installation_proposal( + path, + extra_deps = character(0L), + config = list() +) -new_min_cohort_deps_installation_proposal(path, config = list()) +new_min_cohort_deps_installation_proposal( + path, + extra_deps = character(0L), + config = list() +) -new_min_isolated_deps_installation_proposal(path, config = list()) +new_min_isolated_deps_installation_proposal( + path, + extra_deps = character(0L), + config = list() +) } \arguments{ \item{path}{(\code{string}) path to the package sources} +\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, e.g. +\code{" ( )"} where both \code{operator} and \code{version} are optional. +Multiple entries are possible separated by \code{";"}.} + \item{config}{(\code{list}) configuration options. See \code{\link[pkgdepends:pkg_config]{pkgdepends::pkg_config}} for details. \code{"dependencies"} and \code{"library"} elements are overwritten by package level defaults.} } diff --git a/man/desc_add_extra_deps.Rd b/man/desc_add_extra_deps.Rd new file mode 100644 index 00000000..9442e28c --- /dev/null +++ b/man/desc_add_extra_deps.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/desc_utils.R +\name{desc_add_extra_deps} +\alias{desc_add_extra_deps} +\title{Adds extra dependencies to the \code{desc} object.} +\usage{ +desc_add_extra_deps(d, x) +} +\arguments{ +\item{d}{(\code{desc}) DESCRIPTION object from \link[desc:desc]{desc::desc}} + +\item{x}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, e.g. +\code{" ( )"} where both \code{operator} and \code{version} are optional. +Multiple entries are possible separated by \code{";"}.} +} +\value{ +\code{desc} object with added dependencies. +} +\description{ +This will add dependencies to the \code{Imports} field. +} +\examples{ +d <- desc::desc(cmd = "!new") +d <- verdepcheck:::desc_add_extra_deps(d, "foo (>= 1.2.3); bar (== 2.3.4)") +d$get_deps() +} +\keyword{internal} diff --git a/man/version_from_desc.Rd b/man/version_from_desc.Rd index 76f9f27b..78ad7988 100644 --- a/man/version_from_desc.Rd +++ b/man/version_from_desc.Rd @@ -7,7 +7,7 @@ version_from_desc(d, pkg_name) } \arguments{ -\item{d}{(\code{desc}) DESCRIPTION object from \link[desc:description]{desc::description}} +\item{d}{(\code{desc}) DESCRIPTION object from \link[desc:desc]{desc::desc}} \item{pkg_name}{(\code{character}) Package name} } From 536d2df200d52c2557efd0fb65b49bdd20a99d3b Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:31:37 +0200 Subject: [PATCH 02/13] more robust against NA --- R/desc_utils.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/desc_utils.R b/R/desc_utils.R index 28d0e5f9..def2671d 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -164,6 +164,9 @@ deparse_dep_str <- function(x) { x <- trimws(strsplit(x, "\\(")[[1]]) package <- x[1] ver_str <- gsub("\\)$", "", x[2]) + if (is.na(ver_str)) { + ver_str <- "" + } ver_str_deparsed <- deparse_ver_str(ver_str) list( package = x[1], @@ -184,7 +187,7 @@ deparse_dep_str <- function(x) { #' verdepcheck:::deparse_ver_str(">= 1.2.3") deparse_ver_str <- function(x) { x <- trimws(x) - if (x == "*" || x == "") { + if (is.na(x) || length(x) == 0 || x == "*" || x == "") { return(list(op = "", op_ver = "")) } split_vec <- strsplit(x, " ")[[1]] From 183f50720093e7982c6e54641474498f7d3e5644 Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:12:36 +0200 Subject: [PATCH 03/13] handle missing ver better --- R/desc_utils.R | 7 ++++--- man/deps_check.Rd | 4 ++-- man/deps_installation_proposal.Rd | 4 ++-- man/desc_add_extra_deps.Rd | 7 ++++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/R/desc_utils.R b/R/desc_utils.R index def2671d..842da2b8 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -137,11 +137,12 @@ desc_cond_set_refs <- function(d, refs) { #' #' @examples #' d <- desc::desc(cmd = "!new") -#' d <- verdepcheck:::desc_add_extra_deps(d, "foo (>= 1.2.3); bar (== 2.3.4)") +#' d <- verdepcheck:::desc_add_extra_deps(d, "foo (>= 1.2.3)") +#' d <- verdepcheck:::desc_add_extra_deps(d, "bar (>= 2.3.4); baz (>= 3.4.5)") #' d$get_deps() desc_add_extra_deps <- function(d, x) { if (length(x)) { - for (x_i in strsplit(x, ";")[[1]]) { + for (x_i in trimws(strsplit(x, ";")[[1]])) { x_i_deparsed <- deparse_dep_str(trimws(x_i)) d$set_dep(x_i_deparsed$package, "Imports", x_i_deparsed$ver_str) } @@ -165,7 +166,7 @@ deparse_dep_str <- function(x) { package <- x[1] ver_str <- gsub("\\)$", "", x[2]) if (is.na(ver_str)) { - ver_str <- "" + ver_str <- "*" } ver_str_deparsed <- deparse_ver_str(ver_str) list( diff --git a/man/deps_check.Rd b/man/deps_check.Rd index c4b119e2..ce7b59bc 100644 --- a/man/deps_check.Rd +++ b/man/deps_check.Rd @@ -46,8 +46,8 @@ min_isolated_deps_check( \arguments{ \item{path}{(\code{string}) path to the package sources} -\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, e.g. -\code{" ( )"} where both \code{operator} and \code{version} are optional. +\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, i.e. +\code{" ( )"} where both \verb{} and \verb{} are optional. Multiple entries are possible separated by \code{";"}.} \item{config}{(\code{list}) configuration options. See \code{\link[pkgdepends:pkg_config]{pkgdepends::pkg_config}} for details. diff --git a/man/deps_installation_proposal.Rd b/man/deps_installation_proposal.Rd index ed7033d3..246f8541 100644 --- a/man/deps_installation_proposal.Rd +++ b/man/deps_installation_proposal.Rd @@ -35,8 +35,8 @@ new_min_isolated_deps_installation_proposal( \arguments{ \item{path}{(\code{string}) path to the package sources} -\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, e.g. -\code{" ( )"} where both \code{operator} and \code{version} are optional. +\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, i.e. +\code{" ( )"} where both \verb{} and \verb{} are optional. Multiple entries are possible separated by \code{";"}.} \item{config}{(\code{list}) configuration options. See \code{\link[pkgdepends:pkg_config]{pkgdepends::pkg_config}} for details. diff --git a/man/desc_add_extra_deps.Rd b/man/desc_add_extra_deps.Rd index 9442e28c..eca12566 100644 --- a/man/desc_add_extra_deps.Rd +++ b/man/desc_add_extra_deps.Rd @@ -9,8 +9,8 @@ desc_add_extra_deps(d, x) \arguments{ \item{d}{(\code{desc}) DESCRIPTION object from \link[desc:desc]{desc::desc}} -\item{x}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, e.g. -\code{" ( )"} where both \code{operator} and \code{version} are optional. +\item{x}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, i.e. +\code{" ( )"} where both \verb{} and \verb{} are optional. Multiple entries are possible separated by \code{";"}.} } \value{ @@ -21,7 +21,8 @@ This will add dependencies to the \code{Imports} field. } \examples{ d <- desc::desc(cmd = "!new") -d <- verdepcheck:::desc_add_extra_deps(d, "foo (>= 1.2.3); bar (== 2.3.4)") +d <- verdepcheck:::desc_add_extra_deps(d, "foo (>= 1.2.3)") +d <- verdepcheck:::desc_add_extra_deps(d, "bar (>= 2.3.4); baz (>= 3.4.5)") d$get_deps() } \keyword{internal} From 4efae8158cf190ed4bd1895d6b42da5764328504 Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:29:26 +0200 Subject: [PATCH 04/13] add debug statements --- R/desc_utils.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/R/desc_utils.R b/R/desc_utils.R index 842da2b8..48ba7ecd 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -141,6 +141,10 @@ desc_cond_set_refs <- function(d, refs) { #' d <- verdepcheck:::desc_add_extra_deps(d, "bar (>= 2.3.4); baz (>= 3.4.5)") #' d$get_deps() desc_add_extra_deps <- function(d, x) { + cat("desc_add_extra_deps: \n") + cat(x) + cat("\n") + if (length(x)) { for (x_i in trimws(strsplit(x, ";")[[1]])) { x_i_deparsed <- deparse_dep_str(trimws(x_i)) @@ -162,6 +166,10 @@ desc_add_extra_deps <- function(d, x) { #' verdepcheck:::deparse_dep_str("foo") #' verdepcheck:::deparse_dep_str("foo (>= 1.2.3)") deparse_dep_str <- function(x) { + cat("deparse_dep_str: \n") + cat(x) + cat("\n") + x <- trimws(strsplit(x, "\\(")[[1]]) package <- x[1] ver_str <- gsub("\\)$", "", x[2]) @@ -187,6 +195,10 @@ deparse_dep_str <- function(x) { #' @examples #' verdepcheck:::deparse_ver_str(">= 1.2.3") deparse_ver_str <- function(x) { + cat("deparse_ver_str: \n") + cat(x) + cat("\n") + x <- trimws(x) if (is.na(x) || length(x) == 0 || x == "*" || x == "") { return(list(op = "", op_ver = "")) From db76e14e529c07b641265620e3ef2cbfe9c9370f Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:00:12 +0200 Subject: [PATCH 05/13] more debug statements --- R/desc_utils.R | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/R/desc_utils.R b/R/desc_utils.R index 48ba7ecd..638a508f 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -143,11 +143,24 @@ desc_cond_set_refs <- function(d, refs) { desc_add_extra_deps <- function(d, x) { cat("desc_add_extra_deps: \n") cat(x) + cat("strsplit:\n") + cat(strsplit(x, ";")[[1]]) + cat("\n") + cat(trimws(strsplit(x, ";")[[1]])) cat("\n") if (length(x)) { for (x_i in trimws(strsplit(x, ";")[[1]])) { - x_i_deparsed <- deparse_dep_str(trimws(x_i)) + cat("x_i: \n") + cat(x_i) + cat("\n") + + x_i_deparsed <- deparse_dep_str(x_i) + + cat("x_i_deparsed: \n") + cat(x_i_deparsed) + cat("\n") + d$set_dep(x_i_deparsed$package, "Imports", x_i_deparsed$ver_str) } } From ebf0fa3332585a0d163cdf0cf80c8b92aa9c9cda Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:12:50 +0200 Subject: [PATCH 06/13] more debug statements --- R/desc_utils.R | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/R/desc_utils.R b/R/desc_utils.R index 638a508f..4ec091f9 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -143,10 +143,18 @@ desc_cond_set_refs <- function(d, refs) { desc_add_extra_deps <- function(d, x) { cat("desc_add_extra_deps: \n") cat(x) + cat("\n") cat("strsplit:\n") cat(strsplit(x, ";")[[1]]) cat("\n") - cat(trimws(strsplit(x, ";")[[1]])) + cat("strsplit (fixed):\n") + cat(strsplit(x, ";", fixed = TRUE)[[1]]) + cat("\n") + cat("strsplit (perl):\n") + cat(strsplit(x, ";", perl = TRUE)[[1]]) + cat("\n") + cat("strsplit (useBytes):\n") + cat(strsplit(x, ";", useBytes = TRUE)[[1]]) cat("\n") if (length(x)) { @@ -156,11 +164,6 @@ desc_add_extra_deps <- function(d, x) { cat("\n") x_i_deparsed <- deparse_dep_str(x_i) - - cat("x_i_deparsed: \n") - cat(x_i_deparsed) - cat("\n") - d$set_dep(x_i_deparsed$package, "Imports", x_i_deparsed$ver_str) } } From 5640d65b27604c9388f3d53c0c00971bbbace7f0 Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:21:06 +0200 Subject: [PATCH 07/13] escape semicolon --- R/desc_utils.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/desc_utils.R b/R/desc_utils.R index 4ec091f9..02548415 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -145,20 +145,20 @@ desc_add_extra_deps <- function(d, x) { cat(x) cat("\n") cat("strsplit:\n") - cat(strsplit(x, ";")[[1]]) + cat(strsplit(x, "\\;")[[1]]) cat("\n") cat("strsplit (fixed):\n") - cat(strsplit(x, ";", fixed = TRUE)[[1]]) + cat(strsplit(x, "\\;", fixed = TRUE)[[1]]) cat("\n") cat("strsplit (perl):\n") - cat(strsplit(x, ";", perl = TRUE)[[1]]) + cat(strsplit(x, "\\;", perl = TRUE)[[1]]) cat("\n") cat("strsplit (useBytes):\n") - cat(strsplit(x, ";", useBytes = TRUE)[[1]]) + cat(strsplit(x, "\\;", useBytes = TRUE)[[1]]) cat("\n") if (length(x)) { - for (x_i in trimws(strsplit(x, ";")[[1]])) { + for (x_i in trimws(strsplit(x, "\\;")[[1]])) { cat("x_i: \n") cat(x_i) cat("\n") From b42798df02adf8e25e683027b4e6a290b9c8432a Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:29:51 +0200 Subject: [PATCH 08/13] more debug statements --- R/desc_utils.R | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/R/desc_utils.R b/R/desc_utils.R index 02548415..9eb8502d 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -142,19 +142,15 @@ desc_cond_set_refs <- function(d, refs) { #' d$get_deps() desc_add_extra_deps <- function(d, x) { cat("desc_add_extra_deps: \n") - cat(x) - cat("\n") + print(x) cat("strsplit:\n") - cat(strsplit(x, "\\;")[[1]]) - cat("\n") + print(strsplit(x, "\\;")) cat("strsplit (fixed):\n") - cat(strsplit(x, "\\;", fixed = TRUE)[[1]]) - cat("\n") + print(strsplit(x, "\\;", fixed = TRUE)) cat("strsplit (perl):\n") - cat(strsplit(x, "\\;", perl = TRUE)[[1]]) - cat("\n") + print(strsplit(x, "\\;", perl = TRUE)) cat("strsplit (useBytes):\n") - cat(strsplit(x, "\\;", useBytes = TRUE)[[1]]) + print(strsplit(x, "\\;", useBytes = TRUE)) cat("\n") if (length(x)) { From f381c5a26c1861a98cac489bdb60126c1b757c81 Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:47:54 +0200 Subject: [PATCH 09/13] rm debug prints --- R/desc_utils.R | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/R/desc_utils.R b/R/desc_utils.R index 9eb8502d..bdb556ae 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -141,24 +141,8 @@ desc_cond_set_refs <- function(d, refs) { #' d <- verdepcheck:::desc_add_extra_deps(d, "bar (>= 2.3.4); baz (>= 3.4.5)") #' d$get_deps() desc_add_extra_deps <- function(d, x) { - cat("desc_add_extra_deps: \n") - print(x) - cat("strsplit:\n") - print(strsplit(x, "\\;")) - cat("strsplit (fixed):\n") - print(strsplit(x, "\\;", fixed = TRUE)) - cat("strsplit (perl):\n") - print(strsplit(x, "\\;", perl = TRUE)) - cat("strsplit (useBytes):\n") - print(strsplit(x, "\\;", useBytes = TRUE)) - cat("\n") - if (length(x)) { for (x_i in trimws(strsplit(x, "\\;")[[1]])) { - cat("x_i: \n") - cat(x_i) - cat("\n") - x_i_deparsed <- deparse_dep_str(x_i) d$set_dep(x_i_deparsed$package, "Imports", x_i_deparsed$ver_str) } @@ -178,10 +162,6 @@ desc_add_extra_deps <- function(d, x) { #' verdepcheck:::deparse_dep_str("foo") #' verdepcheck:::deparse_dep_str("foo (>= 1.2.3)") deparse_dep_str <- function(x) { - cat("deparse_dep_str: \n") - cat(x) - cat("\n") - x <- trimws(strsplit(x, "\\(")[[1]]) package <- x[1] ver_str <- gsub("\\)$", "", x[2]) @@ -207,10 +187,6 @@ deparse_dep_str <- function(x) { #' @examples #' verdepcheck:::deparse_ver_str(">= 1.2.3") deparse_ver_str <- function(x) { - cat("deparse_ver_str: \n") - cat(x) - cat("\n") - x <- trimws(x) if (is.na(x) || length(x) == 0 || x == "*" || x == "") { return(list(op = "", op_ver = "")) From bc6ed21322079ab23a6c05c9e041223a5d068096 Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:12:07 +0200 Subject: [PATCH 10/13] fix docs; spelling and urlchecker --- _pkgdown.yml | 1 + inst/WORDLIST | 6 +----- vignettes/run_with_docker_container.Rmd | 10 +++++----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index 124a04b8..abaecc0b 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -13,6 +13,7 @@ articles: - title: Articles navbar: ~ contents: + - matches("*") reference: - title: Dependency Check diff --git a/inst/WORDLIST b/inst/WORDLIST index 6fc5163c..d98ed468 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,7 +1,3 @@ -behaviour CMD -cran -deps +RStudio pre -ver -verdepcheck diff --git a/vignettes/run_with_docker_container.Rmd b/vignettes/run_with_docker_container.Rmd index ada4f56b..e80359fb 100644 --- a/vignettes/run_with_docker_container.Rmd +++ b/vignettes/run_with_docker_container.Rmd @@ -16,7 +16,7 @@ knitr::opts_chunk$set( ``` `verdepcheck` can be used within a docker container to consistently check the version dependencies of an R package. -This vignette demonstrates how to run the [`r-verdepcheck-action`](https://github.com/insightsengineering/r-verdepcheck-action) Github workflow locally with a minimal setup. +This vignette demonstrates how to run the [`r-verdepcheck-action`](https://github.com/insightsengineering/r-verdepcheck-action) GitHub workflow locally with a minimal setup. 1. Download the docker image 1. Run the docker container @@ -29,7 +29,7 @@ _Note_: that you can skip the container setup and run the code below in your loc ### Pull and run the docker image -The docker image used in this vignette is available on the Github Container Registry (ghcr.io) and is being used by the Insights Engineering R packages (such as `teal` and `tern`). +The docker image used in this vignette is available on the GitHub Container Registry ([`ghcr.io`](https://ghcr.io)) and is being used by the Insights Engineering R packages (such as `teal` and `tern`). ```bash docker pull ghcr.io/insightsengineering/rstudio:latest @@ -38,7 +38,7 @@ docker run --rm -p 8787:8787 -e PASSWORD=test -v ./:/workspace/project ghcr.io/i ### Open the RStudio in the browser -Navigate to [http://localhost:8787](http://localhost:8788) and login with the username `rstudio` and password `test`. +Navigate to [`http://localhost:8787`] and login with the username `rstudio` and password `test`. ### Clean `pkgcache` cache before repeated runs @@ -49,7 +49,7 @@ In order to avoid using cached downloads from the previous run, it is recommend rm -rf /home/rstudio/.cache/R/pkgcache ``` -_note_: The location of the pkgcache directory may vary depending on the operation system. +_note_: The location of the `pkgcache` directory may vary depending on the operation system. Use the R command `pkgcache::pkg_cache_summary()` to find its location in your system. ### Run the code below inside the container @@ -87,7 +87,7 @@ system2( "clone", depth, ref, - sprintf("https://github.com/%s", github_id), + paste0("https://github.com/", github_id), repo_path ) |> purrr::compact() # remove empty arguments if they are NULL ) From b90ae5f878978adcf4f3e7c085c63e5adeafa8d7 Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Mon, 24 Jun 2024 17:59:40 +0200 Subject: [PATCH 11/13] raise error if dep exists; add tests --- R/desc_utils.R | 3 +++ tests/testthat/test-desc_utils.R | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/R/desc_utils.R b/R/desc_utils.R index bdb556ae..a84acbc2 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -144,6 +144,9 @@ desc_add_extra_deps <- function(d, x) { if (length(x)) { for (x_i in trimws(strsplit(x, "\\;")[[1]])) { x_i_deparsed <- deparse_dep_str(x_i) + if (any(d$get_deps()$package == x_i_deparsed$package)) { + stop("Cannot add extra dependency '", x_i_deparsed$package, "' as it already exists in DESCRIPTION file.") + } d$set_dep(x_i_deparsed$package, "Imports", x_i_deparsed$ver_str) } } diff --git a/tests/testthat/test-desc_utils.R b/tests/testthat/test-desc_utils.R index f7388d73..a363daf4 100644 --- a/tests/testthat/test-desc_utils.R +++ b/tests/testthat/test-desc_utils.R @@ -150,6 +150,18 @@ test_that("desc_remotes_cleanup accepts no Config/Need/verdepcheck", { expect_contains(clean_d$get_remotes(), "tidyverse/dplyr@*release") }) +test_that("desc_add_extra_deps will add extra dependencies", { + d <- desc::desc("!new") + d <- desc_add_extra_deps(d, "foo (>= 1.2.3)") + expect_contains(d$get_deps(), data.frame(type = "Imports", package = "foo", version = ">= 1.2.3")) +}) + +test_that("desc_add_extra_deps raises error for already existing package", { + d <- desc::desc("!new") + d$set_dep("foo", "Imports", ">= 1.2.3") + expect_error(desc_add_extra_deps(d, "foo (>= 1.2.3)"), "already exists") +}) + test_that("get_desc_field_pkgs allows for no Config/Needs/verdepcheck", { d <- desc::desc( file = verdepcheck:::local_description( From d9967798cb8b90ee189514dc64468d0b72e5271a Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:03:08 +0200 Subject: [PATCH 12/13] docs wording --- R/deps_installation_proposal.R | 2 +- man/deps_check.Rd | 2 +- man/deps_installation_proposal.Rd | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/deps_installation_proposal.R b/R/deps_installation_proposal.R index 793bb875..b9e40730 100644 --- a/R/deps_installation_proposal.R +++ b/R/deps_installation_proposal.R @@ -39,7 +39,7 @@ #' Please see also [`pkgdepends::pkg_config`] and [`pak::pak-config`] for other configuration possibilities. #' #' @param path (`string`) path to the package sources -#' @param extra_deps (`character(1)`) Extra dependencies specified similarly to the `DESCRIPTION` file, i.e. +#' @param extra_deps (`character(1)`) Extra dependencies specified similarly as in the `DESCRIPTION` file, i.e. #' `" ( )"` where both `` and `` are optional. #' Multiple entries are possible separated by `";"`. #' @param config (`list`) configuration options. See [`pkgdepends::pkg_config`] for details. diff --git a/man/deps_check.Rd b/man/deps_check.Rd index ce7b59bc..88cd6040 100644 --- a/man/deps_check.Rd +++ b/man/deps_check.Rd @@ -46,7 +46,7 @@ min_isolated_deps_check( \arguments{ \item{path}{(\code{string}) path to the package sources} -\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, i.e. +\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly as in the \code{DESCRIPTION} file, i.e. \code{" ( )"} where both \verb{} and \verb{} are optional. Multiple entries are possible separated by \code{";"}.} diff --git a/man/deps_installation_proposal.Rd b/man/deps_installation_proposal.Rd index 246f8541..6e6af34b 100644 --- a/man/deps_installation_proposal.Rd +++ b/man/deps_installation_proposal.Rd @@ -35,7 +35,7 @@ new_min_isolated_deps_installation_proposal( \arguments{ \item{path}{(\code{string}) path to the package sources} -\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, i.e. +\item{extra_deps}{(\code{character(1)}) Extra dependencies specified similarly as in the \code{DESCRIPTION} file, i.e. \code{" ( )"} where both \verb{} and \verb{} are optional. Multiple entries are possible separated by \code{";"}.} From 994e0de9539f0d8171ebd75266094d84ae71c7ac Mon Sep 17 00:00:00 2001 From: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:04:31 +0200 Subject: [PATCH 13/13] docs cont. --- R/desc_utils.R | 2 +- man/desc_add_extra_deps.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/desc_utils.R b/R/desc_utils.R index a84acbc2..492be862 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -127,7 +127,7 @@ desc_cond_set_refs <- function(d, refs) { #' This will add dependencies to the `Imports` field. #' #' @param d (`desc`) DESCRIPTION object from [desc::desc] -#' @param x (`character(1)`) Extra dependencies specified similarly to the `DESCRIPTION` file, i.e. +#' @param x (`character(1)`) Extra dependencies specified similarly as in the `DESCRIPTION` file, i.e. #' `" ( )"` where both `` and `` are optional. #' Multiple entries are possible separated by `";"`. #' diff --git a/man/desc_add_extra_deps.Rd b/man/desc_add_extra_deps.Rd index eca12566..065ec758 100644 --- a/man/desc_add_extra_deps.Rd +++ b/man/desc_add_extra_deps.Rd @@ -9,7 +9,7 @@ desc_add_extra_deps(d, x) \arguments{ \item{d}{(\code{desc}) DESCRIPTION object from \link[desc:desc]{desc::desc}} -\item{x}{(\code{character(1)}) Extra dependencies specified similarly to the \code{DESCRIPTION} file, i.e. +\item{x}{(\code{character(1)}) Extra dependencies specified similarly as in the \code{DESCRIPTION} file, i.e. \code{" ( )"} where both \verb{} and \verb{} are optional. Multiple entries are possible separated by \code{";"}.} }