Skip to content

Commit

Permalink
Add check before deregistering modules
Browse files Browse the repository at this point in the history
Fixes #363.

Squashed commit of the following:

commit 9e02d8840f6b832e8bf9a870cc8787fe44925c88
Author: Konrad Rudolph <[email protected]>
Date:   Sat Jun 29 18:51:36 2024 +0200

    Check before dereginstering a module

    A module may have already been deregistered if it was loaded by two
    modules which are both loaded by the module being unloaded by the user.

commit b7a464c9024e58e42e44ac5cd6ba5c76db248e80
Author: Konrad Rudolph <[email protected]>
Date:   Sun Jun 30 23:13:42 2024 +0200

    Add failing unit test

commit ccf9a10
Author: Konrad Rudolph <[email protected]>
Date:   Sun Jun 30 23:31:49 2024 +0200

    Set dev version number

commit b88b59b069b63a2facdbbaf7f364afa5b2063858
Author: Konrad Rudolph <[email protected]>
Date:   Sun Jun 30 23:43:17 2024 +0200

    Document changes
  • Loading branch information
klmr committed Jun 30, 2024
1 parent 10e1b45 commit e0a64e3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: box
Title: Write Reusable, Composable and Modular R Code
Version: 1.2.0
Version: 1.2.0.9000
Authors@R: c(
person(
'Konrad', 'Rudolph',
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# box (development version)

## Bug fixes

* Suppress a spurious internal warning upon reloading a module, caused by a dependent module being imported more than once (#363).


# box 1.2.0

## Breaking changes
Expand Down
6 changes: 5 additions & 1 deletion R/loaded.r
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ register_mod = function (info, mod_ns) {

#' @rdname loaded
deregister_mod = function (info) {
rm(list = info$source_path, envir = loaded_mods)
# May already have been removed if called by `unload_mod_recursive`, where
# a given module is imported by multiple submodules.
if (exists(info$source_path, envir = loaded_mods)) {
rm(list = info$source_path, envir = loaded_mods)
}
}

#' @rdname loaded
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/mod/reload/nested/a.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
box::export()
3 changes: 3 additions & 0 deletions tests/testthat/mod/reload/nested/b.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
box::use(./a)

box::export()
3 changes: 3 additions & 0 deletions tests/testthat/mod/reload/nested/c.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
box::use(./a, ./b)

box::export()
6 changes: 6 additions & 0 deletions tests/testthat/test-reload.r
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@ test_that('`reload` shows expected errors', {
'"reload" expects a module object, got "x", which is of type "integer" instead'
)
})

test_that('reloading a module used twice does not cause a warning', {
box::use(mod/reload/nested/c)

expect_warning(box::reload(c), NA)
})

0 comments on commit e0a64e3

Please sign in to comment.