Skip to content

Commit b67501d

Browse files
committed
Handle package dependencies during auto-reloading
1 parent ee93573 commit b67501d

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

R/autoreload.r

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ autoreload = local({
185185
}
186186

187187
needs_reloading = function (info, ns) {
188+
UseMethod('needs_reloading')
189+
}
190+
191+
`needs_reloading.box$mod_info` = function (info, ns) {
188192
included(info) && (
189193
is_file_modified(info, ns) || {
190194
imports = namespace_info(ns, 'imports')
@@ -193,6 +197,10 @@ autoreload = local({
193197
)
194198
}
195199

200+
`needs_reloading.box$pkg_info` = function (info, ns) {
201+
FALSE
202+
}
203+
196204
reset()
197205

198206
self

R/env.r

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,25 @@ make_export_env = function (info, spec, ns) {
134134
structure(
135135
new.env(parent = emptyenv()),
136136
name = paste0('mod:', spec_name(spec)),
137-
class = autoreload$export_env_class(info),
137+
class = export_env_class(info),
138138
spec = spec,
139139
info = info,
140140
namespace = ns
141141
)
142142
}
143143

144+
export_env_class = function (info) {
145+
UseMethod('export_env_class')
146+
}
147+
148+
`export_env_class.box$mod_info` = function (info) {
149+
autoreload$export_env_class(info)
150+
}
151+
152+
`export_env_class.box$pkg_info` = function (info) {
153+
'box$mod'
154+
}
155+
144156
strict_extract = function (e1, e2) {
145157
# Implemented in C since this function is called very frequently and needs
146158
# to be fast, and the C implementation is about 270% faster than an R

tests/testthat/test-autoreload.r

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ create_simple_test_module = function (dir) {
1010
mod = file.path(dir, 'mod')
1111
dir.create(mod)
1212
a = file.path(mod, 'a.r')
13-
writeLines(c("#' @export", 'f = function () 1L'), a)
13+
writeLines(c(
14+
'box::use(stats)',
15+
"#' @export",
16+
'f = function () 1L'
17+
), a)
1418
}
1519

1620
edit_simple_test_module = function (dir) {

0 commit comments

Comments
 (0)