-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Polish code and docs re: options for DESCRIPTION fields #367
Conversation
No need to consult options (usethis or devtools) twice
R/description.R
Outdated
@@ -48,22 +58,15 @@ build_description <- function(name, fields = list()) { | |||
} | |||
|
|||
build_description_list <- function(name, fields = list()) { | |||
author <- getOption("devtools.desc.author") %||% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're abandoning these individual options in favour of the omnibus usethis.description
? If yes, need to call out in the NEWS (although it probably doesn't affect many people)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I failed to see that this wasn't just grabbing the "author" element of the "devtools.desc" list.
But it does seem like something we could probably drop. Or switch entirely to "devtools.desc.XYZ". Supporting usethis and devtools options, in individual and ombibus form seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm fine with dropping it.
R/description.R
Outdated
getOption("devtools.desc") %||% | ||
list() | ||
## the definitive source of user-supplied info: in this call or via options | ||
fields <- utils::modifyList( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth doing some light type checking here - e.g. that it's a list with names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And should all this logic be moved into build_description()
? I think that would make the tests simpler since you wouldn't need so many temporary projects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to move things around.
Part of the reason I tested via use_description()
, though, was to test that directly specified fields override options & defaults, but in a targetted manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it would be better to move all that code out so you can test independently of the writing.
I think this does everything we discussed @hadley:
|
R/description.R
Outdated
#' } | ||
use_description <- function(fields = NULL) { | ||
name <- project_name() | ||
check_package_name(name) | ||
if (!is.null(fields)) check_is_named_list(fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you moved this one line lower you could drop the conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ByteCompile = "true" | ||
build_description_list <- function(fields = list()) { | ||
defaults <- use_description_defaults() | ||
defaults <- utils::modifyList( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels to me like this belongs in use_description_defaults()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually made use_description_defaults()
"data only" on purpose. It's the only easy way to see the usethis field defaults w/o reading source. Unless you care deeply, will leave this.
context("use_description") | ||
|
||
test_that("build_description_list() defaults to values built into usethis", { | ||
withr::with_options( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's easier to read if you use local_options()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AHA! done.
fields = list(Title = "aaa", URL = "https://www.r-project.org") | ||
) | ||
## from user's fields | ||
expect_identical(d$Title, "aaa") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why test two fields from each case? Isn't one enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One is an overwrite, one is novel. But I did remove one test case re: default values.
Closes #233 create_package() should document options
Closes #159 Review all uses of getOption("devtools.SOMETHING")
Rationalize and document the use of options and internal defaults re: DESCRIPTION fields. Key principles:
modifyList()
mentality vs. the "all or nothing" mentality of%||%