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

Add extra #49

Merged
merged 13 commits into from
Jun 25, 2024
Merged
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
12 changes: 8 additions & 4 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
}

Expand All @@ -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, ...)
}

Expand All @@ -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, ...)
}

Expand All @@ -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, ...)
}

Expand Down
11 changes: 11 additions & 0 deletions R/deps_installation_proposal.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 as in the `DESCRIPTION` file, i.e.
#' `"<package name> (<operator> <version>)"` where both `<operator>` and `<version>` 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.
#'
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
101 changes: 90 additions & 11 deletions R/desc_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,85 @@ 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 as in the `DESCRIPTION` file, i.e.
#' `"<package name> (<operator> <version>)"` where both `<operator>` and `<version>` 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)")
#' 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 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)
}
}
return(invisible(d))
}

#' Deparse a dependency string
#'
#' @param x (`character`) Dependency string in form of `<package name> (<operator> <version>)`. 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])
if (is.na(ver_str)) {
ver_str <- "*"
}
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 `<operator> <version>`. 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 (is.na(x) || length(x) == 0 || 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
Expand All @@ -137,7 +216,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
#'
Expand All @@ -152,20 +231,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
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ articles:
- title: Articles
navbar: ~
contents:
- matches("*")

reference:
- title: Dependency Check
Expand Down
6 changes: 1 addition & 5 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
behaviour
CMD
cran
deps
RStudio
pre
ver
verdepcheck
22 changes: 22 additions & 0 deletions man/deparse_dep_str.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/deparse_ver_str.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/deps_check.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading