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

Let use_package() decrement a package dependency. #2043

Merged
merged 7 commits into from
Aug 15, 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
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# usethis (development version)

## Bug fixes and minor improvements

* `use_package()` now decreases a package minimum version required when
`min_version` is lower than what is currently specified in the DESCRIPTION
file (@jplecavalier, #1957).

* `use_data()` now uses serialization version 3 by default. (@laurabrianna, #2044)

* Reverse dependency checks are only suggested if they exist
(#1817, @seankross).

Expand Down
27 changes: 15 additions & 12 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ use_dependency <- function(package, type, min_version = NULL) {
"!" = "Package {.pkg {package}} is already listed in
{.field {existing_type}} in DESCRIPTION; no change made."
))
} else if (delta == 0 && !is.null(min_version)) {
# change version
upgrade <- existing_version == "*" ||
numeric_version(min_version) > version_spec(existing_version)
if (upgrade) {
ui_bullets(c(
"v" = "Increasing {.pkg {package}} version to {.val {version}} in
DESCRIPTION."
))
desc$set_dep(package, type, version = version)
desc$write()
changed <- TRUE
} else if (delta == 0 && version_spec(version) != version_spec(existing_version)) {
if (version_spec(version) > version_spec(existing_version)) {
direction <- "Increasing"
} else {
direction <- "Decreasing"
}

ui_bullets(c(
"v" = "{direction} {.pkg {package}} version to {.val {version}} in
DESCRIPTION."
))
desc$set_dep(package, type, version = version)
desc$write()
changed <- TRUE

} else if (delta > 0) {
# moving from, e.g., Suggests to Imports
ui_bullets(c(
Expand All @@ -96,6 +98,7 @@ r_version <- function() {
}

version_spec <- function(x) {
if (x == "*") x <- "0"
x <- gsub("(<=|<|>=|>|==)\\s*", "", x)
numeric_version(x)
}
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
Message
v Increasing crayon version to ">= 2.0.0" in DESCRIPTION.

---

Code
use_dependency("crayon", "Imports", min_version = "1.0.0")
Message
v Decreasing crayon version to ">= 1.0.0" in DESCRIPTION.

# use_dependency() upgrades a dependency

Code
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ test_that("we message for version change and are silent for same version", {
expect_snapshot(
use_dependency("crayon", "Imports", min_version = "2.0.0")
)
expect_silent(use_dependency("crayon", "Imports", min_version = "1.0.0"))
expect_snapshot(
use_dependency("crayon", "Imports", min_version = "1.0.0")
)
})

## https://github.com/r-lib/usethis/issues/99
Expand Down
Loading