Skip to content

Commit

Permalink
Merge pull request #139 from ropensci/devtools
Browse files Browse the repository at this point in the history
Reduce number of dependencies
  • Loading branch information
slager authored Apr 27, 2024
2 parents d52b5a4 + 8a73c02 commit 65d392d
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 45 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ Imports:
desc,
yaml,
purrr,
roxygen2 (>= 6.0.1),
devtools (>= 1.12.0),
roxygen2,
stringr,
futile.logger,
rprojroot,
usethis,
crayon,
withr
pkgbuild,
pkgload
VignetteBuilder: knitr
RoxygenNote: 7.3.1
Encoding: UTF-8
Expand All @@ -69,9 +69,10 @@ Suggests:
testthat,
covr,
data.tree,
withr
URL:
https://github.com/ropensci/DataPackageR/,
https://github.com/ropensci/DataPackageR,
https://docs.ropensci.org/DataPackageR/
BugReports: https://github.com/ropensci/DataPackageR/issues
SystemRequirements: pandoc (>= 1.12.3) - http://pandoc.org
SystemRequirements: pandoc (>= 1.12.3) - https://pandoc.org
Language: en-US
7 changes: 0 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export(yml_write)
importFrom(crayon,bold)
importFrom(crayon,green)
importFrom(desc,desc)
importFrom(devtools,build)
importFrom(devtools,build_vignettes)
importFrom(devtools,parse_deps)
importFrom(devtools,reload)
importFrom(futile.logger,INFO)
importFrom(futile.logger,TRACE)
importFrom(futile.logger,appender.console)
Expand All @@ -53,8 +49,6 @@ importFrom(knitr,spin)
importFrom(purrr,map)
importFrom(rmarkdown,pandoc_available)
importFrom(rmarkdown,render)
importFrom(roxygen2,roxygenise)
importFrom(roxygen2,roxygenize)
importFrom(rprojroot,is_r_package)
importFrom(stringr,str_trim)
importFrom(usethis,create_package)
Expand All @@ -64,7 +58,6 @@ importFrom(usethis,use_build_ignore)
importFrom(usethis,use_data_raw)
importFrom(usethis,use_directory)
importFrom(usethis,use_rstudio)
importFrom(withr,with_options)
importFrom(yaml,as.yaml)
importFrom(yaml,read_yaml)
importFrom(yaml,write_yaml)
Expand Down
2 changes: 1 addition & 1 deletion R/DataPackageR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#' package_build(file.path(tempdir(), pname), install = FALSE)
#'
#' # "install" the data package
#' devtools::load_all(file.path(tempdir(), pname))
#' pkgload::load_all(file.path(tempdir(), pname))
#'
#' # read the data version
#' data_version(pname)
Expand Down
12 changes: 5 additions & 7 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#' @param install \code{logical} automatically install and load the package after building. Default FALSE
#' @param ... additional arguments passed to \code{install.packages} when \code{install=TRUE}.
#' @returns Character vector. File path of the built package.
#' @importFrom roxygen2 roxygenise roxygenize
#' @importFrom devtools build_vignettes build parse_deps reload
#' @importFrom usethis use_build_ignore use_rstudio proj_set use_directory
#' @importFrom rprojroot is_r_package
#' @importFrom rmarkdown pandoc_available
Expand Down Expand Up @@ -97,15 +95,15 @@ package_build <- function(packageName = NULL,
.multilog_trace("Building documentation")
local({
on.exit({
if (packageName %in% devtools::package_info('attached')$package){
devtools::unload(packageName)
if (packageName %in% names(utils::sessionInfo()$otherPkgs)){
pkgload::unload(packageName)
}
})
roxygen2::roxygenise(package_path, clean = TRUE)
roxygen2::roxygenize(package_path, clean = TRUE)
})
.multilog_trace("Building package")
location <- build(package_path,
path = dirname(package_path),
location <- pkgbuild::build(path = package_path,
dest_path = dirname(package_path),
vignettes = vignettes,
quiet = ! getOption('DataPackageR_verbose', TRUE)
)
Expand Down
4 changes: 2 additions & 2 deletions R/dataversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#'
#' package_build(file.path(tempdir(),pname), install = FALSE)
#'
#' devtools::load_all(file.path(tempdir(),pname))
#' pkgload::load_all(file.path(tempdir(),pname))
#' data_version(pname)
#' }
data_version <- function(pkg, lib.loc = NULL) {
Expand Down Expand Up @@ -98,7 +98,7 @@ data_version <- function(pkg, lib.loc = NULL) {
#' code_files = f)
#' package_build(file.path(tempdir(),pname), install = FALSE)
#'
#' devtools::load_all(file.path(tempdir(),pname))
#' pkgload::load_all(file.path(tempdir(),pname))
#'
#' assert_data_version(data_package_name = pname,version_string = "0.1.0",acceptable = "equal")
#' }
Expand Down
16 changes: 9 additions & 7 deletions R/processData.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
#' @noRd
DataPackageR <- function(arg = NULL, deps = TRUE) {
if (! getOption('DataPackageR_verbose', TRUE)){
withr::local_options(list(usethis.quiet = TRUE))
old_usethis_quiet <- getOption('usethis.quiet')
on.exit(options(usethis.quiet = old_usethis_quiet))
options(usethis.quiet = TRUE)
}
pkg_dir <- arg
if (getOption('DataPackageR_verbose', TRUE)) cat("\n")
usethis::proj_set(path = pkg_dir)

#set the option that DataPackageR is building the package. On exit ensures when it leaves, it will set it back to false
options("DataPackageR_packagebuilding" = TRUE)
on.exit(options("DataPackageR_packagebuilding" = FALSE))
on.exit(options("DataPackageR_packagebuilding" = FALSE), add = TRUE)

# validate that render_root exists.
# if it's an old temp dir, what then?
Expand Down Expand Up @@ -769,14 +771,14 @@ document <- function(path = ".", install = FALSE, ...) {
.multilog_trace("Rebuilding data package documentation.")
local({
on.exit({
if (basename(path) %in% devtools::package_info('attached')$package){
devtools::unload(basename(path))
if (basename(path) %in% names(utils::sessionInfo()$otherPkgs)){
pkgload::unload(basename(path))
}
})
devtools::document(pkg = path)
roxygen2::roxygenize(package.dir = path)
})
location <- devtools::build(
pkg = path, path = dirname(path),
location <- pkgbuild::build(
path = path, dest_path = dirname(path),
vignettes = FALSE, quiet = TRUE
)
# try to install and then reload the package in the current session
Expand Down
4 changes: 3 additions & 1 deletion R/skeleton.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ datapackage_skeleton <-
raw_data_dir = character(),
dependencies = character()) {
if (! getOption('DataPackageR_verbose', TRUE)){
withr::local_options(list(usethis.quiet = TRUE))
old_usethis_quiet <- getOption('usethis.quiet')
on.exit(options(usethis.quiet = old_usethis_quiet))
options(usethis.quiet = TRUE)
}
if (is.null(name)) {
stop("Must supply a package name", call. = FALSE)
Expand Down
1 change: 0 additions & 1 deletion R/yamlR.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#' @description Edit a yaml configuration file via an API.
#' @details Add, remove files and objects, enable or disable parsing of specific files, list objects or files in a yaml config, or write a config back to a package.
#' @importFrom yaml yaml.load_file as.yaml write_yaml
#' @importFrom withr with_options
#' @export
#'
#' @examples
Expand Down
4 changes: 2 additions & 2 deletions man/DataPackageR-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/assert_data_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/data_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-data-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ test_that("assert_data_version", {
code_files = f
)
package_build(file.path(tempdir(), pname))
on.exit(devtools::unload(pname))
devtools::load_all(file.path(tempdir(), pname))
on.exit(pkgload::unload(pname))
pkgload::load_all(file.path(tempdir(), pname))
suppressWarnings(expect_true(
data_version(pkg = pname) == numeric_version("0.1.0")
))
Expand Down
11 changes: 5 additions & 6 deletions tests/testthat/test-phantom_loading.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ testthat::test_that(
)
pkg_name <- "mtcars20"
on.exit(
if (pkg_name %in% devtools::package_info('attached')$package){
devtools::unload(pkg_name)
if (pkg_name %in% names(utils::sessionInfo()$otherPkgs)){
pkgload::unload(pkg_name)
}
)
# remove this directory on exit
Expand All @@ -24,17 +24,16 @@ testthat::test_that(
expect_no_warning(package_build(pkg_path, install = FALSE))
# test phantom pkg loading side effect from roxygen2::roxygenise()
expect_false(
res1 <- pkg_name %in% devtools::package_info('attached')$package
res1 <- pkg_name %in% names(utils::sessionInfo()$otherPkgs)
)

# reset for next test
if (res1) devtools::unload(pkg_name)
if (res1) pkgload::unload(pkg_name)

# test phantom pkg loading side effect from roxygen2::roxygenise()
# which is called by devtools::document()
expect_no_warning(document(pkg_path, install = FALSE))
expect_false(
res2 <- pkg_name %in% devtools::package_info('attached')$package
res2 <- pkg_name %in% names(utils::sessionInfo()$otherPkgs)
)
}
)
4 changes: 2 additions & 2 deletions tests/testthat/test-pkg_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ test_that("can_read_pkg_description, data_version", {
r_object_names = c("cars_over_20", "pressure")
)
DataPackageR:::read_pkg_description(file.path(tempdir(), "subsetCars"))
on.exit(devtools::unload("subsetCars"))
devtools::load_all(file.path(tempdir(), "subsetCars"))
on.exit(pkgload::unload("subsetCars"))
pkgload::load_all(file.path(tempdir(), "subsetCars"))
expected_version <-
structure(list(c(0L, 1L, 0L)),
class = c("package_version", "numeric_version")
Expand Down

0 comments on commit 65d392d

Please sign in to comment.