[mirror] Opinionated R package quickstart
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update wordlist; add AGENTS to build ignore

VisruthSK 288f318c 46c1b14b

+132 -9
+1
.Rbuildignore
··· 5 5 ^[.]?air[.]toml$ 6 6 ^\.vscode$ 7 7 ^LICENSE\.md$ 8 + ^AGENTS\.md$
+1
NAMESPACE
··· 6 6 export(setup_agents) 7 7 export(setup_dependabot) 8 8 export(setup_gha) 9 + export(setup_precommit) 9 10 export(use_license) 10 11 importFrom(utils,person)
+23 -2
R/bootstrapper.R
··· 9 9 #' @param setup_gha Whether to configure GitHub Actions setup. 10 10 #' @param setup_dependabot Whether to write a Dependabot configuration. 11 11 #' @param setup_AGENTS Whether to write a default AGENTS file. 12 + #' @param setup_precommit Whether to write a Bash pre-commit hook. 12 13 #' @param ... Additional arguments passed to [usethis::create_package()]. 13 14 #' 14 15 #' @return Invisibly returns `NULL`. ··· 20 21 setup_gha = TRUE, 21 22 setup_dependabot = TRUE, 22 23 setup_AGENTS = FALSE, 24 + setup_precommit = TRUE, 23 25 ... 24 26 ) { 25 27 create_package(path, fields, private, ...) 26 28 pkg_setup( 27 29 setup_gha = setup_gha, 28 30 setup_dependabot = setup_dependabot, 29 - setup_AGENTS = setup_AGENTS 31 + setup_AGENTS = setup_AGENTS, 32 + setup_precommit = setup_precommit 30 33 ) 31 34 invisible(NULL) 32 35 } ··· 88 91 #' @param setup_gha Whether to configure GitHub Actions setup. 89 92 #' @param setup_dependabot Whether to write a Dependabot configuration. 90 93 #' @param setup_AGENTS Whether to write a default AGENTS file. 94 + #' @param setup_precommit Whether to write a Bash pre-commit hook. 91 95 #' 92 96 #' @return Invisibly returns `NULL`. 93 97 #' @export 94 98 pkg_setup <- function( 95 99 setup_gha = TRUE, 96 100 setup_dependabot = TRUE, 97 - setup_AGENTS = FALSE 101 + setup_AGENTS = FALSE, 102 + setup_precommit = TRUE 98 103 ) { 99 104 tryCatch( 100 105 usethis::use_testthat(), ··· 121 126 } 122 127 if (setup_AGENTS) { 123 128 setup_agents() 129 + } 130 + if (setup_precommit) { 131 + setup_precommit() 124 132 } 125 133 126 134 try_air_jarl_format() ··· 215 223 #' @export 216 224 setup_agents <- function() { 217 225 copy_template_file("AGENTS.md", "AGENTS.md") 226 + usethis::use_build_ignore("AGENTS.md") 227 + } 228 + 229 + #' Configure Pre-Commit Hook 230 + #' 231 + #' Writes a Bash pre-commit hook that runs format and lint checks. 232 + #' 233 + #' @return Invisibly returns `NULL`. 234 + #' @export 235 + setup_precommit <- function() { 236 + copy_template_file("pre-commit", fs::path(".git", "hooks", "pre-commit")) 237 + Sys.chmod(fs::path(".git", "hooks", "pre-commit"), mode = "0755") 238 + invisible(NULL) 218 239 } 219 240 220 241 #' Choose and Apply a License
+5 -1
inst/WORDLIST
··· 1 1 CMD 2 2 Codecov 3 - GHA 3 + Dependabot 4 + Jarl 4 5 Kandali 5 6 ORCID 7 + Pre 6 8 Quickstart 7 9 README 8 10 Srimath 11 + md 12 + pre
+5
inst/templates/pre-commit
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + air format . 5 + jarl check . --fix --allow-dirty
+3
man/bootstrapper.Rd
··· 11 11 setup_gha = TRUE, 12 12 setup_dependabot = TRUE, 13 13 setup_AGENTS = FALSE, 14 + setup_precommit = TRUE, 14 15 ... 15 16 ) 16 17 } ··· 27 28 \item{setup_dependabot}{Whether to write a Dependabot configuration.} 28 29 29 30 \item{setup_AGENTS}{Whether to write a default AGENTS file.} 31 + 32 + \item{setup_precommit}{Whether to write a Bash pre-commit hook.} 30 33 31 34 \item{...}{Additional arguments passed to \code{\link[usethis:create_package]{usethis::create_package()}}.} 32 35 }
+8 -1
man/pkg_setup.Rd
··· 4 4 \alias{pkg_setup} 5 5 \title{Apply Opinionated Package Setup} 6 6 \usage{ 7 - pkg_setup(setup_gha = TRUE, setup_dependabot = TRUE, setup_AGENTS = FALSE) 7 + pkg_setup( 8 + setup_gha = TRUE, 9 + setup_dependabot = TRUE, 10 + setup_AGENTS = FALSE, 11 + setup_precommit = TRUE 12 + ) 8 13 } 9 14 \arguments{ 10 15 \item{setup_gha}{Whether to configure GitHub Actions setup.} ··· 12 17 \item{setup_dependabot}{Whether to write a Dependabot configuration.} 13 18 14 19 \item{setup_AGENTS}{Whether to write a default AGENTS file.} 20 + 21 + \item{setup_precommit}{Whether to write a Bash pre-commit hook.} 15 22 } 16 23 \value{ 17 24 Invisibly returns \code{NULL}.
+14
man/setup_precommit.Rd
··· 1 + % Generated by roxygen2: do not edit by hand 2 + % Please edit documentation in R/bootstrapper.R 3 + \name{setup_precommit} 4 + \alias{setup_precommit} 5 + \title{Configure Pre-Commit Hook} 6 + \usage{ 7 + setup_precommit() 8 + } 9 + \value{ 10 + Invisibly returns \code{NULL}. 11 + } 12 + \description{ 13 + Writes a Bash pre-commit hook that runs format and lint checks. 14 + }
+72 -5
tests/testthat/test-bootstrapper.R
··· 10 10 expect_identical(list(...), list(open = FALSE)) 11 11 NULL 12 12 }, 13 - pkg_setup = function(setup_gha, setup_dependabot, setup_AGENTS) { 13 + pkg_setup = function( 14 + setup_gha, 15 + setup_dependabot, 16 + setup_AGENTS, 17 + setup_precommit 18 + ) { 14 19 calls <<- c(calls, "pkg_setup") 15 20 expect_false(setup_gha) 16 21 expect_false(setup_dependabot) 17 22 expect_false(setup_AGENTS) 23 + expect_false(setup_precommit) 18 24 NULL 19 25 }, 20 26 .package = "bootstrapper" ··· 27 33 private = FALSE, 28 34 setup_gha = FALSE, 29 35 setup_dependabot = FALSE, 36 + setup_precommit = FALSE, 30 37 open = FALSE 31 38 ) 32 39 ) ··· 123 130 calls$sections <<- c(calls$sections, "agents") 124 131 NULL 125 132 }, 133 + setup_precommit = function() { 134 + calls$sections <<- c(calls$sections, "precommit") 135 + NULL 136 + }, 126 137 find_replace_in_file = function(from, to, file, fixed = TRUE) { 127 138 calls$replaced <<- TRUE 128 139 expect_identical(from, "(development version)") ··· 144 155 expect_true("readme:FALSE" %in% calls$actions) 145 156 expect_true("news:FALSE" %in% calls$actions) 146 157 expect_true("tidy_description" %in% calls$actions) 147 - expect_identical(calls$sections, c("gha", "dependabot")) 158 + expect_identical(calls$sections, c("gha", "dependabot", "precommit")) 148 159 expect_true(calls$replaced) 149 160 expect_true(calls$formatted) 150 161 }) ··· 174 185 called <<- TRUE 175 186 NULL 176 187 }, 188 + setup_precommit = function() { 189 + called <<- TRUE 190 + NULL 191 + }, 177 192 find_replace_in_file = function(from, to, file, fixed = TRUE) NULL, 178 193 try_air_jarl_format = function() { 179 194 formatted <<- TRUE ··· 186 201 bootstrapper::pkg_setup( 187 202 setup_gha = FALSE, 188 203 setup_dependabot = FALSE, 189 - setup_AGENTS = FALSE 204 + setup_AGENTS = FALSE, 205 + setup_precommit = FALSE 190 206 ) 191 207 ) 192 208 expect_false(called) ··· 216 232 .package = "bootstrapper" 217 233 ) 218 234 219 - expect_null(bootstrapper::pkg_setup(setup_AGENTS = TRUE)) 235 + expect_null(bootstrapper::pkg_setup( 236 + setup_AGENTS = TRUE, 237 + setup_precommit = FALSE 238 + )) 220 239 expect_true(called) 221 240 }) 222 241 ··· 277 296 actions$replacements, 278 297 c( 279 298 "actions/checkout@v4 -> actions/checkout@v6", 299 + "actions/upload-artifact@v4 -> actions/upload-artifact@v6", 280 300 "JamesIves/github-pages-deploy-action@v4.5.0 -> JamesIves/github-pages-deploy-action@v4" 281 301 ) 282 302 ) ··· 310 330 311 331 test_that("setup_agents copies AGENTS template", { 312 332 setup_agents <- getFromNamespace("setup_agents", "bootstrapper") 313 - captured <- list(template_file = NULL, destination = NULL) 333 + captured <- list( 334 + template_file = NULL, 335 + destination = NULL, 336 + build_ignore = NULL 337 + ) 314 338 315 339 testthat::local_mocked_bindings( 316 340 copy_template_file = function(template_file, destination) { ··· 321 345 .package = "bootstrapper" 322 346 ) 323 347 348 + testthat::local_mocked_bindings( 349 + use_build_ignore = function(path, ...) { 350 + captured$build_ignore <<- path 351 + NULL 352 + }, 353 + .package = "usethis" 354 + ) 355 + 324 356 expect_null(setup_agents()) 325 357 expect_identical(captured$template_file, "AGENTS.md") 326 358 expect_identical(captured$destination, "AGENTS.md") 359 + expect_identical(captured$build_ignore, "AGENTS.md") 360 + }) 361 + 362 + test_that("setup_precommit writes a bash hook and marks it executable", { 363 + setup_precommit <- getFromNamespace("setup_precommit", "bootstrapper") 364 + captured <- list(template_file = NULL, destination = NULL, chmod = NULL) 365 + 366 + testthat::local_mocked_bindings( 367 + copy_template_file = function(template_file, destination) { 368 + captured$template_file <<- template_file 369 + captured$destination <<- destination 370 + NULL 371 + }, 372 + .package = "bootstrapper" 373 + ) 374 + 375 + testthat::local_mocked_bindings( 376 + Sys.chmod = function(paths, mode = "0777", use_umask = TRUE) { 377 + captured$chmod <<- list(paths = paths, mode = mode) 378 + TRUE 379 + }, 380 + .package = "base" 381 + ) 382 + 383 + expect_null(setup_precommit()) 384 + expect_identical(captured$template_file, "pre-commit") 385 + expect_identical( 386 + captured$destination, 387 + fs::path(".git", "hooks", "pre-commit") 388 + ) 389 + expect_identical( 390 + captured$chmod$paths, 391 + fs::path(".git", "hooks", "pre-commit") 392 + ) 393 + expect_identical(captured$chmod$mode, "0755") 327 394 }) 328 395 329 396 test_that("pkg_setup rethrows a generic message when test setup fails", {