-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import
load_all()
dependencies lazily
Closes #189
- Loading branch information
Showing
3 changed files
with
50 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,49 @@ | ||
.onLoad <- function(libname, pkgname) { | ||
# These withr functions are used in load_all() so need to exist in the | ||
# devtools namespace so the withr namespace is not prematurely loaded by `::` | ||
# during a load_all() call | ||
env <- asNamespace(pkgname) | ||
assign("withr_with_dir", withr::with_dir, envir = env) | ||
assign("withr_with_collate", withr::with_collate, envir = env) | ||
assign("withr_with_envvar", withr::with_envvar, envir = env) | ||
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_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 { | ||
assign("testthat_source_test_helpers", function(...) TRUE, envir = env) | ||
} | ||
run_on_load() | ||
ns <- ns_env(pkgname) | ||
|
||
nms <- fn_env(onload_assign)$names | ||
funs <- fn_env(onload_assign)$funs | ||
|
||
nms <- environment(onload_assign)$names | ||
funs <- environment(onload_assign)$funs | ||
for (i in seq_along(nms)) { | ||
assign(nms[[i]], eval(funs[[i]], envir = env), envir = env) | ||
env_poke(ns, nms[[i]], eval(funs[[i]], ns)) | ||
} | ||
} | ||
|
||
# These functions are used in load_all() so need to exist in the | ||
# devtools namespace so the withr namespace is not prematurely loaded | ||
# by `::` during a load_all() call. | ||
# | ||
# They are lazily assigned to avoid racing issues while installing in | ||
# parallel (see #89), and forced via `force_load_all_deps()` before | ||
# unregistering namespaces. | ||
on_load({ | ||
withr_with_dir %<~% withr::with_dir | ||
withr_with_collate %<~% withr::with_collate | ||
withr_with_envvar %<~% withr::with_envvar | ||
|
||
desc_desc %<~% desc::desc | ||
desc_desc_get %<~% desc::desc_get | ||
desc_desc_get_version %<~% desc::desc_get_version | ||
|
||
rprojroot_find_package_root_file %<~% rprojroot::find_package_root_file | ||
|
||
if (is_installed("testthat")) { | ||
testthat_source_test_helpers %<~% testthat::source_test_helpers | ||
} else { | ||
testthat_source_test_helpers %<~% function(...) TRUE | ||
} | ||
}) | ||
|
||
invisible() | ||
force_load_all_deps <- function() { | ||
list( | ||
withr_with_dir, | ||
withr_with_collate, | ||
withr_with_envvar, | ||
desc_desc, | ||
desc_desc_get, | ||
desc_desc_get_version, | ||
rprojroot_find_package_root_file, | ||
testthat_source_test_helpers | ||
) | ||
} |