Skip to content

Commit 4144936

Browse files
committed
Update uses_WHATEVER() functions
These `base_path` arguments are NEVER used in earnest. Their existence feels like it dates back to before we truly embraced the notion of the active project. And remember `with_project()` and `local_project()` are always available for the very rare situation where you want to use usethis functions on something other than active project.
1 parent 8aaf785 commit 4144936

File tree

8 files changed

+67
-83
lines changed

8 files changed

+67
-83
lines changed

R/description.R

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,10 @@ tidy_desc <- function(desc) {
171171
#
172172
# I won't change use_description_field() now, but use_description_list() is
173173
# implemented differently, more in keeping with our current style
174-
use_description_field <- function(name,
175-
value,
176-
base_path = proj_get(),
177-
overwrite = FALSE) {
174+
use_description_field <- function(name, value, overwrite = FALSE) {
178175
# account for `value`s produced via `glue::glue()`
179176
value <- as.character(value)
180-
curr <- desc::desc_get(name, file = base_path)[[1]]
177+
curr <- desc::desc_get(name, file = proj_get())[[1]]
181178
curr <- gsub("^\\s*|\\s*$", "", curr)
182179

183180
if (identical(curr, value)) {
@@ -192,7 +189,7 @@ use_description_field <- function(name,
192189
}
193190

194191
ui_done("Setting {ui_field(name)} field in DESCRIPTION to {ui_value(value)}")
195-
desc::desc_set(name, value, file = base_path)
192+
desc::desc_set(name, value, file = proj_get())
196193
invisible()
197194
}
198195

R/github-actions.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ use_github_actions_badge <- function(name = "R-CMD-check", repo_spec = NULL) {
7676
use_badge(name, url, img)
7777
}
7878

79-
uses_github_actions <- function(base_path = proj_get()) {
80-
path <- glue("{base_path}/.github/workflows")
79+
uses_github_actions <- function() {
80+
path <- proj_path(".github", "workflows")
8181
file_exists(path)
8282
}
8383

84-
check_uses_github_actions <- function(base_path = proj_get()) {
85-
if (uses_github_actions(base_path)) {
84+
check_uses_github_actions <- function() {
85+
if (uses_github_actions()) {
8686
return(invisible())
8787
}
8888

8989
ui_stop("
90-
Cannot detect that package {ui_value(project_name(base_path))} already \\
90+
Cannot detect that package {ui_value(project_name())} already \\
9191
uses GitHub Actions.
9292
Do you need to run {ui_code('use_github_actions()')}?")
9393
}

R/make.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@ use_make <- function() {
1212
)
1313
use_build_ignore("Makefile")
1414
}
15-
16-
uses_make <- function(base_path = proj_get()) {
17-
makefile_path <- proj_path("Makefile")
18-
file_exists(makefile_path)
19-
}

R/pkgdown.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ tidyverse_url <- function(url, tr = NULL) {
139139
}
140140
}
141141

142-
pkgdown_config_path <- function(base_path = proj_get()) {
142+
pkgdown_config_path <- function() {
143143
path_first_existing(
144-
path(
145-
base_path,
144+
proj_path(
146145
c(
147146
"_pkgdown.yml",
148147
"_pkgdown.yaml",
@@ -153,24 +152,24 @@ pkgdown_config_path <- function(base_path = proj_get()) {
153152
)
154153
}
155154

156-
uses_pkgdown <- function(base_path = proj_get()) {
157-
!is.null(pkgdown_config_path(base_path))
155+
uses_pkgdown <- function() {
156+
!is.null(pkgdown_config_path())
158157
}
159158

160-
pkgdown_config_meta <- function(base_path = proj_get()) {
161-
if (!uses_pkgdown(base_path)) {
159+
pkgdown_config_meta <- function() {
160+
if (!uses_pkgdown()) {
162161
return(list())
163162
}
164-
path <- pkgdown_config_path(base_path)
163+
path <- pkgdown_config_path()
165164
yaml::read_yaml(path) %||% list()
166165
}
167166

168-
pkgdown_url <- function(base_path = proj_get(), pedantic = FALSE) {
169-
if (!uses_pkgdown(base_path)) {
167+
pkgdown_url <- function(pedantic = FALSE) {
168+
if (!uses_pkgdown()) {
170169
return(NULL)
171170
}
172171

173-
meta <- pkgdown_config_meta(base_path)
172+
meta <- pkgdown_config_meta()
174173
url <- meta$url
175174
if (is.null(url)) {
176175
if (pedantic) {

R/roxygen.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ use_roxygen_md <- function() {
3232
invisible()
3333
}
3434

35-
uses_roxygen_md <- function(base_path = proj_get()) {
36-
if (!desc::desc_has_fields("Roxygen", base_path)) {
35+
uses_roxygen_md <- function() {
36+
if (!desc::desc_has_fields("Roxygen", file = proj_get())) {
3737
return(FALSE)
3838
}
3939

40-
roxygen <- desc::desc_get("Roxygen", base_path)[[1]]
40+
roxygen <- desc::desc_get("Roxygen", file = proj_get())[[1]]
4141
value <- tryCatch(
4242
{
4343
eval(parse(text = roxygen))
@@ -50,8 +50,8 @@ uses_roxygen_md <- function(base_path = proj_get()) {
5050
isTRUE(value$markdown)
5151
}
5252

53-
uses_roxygen <- function(base_path = proj_get()) {
54-
desc::desc_has_fields("RoxygenNote", base_path)
53+
uses_roxygen <- function() {
54+
desc::desc_has_fields("RoxygenNote", file = proj_get())
5555
}
5656

5757
roxygen_ns_append <- function(tag) {

R/test.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ check_edition <- function(edition = NULL) {
8181
}
8282

8383

84-
uses_testthat <- function(base_path = proj_get()) {
85-
paths <- c(
86-
path(base_path, "inst", "tests"),
87-
path(base_path, "tests", "testthat")
88-
)
89-
84+
uses_testthat <- function() {
85+
paths <- proj_path(c(path("inst", "tests"), path("tests", "testthat")))
9086
any(dir_exists(paths))
9187
}

tests/testthat/test-description.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,45 @@ test_that("use_description_list() can initiate, add to, or replace", {
125125
desc <- desc::desc()
126126
expect_equal(desc$get_list("Config/Needs/foofy"), "charlie")
127127
})
128+
129+
130+
test_that("use_description_field() can address an existing field", {
131+
pkg <- create_local_package()
132+
orig <- tools::md5sum(proj_path("DESCRIPTION"))
133+
134+
## specify existing value of existing field --> should be no op
135+
use_description_field(
136+
name = "Version",
137+
value = desc::desc_get("Version", file = pkg)[[1]]
138+
)
139+
expect_identical(orig, tools::md5sum(proj_path("DESCRIPTION")))
140+
141+
expect_usethis_error(
142+
use_description_field(
143+
name = "Version",
144+
value = "1.1.1"
145+
),
146+
"has a different value"
147+
)
148+
149+
## overwrite existing field
150+
use_description_field(
151+
name = "Version",
152+
value = "1.1.1",
153+
overwrite = TRUE
154+
)
155+
expect_identical(c(Version = "1.1.1"), desc::desc_get("Version", file = pkg))
156+
})
157+
158+
test_that("use_description_field() can add new field", {
159+
pkg <- create_local_package()
160+
use_description_field(name = "foo", value = "bar")
161+
expect_identical(c(foo = "bar"), desc::desc_get("foo", file = pkg))
162+
})
163+
164+
test_that("use_description_field() ignores whitespace", {
165+
pkg <- create_local_package()
166+
use_description_field(name = "foo", value = "\n bar")
167+
use_description_field(name = "foo", value = "bar")
168+
expect_identical(c(foo = "\n bar"), desc::desc_get("foo", file = pkg))
169+
})

tests/testthat/test-helpers.R

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,3 @@
1-
2-
test_that("use_description_field() can address an existing field", {
3-
pkg <- create_local_package()
4-
orig <- tools::md5sum(proj_path("DESCRIPTION"))
5-
6-
## specify existing value of existing field --> should be no op
7-
use_description_field(
8-
name = "Version",
9-
value = desc::desc_get("Version", pkg)[[1]],
10-
base_path = pkg
11-
)
12-
expect_identical(orig, tools::md5sum(proj_path("DESCRIPTION")))
13-
14-
expect_usethis_error(
15-
use_description_field(
16-
name = "Version",
17-
value = "1.1.1",
18-
base_path = pkg
19-
),
20-
"has a different value"
21-
)
22-
23-
## overwrite existing field
24-
use_description_field(
25-
name = "Version",
26-
value = "1.1.1",
27-
base_path = pkg,
28-
overwrite = TRUE
29-
)
30-
expect_identical(c(Version = "1.1.1"), desc::desc_get("Version", pkg))
31-
})
32-
33-
test_that("use_description_field() can add new field", {
34-
pkg <- create_local_package()
35-
use_description_field(name = "foo", value = "bar", base_path = pkg)
36-
expect_identical(c(foo = "bar"), desc::desc_get("foo", pkg))
37-
})
38-
39-
test_that("use_description_field() ignores whitespace", {
40-
pkg <- create_local_package()
41-
use_description_field(name = "foo", value = "\n bar")
42-
use_description_field(name = "foo", value = "bar")
43-
expect_identical(c(foo = "\n bar"), desc::desc_get("foo", pkg))
44-
})
45-
461
test_that("valid_package_name() enforces valid package names", {
472
# Contain only ASCII letters, numbers, and '.'
483
# Have at least two characters

0 commit comments

Comments
 (0)