Fix detection of change in dependency #1807
Merged
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.
This should fix the failing main branch
In #1789, support was added for the imports field of
use_standalone()
and internally that useduse_package()
to add the required packages to Imports.use_package()
calleduse_dependency()
, and I thinkuse_dependency()
had a small bug in it, which I'll explain below.The changes caused this test to fail because of snapshot changes
usethis/tests/testthat/test-tidyverse.R
Lines 15 to 23 in a336c67
Specifically it was adding this to the snapshots
But that is weird, because
use_tidy_dependencies()
already calleduse_package("rlang")
up above, and its usage ofuse_standalone("r-lib/rlang", "purrr")
should not have caused a "change" in package dependency type that should trigger thishow_to_use()
line inuse_package()
, but it obviously does:usethis/R/package.R
Lines 40 to 43 in a336c67
For reference the rlang standalone file does not use a versioned version of rlang
https://github.com/r-lib/rlang/blob/9b450274026baa46aa8f4520fdefd87de02e4565/R/standalone-purrr.R#L6
Turns out
use_dependency()
was actually returningTRUE
here by mistake, because there isn't adelta == 0L
branch that exits and returnsFALSE
(i.e. the case of package exists and no change in version). I've tweakeduse_dependency()
to have achanged
variable that keeps track of whether or not something has changed in the DESCRIPTION file (i.e.changed <- TRUE
always follows adesc$write()
call).This change results in a snapshot change that I actually think is a bug fix, because now 2 calls to
use_package("withr")
results in the 2nd call being completely silentI also sort of question the usage of
use_package()
inuse_standalone()
over the quieteruse_dependency()
, but that is a separate issue, since this one is clearly a bug.