Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify DESCRIPTION check #149

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* `load_all(warn_conflicts = TRUE)` becomes more narrow and only warns when a *function* in the global environment masks a *function* in the package, consistent with the docs (#125, #143 @jennybc).
* `unload()` no longer warns when it can't unload a namespace.
* `load_all()` no longer does a comprehensive check on the `DESCRIPTION` file when loading, instead just checking that it exists and starts with Package (#149, @malcolmbarrett)

# pkgload 1.2.0

Expand Down
10 changes: 0 additions & 10 deletions R/load.r
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,6 @@ load_all <- function(path = ".", reset = TRUE, compile = NA,
on.exit(compiler::enableJIT(oldEnabled), TRUE)
}

# Check description file is ok
check <- ("tools" %:::% ".check_package_description")(
package_file("DESCRIPTION", path = path))

if (length(check) > 0) {
msg <- utils::capture.output(("tools" %:::% "print.check_package_description")(check))
cli::cli_alert_danger("Invalid DESCRIPTION")
cli::cli_code(msg)
}

# Compile dll if requested
if (missing(compile) && !missing(recompile)) {
compile <- if (isTRUE(recompile)) TRUE else NA
Expand Down
12 changes: 11 additions & 1 deletion R/package.r
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ NULL
#' @describeIn packages Return the normalized package path.
#' @export
pkg_path <- function(path = ".") {
path <- rprojroot_find_root("DESCRIPTION", path)
path <- tryCatch({
rprojroot_find_package_root_file(path = path)
},
error = function(e) {
abort(paste(
"Could not find a root 'DESCRIPTION' file that starts with '^Package' in",
paste0("'", normalizePath(path), "'."),
"Are you in your project directory,",
"and does your project have a 'DESCRIPTION' file?"
), class = "pkgload_no_desc")
})

# Strip trailing slashes, which can cause errors on Windows (#73)
sub("[/\\]$", "", path)
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
assign("desc_desc", desc::desc, envir = env)
assign("desc_desc_get", desc::desc_get, envir = env)
assign("desc_desc_get_version", desc::desc_get_version, envir = env)
assign("rprojroot_find_root", rprojroot::find_root, envir = env)
assign("rprojroot_find_package_root_file", rprojroot::find_package_root_file, envir = env)
if (is_installed("testthat")) {
assign("testthat_source_test_helpers", testthat::source_test_helpers, envir = env)
} else {
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-load.r
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,10 @@ test_that("reloading a package unloads deleted S3 methods", {
load_all("testS3removed2")
expect_equal(as.character(x), character())
})

test_that("load_all() errors when no DESCRIPTION found", {
withr::with_tempdir({
expect_error(load_all(), class = "pkgload_no_desc")
})
})