Skip to content

Commit 1f15a9c

Browse files
committed
More polish for different platfroms and checks
1 parent 9eedf94 commit 1f15a9c

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

RcppTskit/.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
^cran-comments\.md$
1414
^inst/examples/create_test\.trees\.R$
1515
^inst/examples/create_test\.trees\.py$
16+
^LICENSE.md$
1617
^notes_pkg_dev\.Rmd$
1718
^pkg_dev_notes\.md$
1819
^tests/testthat/_snaps$

RcppTskit/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2026 Gregor Gorjanc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

RcppTskit/R/RcppTskit.R

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ get_tskit_py <- function(object_name = "tskit") {
3030
if (test) {
3131
tskit <- get(object_name, envir = .GlobalEnv, inherits = FALSE)
3232
test <- reticulate::is_py_object(tskit) &&
33-
is(tskit) == "python.builtin.module"
33+
is(tskit, "python.builtin.module")
3434
if (test) {
3535
return(tskit)
3636
} else {
@@ -43,22 +43,36 @@ get_tskit_py <- function(object_name = "tskit") {
4343
}
4444
}
4545
# else
46-
# These lines are hard to hit with tests with cached reticulate Python and modules
46+
# These lines are hard to hit with tests and cached reticulate Python and modules
4747
# nocov start
48+
msgSuccess <- 'reticulate::py_require("tskit") succeded!'
49+
msgFail <- 'reticulate::py_require("tskit") failed!'
50+
e <- simpleError(msgFail)
4851
if (!reticulate::py_module_available("tskit")) {
4952
txt <- "Python module 'tskit' is not available. Attempting to install it ..."
5053
message(txt)
51-
reticulate::py_require("tskit")
54+
out <- tryCatch(
55+
reticulate::py_require("tskit"),
56+
error = function(s) e
57+
)
58+
if (is(out, "simpleError")) {
59+
return(msgFail)
60+
}
5261
}
53-
# nocov end
54-
return(reticulate::import("tskit", delay_load = TRUE))
62+
msgFail <- 'reticulate::import("tskit") failed!'
63+
e <- simpleError(msgFail)
64+
out <- tryCatch(
65+
reticulate::import("tskit", delay_load = TRUE),
66+
error = function(e) e
67+
)
68+
return(out)
5569
}
5670

5771
#' @describeIn get_tskit_py Test if \code{get_tskit_py} returned a reticulate Python module object
5872
#' @export
5973
check_tskit_py <- function(object, stop = FALSE) {
6074
test <- reticulate::is_py_object(object) &&
61-
("python.builtin.module" %in% is(object))
75+
(is(object, "python.builtin.module"))
6276
if (test) {
6377
return(TRUE)
6478
} else {

RcppTskit/tests/testthat/test_get_tskit_py.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test_that("get_tskit_py() works", {
2626
# lobstr::obj_addr(tskit)
2727
# "0x12218b910"
2828
expect_true(is_py_object(tskit))
29-
expect_true(is(tskit) == "python.builtin.module")
29+
expect_true(is(tskit, "python.builtin.module"))
3030
expect_equal(tskit$`__name__`, "tskit")
3131

3232
# Testing that get_tskit_py() returns the same tskit object if it already exists

0 commit comments

Comments
 (0)