From d3c9cedc87f1150f900d2ef6ad2da1b69074e269 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 18 Mar 2024 15:14:18 +0100 Subject: [PATCH 01/90] Add manifest creation datetime to output --- R/export_manifest.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/export_manifest.R b/R/export_manifest.R index 13866cb2..f2ec13e8 100644 --- a/R/export_manifest.R +++ b/R/export_manifest.R @@ -39,7 +39,13 @@ create_manifest <- function( logger::log_debug("Creating metadata manifest") manifest_list <- list( input_files = get_file_metadata(input_files), - output_files = get_file_metadata(output_files) + output_files = get_file_metadata(output_files), + manifest_creation_datetime = format.POSIXct( + x = Sys.time(), + format = "%F %R", + tz = "UTC", + usetz = TRUE + ) ) return(manifest_list) } From f50be581601c97587ed3a49df774cc884ff47d01 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 19 Mar 2024 16:53:44 +0100 Subject: [PATCH 02/90] add function to get environment information --- R/get_environment.R | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 R/get_environment.R diff --git a/R/get_environment.R b/R/get_environment.R new file mode 100644 index 00000000..961f438e --- /dev/null +++ b/R/get_environment.R @@ -0,0 +1,87 @@ +#' Get Environment information for manifest +#' +#' This function takes no arguments and returns a nested list, suitable for +#' inclusion in manifest export. +#' +#' @return nested list of file details, length the same as the input vector. +get_manifest_envirionment_info <- function() { + + # TODO: Envvars + # TODO: Session + # Todo: packages + + + return(invisible(FALSE)) +} + +get_r_session_info <- function() { + return( + list( + R.version = utils::sessionInfo()[["R.version"]], + platform = utils::sessionInfo()[["platform"]], + running = utils::sessionInfo()[["running"]], + locale = utils::sessionInfo()[["locale"]], + tzone = utils::sessionInfo()[["tzone"]], + ) + ) +} + +get_package_info <- function( + base = utils::sessionInfo()[["basePkgs"]], + attached = names(utils::sessionInfo()[["otherPkgs"]]), + loaded = names(utils::sessionInfo()[["loadedOnly"]]) +) { + log_debug("Getting package info.") + log_trace("Base packages: {base}") + base_pkgs <- vapply( + X = base, + FUN = get_individual_package_info, + FUN.VALUE = list(10L), + USE.NAMES = TRUE + ) + log_trace("Attached packages: {attached}") + attached_pkgs <- vapply( + X = attached, + FUN = get_individual_package_info, + FUN.VALUE = list(1L), + USE.NAMES = TRUE + ) + log_trace("Loaded packages: {loaded}") + loaded_pkgs <- vapply( + X = loaded, + FUN = get_individual_package_info, + FUN.VALUE = list(10L), + USE.NAMES = TRUE + ) + log_debug("Done fetching package info.") + return( + list( + base = base_pkgs, + attached = attached_pkgs, + loaded = loaded_pkgs + ) + ) +} + +get_individual_package_info <- function(packagename) { + log_trace("Getting package info for {packagename}.") + pkg_details <- as.list( + pak::pkg_status(packagename)[ + c( + "package", + "version", + "library", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" + ) + ] + ) + output <- list() + output[[packagename]] <- pkg_details + return(output) +} From c43ca87afd3ff8f048993a88bee38c14fe92d3b6 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 19 Mar 2024 16:59:20 +0100 Subject: [PATCH 03/90] Add test for session info --- tests/testthat/test-get_environment.R | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/testthat/test-get_environment.R diff --git a/tests/testthat/test-get_environment.R b/tests/testthat/test-get_environment.R new file mode 100644 index 00000000..5fb6fa30 --- /dev/null +++ b/tests/testthat/test-get_environment.R @@ -0,0 +1,28 @@ +## save current settings so that we can reset later +threshold <- logger::log_threshold() +appender <- logger::log_appender() +layout <- logger::log_layout() +on.exit({ + ## reset logger settings + logger::log_threshold(threshold) + logger::log_layout(layout) + logger::log_appender(appender) +}) + +logger::log_appender(logger::appender_stdout) +logger::log_threshold(logger::FATAL) +logger::log_layout(logger::layout_simple) + +test_that("get_single_file_metadata processes CSV tables correctly", { + expect_identical( + get_r_session_info(), + list( + R.version = utils::sessionInfo()[["R.version"]], + platform = utils::sessionInfo()[["platform"]], + running = utils::sessionInfo()[["running"]], + locale = utils::sessionInfo()[["locale"]], + tzone = utils::sessionInfo()[["tzone"]] + ) + ) +}) + From bc3e60e8098ebee23ceb187d65b454ddece94769 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 19 Mar 2024 17:00:42 +0100 Subject: [PATCH 04/90] eliminate extra comma --- R/get_environment.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index 961f438e..abf77011 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -7,7 +7,6 @@ get_manifest_envirionment_info <- function() { # TODO: Envvars - # TODO: Session # Todo: packages @@ -17,11 +16,11 @@ get_manifest_envirionment_info <- function() { get_r_session_info <- function() { return( list( - R.version = utils::sessionInfo()[["R.version"]], - platform = utils::sessionInfo()[["platform"]], - running = utils::sessionInfo()[["running"]], - locale = utils::sessionInfo()[["locale"]], - tzone = utils::sessionInfo()[["tzone"]], + R.version = utils::sessionInfo()[["R.version"]], + platform = utils::sessionInfo()[["platform"]], + running = utils::sessionInfo()[["running"]], + locale = utils::sessionInfo()[["locale"]], + tzone = utils::sessionInfo()[["tzone"]] ) ) } From d7297c30bd6714b3310df8b67cdd8cf9c5a7dadb Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 19 Mar 2024 17:01:38 +0100 Subject: [PATCH 05/90] Reindent --- R/get_environment.R | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index abf77011..587a20df 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -65,21 +65,21 @@ get_package_info <- function( get_individual_package_info <- function(packagename) { log_trace("Getting package info for {packagename}.") pkg_details <- as.list( - pak::pkg_status(packagename)[ - c( - "package", - "version", - "library", - "repository", - "platform", - "built", - "remotetype", - "remotepkgref", - "remoteref", - "remotesha" - ) - ] - ) + pak::pkg_status(packagename)[ + c( + "package", + "version", + "library", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" + ) + ] + ) output <- list() output[[packagename]] <- pkg_details return(output) From 7a25821dcd003a530ce617962ddc12cc90ff4ccc Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 19 Mar 2024 18:12:05 +0100 Subject: [PATCH 06/90] Add tests for local package info --- tests/testthat/test-get_package_info.R | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/testthat/test-get_package_info.R diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R new file mode 100644 index 00000000..f08fea50 --- /dev/null +++ b/tests/testthat/test-get_package_info.R @@ -0,0 +1,101 @@ +## save current settings so that we can reset later +threshold <- logger::log_threshold() +appender <- logger::log_appender() +layout <- logger::log_layout() +on.exit({ + ## reset logger settings + logger::log_threshold(threshold) + logger::log_layout(layout) + logger::log_appender(appender) +}) + +logger::log_appender(logger::appender_stdout) +logger::log_threshold(logger::FATAL) +logger::log_layout(logger::layout_simple) + +test_that("get_individual_package_info collects information for CRAN packages correctly", { + expect_identical( + get_individual_package_info("digest"), + list( + digest = list( + package = "digest", + version = as.character(utils::packageVersion("digest")), + library = .libPaths()[1], #nolint: undesirable_function_linter + repository = "CRAN", + platform = strsplit( + x = utils::packageDescription("digest")[["Built"]], + split = "; ", + fixed = TRUE + )[[1L]][[2L]], + built = utils::packageDescription("digest")[["Built"]], + remotetype = "standard", + remotepkgref = "digest", + remoteref = "digest", + remotesha = as.character(utils::packageVersion("digest")) + ) + ) + ) +}) + +test_that("get_individual_package_info collects information for local packages correctly", { + package_info <- get_individual_package_info("pacta.workflow.utils") + expect_type(package_info, "list") + expect_named( + package_info, + "pacta.workflow.utils" + ) + expect_named( + package_info[["pacta.workflow.utils"]], + c( + "package", + "version", + "library", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" + ) + ) + expect_identical( + package_info[["pacta.workflow.utils"]][["package"]], + "pacta.workflow.utils" + ) + expect_identical( + package_info[["pacta.workflow.utils"]][["version"]], + as.character(utils::packageVersion("pacta.workflow.utils")) + ) + expect_identical( + package_info[["pacta.workflow.utils"]][["library"]], + .libPaths()[1] #nolint: undesirable_function_linter + ) + expect_identical( + package_info[["pacta.workflow.utils"]][["repository"]], + NA_character_ + ) + expect_identical( + package_info[["pacta.workflow.utils"]][["platform"]], + "*" + ) + expect_false( + is.null(package_info[["pacta.workflow.utils"]][["built"]]) + ) + expect_identical( + package_info[["pacta.workflow.utils"]][["remotetype"]], + "local" + ) + expect_match( + package_info[["pacta.workflow.utils"]][["remotepkgref"]], + "^local::.*pacta\\.workflow\\.utils$" + ) + expect_identical( + package_info[["pacta.workflow.utils"]][["remoteref"]], + NA_character_ + ) + expect_identical( + package_info[["pacta.workflow.utils"]][["remotesha"]], + NA_character_ + ) +}) From ac5a6f35efa7d77f8c2d093e311bd60becaced25 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 19 Mar 2024 19:15:00 +0100 Subject: [PATCH 07/90] Add test for package info from GH source --- tests/testthat/test-get_package_info.R | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index f08fea50..3f186c1c 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -99,3 +99,71 @@ test_that("get_individual_package_info collects information for local packages c NA_character_ ) }) + +test_that("get_individual_package_info collects information for GitHub packages correctly", { + testthat::skip_on_cran() + withr::with_temp_libpaths(action = "replace", code = { + new_lib <- .libPaths()[1] #nolint: undesirable_function_linter + pak::pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter + package_info <- get_individual_package_info("rmini") + expect_type(package_info, "list") + expect_named( + package_info, + "rmini" + ) + expect_named( + package_info[["rmini"]], + c( + "package", + "version", + "library", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" + ) + ) + expect_identical( + package_info[["rmini"]][["package"]], + "rmini" + ) + expect_identical( + package_info[["rmini"]][["version"]], + as.character(utils::packageVersion("rmini")) + ) + expect_match( + package_info[["rmini"]][["library"]], + paste0(new_lib, "$") + ) + expect_identical( + package_info[["rmini"]][["repository"]], + NA_character_ + ) + expect_identical( + package_info[["rmini"]][["platform"]], + R.version[["platform"]] + ) + expect_false( + is.null(package_info[["rmini"]][["built"]]) + ) + expect_identical( + package_info[["rmini"]][["remotetype"]], + "github" + ) + expect_match( + package_info[["rmini"]][["remotepkgref"]], + "yihui/rmini" #nolint: nonportable_path_linter + ) + expect_identical( + package_info[["rmini"]][["remoteref"]], + "HEAD" + ) + expect_identical( + package_info[["rmini"]][["remotesha"]], + "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + ) + }) +}) From b58e156cb7c05d633534e41d69316e3029ba1ff3 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 19 Mar 2024 19:18:47 +0100 Subject: [PATCH 08/90] Add dependency on `pak` --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 497f740d..bac43e13 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,8 @@ RoxygenNote: 7.3.1 Imports: digest, jsonlite, - logger + logger, + pak Suggests: testthat (>= 3.0.0), withr From 85e46ecb477088e3756de4f513e9c72aa86d13ff Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 19 Mar 2024 19:21:32 +0100 Subject: [PATCH 09/90] linting --- R/get_environment.R | 3 +-- tests/testthat/test-get_environment.R | 1 - tests/testthat/test-get_package_info.R | 6 +++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index 587a20df..8b312550 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -6,8 +6,7 @@ #' @return nested list of file details, length the same as the input vector. get_manifest_envirionment_info <- function() { - # TODO: Envvars - # Todo: packages + #: Envvars return(invisible(FALSE)) diff --git a/tests/testthat/test-get_environment.R b/tests/testthat/test-get_environment.R index 5fb6fa30..c1bcc3cd 100644 --- a/tests/testthat/test-get_environment.R +++ b/tests/testthat/test-get_environment.R @@ -25,4 +25,3 @@ test_that("get_single_file_metadata processes CSV tables correctly", { ) ) }) - diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 3f186c1c..3728a0f4 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -13,7 +13,7 @@ logger::log_appender(logger::appender_stdout) logger::log_threshold(logger::FATAL) logger::log_layout(logger::layout_simple) -test_that("get_individual_package_info collects information for CRAN packages correctly", { +test_that("get_individual_package_info collects information for CRAN packages correctly", { #nolint: line_length_linter expect_identical( get_individual_package_info("digest"), list( @@ -37,7 +37,7 @@ test_that("get_individual_package_info collects information for CRAN packages co ) }) -test_that("get_individual_package_info collects information for local packages correctly", { +test_that("get_individual_package_info collects information for local packages correctly", { #nolint: line_length_linter package_info <- get_individual_package_info("pacta.workflow.utils") expect_type(package_info, "list") expect_named( @@ -100,7 +100,7 @@ test_that("get_individual_package_info collects information for local packages c ) }) -test_that("get_individual_package_info collects information for GitHub packages correctly", { +test_that("get_individual_package_info collects information for GitHub packages correctly", { #nolint: line_length_linter testthat::skip_on_cran() withr::with_temp_libpaths(action = "replace", code = { new_lib <- .libPaths()[1] #nolint: undesirable_function_linter From 8c4d51c8d5e110e993b8327235dbde48c3457b1c Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 10:03:32 +0100 Subject: [PATCH 10/90] Change testing flow for local packages --- tests/testthat/test-get_package_info.R | 127 ++++++++++++++----------- 1 file changed, 69 insertions(+), 58 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 3728a0f4..6989af30 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -38,66 +38,77 @@ test_that("get_individual_package_info collects information for CRAN packages co }) test_that("get_individual_package_info collects information for local packages correctly", { #nolint: line_length_linter - package_info <- get_individual_package_info("pacta.workflow.utils") - expect_type(package_info, "list") - expect_named( - package_info, - "pacta.workflow.utils" + testthat::skip_on_cran() + dest_dir <- withr::local_tempdir() + dl <- git2r::clone( + url = "https://github.com/yihui/rmini.git", #nolint: nonportable_path_linter + local_path = dest_dir, + progress = FALSE ) - expect_named( - package_info[["pacta.workflow.utils"]], - c( - "package", - "version", - "library", - "repository", - "platform", - "built", - "remotetype", - "remotepkgref", - "remoteref", - "remotesha" + withr::with_temp_libpaths(action = "replace", code = { + new_lib <- .libPaths()[1] #nolint: undesirable_function_linter + pak::local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter + package_info <- get_individual_package_info("rmini") + expect_type(package_info, "list") + expect_named( + package_info, + "rmini" ) - ) - expect_identical( - package_info[["pacta.workflow.utils"]][["package"]], - "pacta.workflow.utils" - ) - expect_identical( - package_info[["pacta.workflow.utils"]][["version"]], - as.character(utils::packageVersion("pacta.workflow.utils")) - ) - expect_identical( - package_info[["pacta.workflow.utils"]][["library"]], - .libPaths()[1] #nolint: undesirable_function_linter - ) - expect_identical( - package_info[["pacta.workflow.utils"]][["repository"]], - NA_character_ - ) - expect_identical( - package_info[["pacta.workflow.utils"]][["platform"]], - "*" - ) - expect_false( - is.null(package_info[["pacta.workflow.utils"]][["built"]]) - ) - expect_identical( - package_info[["pacta.workflow.utils"]][["remotetype"]], - "local" - ) - expect_match( - package_info[["pacta.workflow.utils"]][["remotepkgref"]], - "^local::.*pacta\\.workflow\\.utils$" - ) - expect_identical( - package_info[["pacta.workflow.utils"]][["remoteref"]], - NA_character_ - ) - expect_identical( - package_info[["pacta.workflow.utils"]][["remotesha"]], - NA_character_ - ) + expect_named( + package_info[["rmini"]], + c( + "package", + "version", + "library", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" + ) + ) + expect_identical( + package_info[["rmini"]][["package"]], + "rmini" + ) + expect_identical( + package_info[["rmini"]][["version"]], + as.character(utils::packageVersion("rmini")) + ) + expect_match( + package_info[["rmini"]][["library"]], + paste0(new_lib, "$") + ) + expect_identical( + package_info[["rmini"]][["repository"]], + NA_character_ + ) + expect_identical( + package_info[["rmini"]][["platform"]], + R.version[["platform"]] + ) + expect_false( + is.null(package_info[["rmini"]][["built"]]) + ) + expect_identical( + package_info[["rmini"]][["remotetype"]], + "local" + ) + expect_match( + package_info[["rmini"]][["remotepkgref"]], + paste0("^local::/.*", basename(dest_dir)) + ) + expect_identical( + package_info[["rmini"]][["remoteref"]], + NA #logical + ) + expect_identical( + package_info[["rmini"]][["remotesha"]], + NA #logical + ) + }) }) test_that("get_individual_package_info collects information for GitHub packages correctly", { #nolint: line_length_linter From b6d28fe24c954844e21f26a2f54789c61e65c0b3 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 10:45:21 +0100 Subject: [PATCH 11/90] add local R_USER_CACHE_DIR --- tests/testthat/test-get_package_info.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 6989af30..99e608a8 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -112,6 +112,8 @@ test_that("get_individual_package_info collects information for local packages c }) test_that("get_individual_package_info collects information for GitHub packages correctly", { #nolint: line_length_linter + cache_dir <- withr::local_tempdir() + withr::local_envvar(.new = c(R_USER_CACHE_DIR = cache_dir)) testthat::skip_on_cran() withr::with_temp_libpaths(action = "replace", code = { new_lib <- .libPaths()[1] #nolint: undesirable_function_linter From c1a40a7e36ed4958cf4c1facf84dd86a31ebf7d5 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 11:13:20 +0100 Subject: [PATCH 12/90] Change from pak to pkgdepends fo package info --- DESCRIPTION | 3 ++- R/get_environment.R | 29 +++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bac43e13..be0a78c9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,8 +19,9 @@ Imports: digest, jsonlite, logger, - pak + pkgdepends Suggests: + git2r, testthat (>= 3.0.0), withr Config/testthat/edition: 3 diff --git a/R/get_environment.R b/R/get_environment.R index 8b312550..04699aaf 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -63,23 +63,20 @@ get_package_info <- function( get_individual_package_info <- function(packagename) { log_trace("Getting package info for {packagename}.") - pkg_details <- as.list( - pak::pkg_status(packagename)[ - c( - "package", - "version", - "library", - "repository", - "platform", - "built", - "remotetype", - "remotepkgref", - "remoteref", - "remotesha" - ) - ] - ) + pkg_details <- as.list(pkgdepends::lib_status(packages = packagename)) output <- list() + output[[packagename]] <- list( + package = pkg_details[["package"]], + version = pkg_details[["version"]], + library = pkg_details[["library"]], + repository = pkg_details[["repository"]], + platform = pkg_details[["platform"]], + built = pkg_details[["built"]], + remotetype = pkg_details[["remotetype"]], + remotepkgref = pkg_details[["remotepkgref"]], + remoteref = pkg_details[["remoteref"]], + remotesha = pkg_details[["remotesha"]] + ) output[[packagename]] <- pkg_details return(output) } From 506af48ae735bdf397ce5c96d4894b116a7595eb Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 11:16:23 +0100 Subject: [PATCH 13/90] Capture PAK output to make tests easier to read --- tests/testthat/test-get_package_info.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 99e608a8..f82ca82a 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -47,7 +47,9 @@ test_that("get_individual_package_info collects information for local packages c ) withr::with_temp_libpaths(action = "replace", code = { new_lib <- .libPaths()[1] #nolint: undesirable_function_linter - pak::local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter + testthat::capture_output( #make pak quiet + pak::local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter + ) package_info <- get_individual_package_info("rmini") expect_type(package_info, "list") expect_named( @@ -117,7 +119,9 @@ test_that("get_individual_package_info collects information for GitHub packages testthat::skip_on_cran() withr::with_temp_libpaths(action = "replace", code = { new_lib <- .libPaths()[1] #nolint: undesirable_function_linter - pak::pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter + testthat::capture_output( #make pak quiet + pak::pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter + ) package_info <- get_individual_package_info("rmini") expect_type(package_info, "list") expect_named( From 2df69db5ae8f962cbdac7f6d48c9dfefa45fcfda Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 11:25:08 +0100 Subject: [PATCH 14/90] Sanitize package details before exporting --- R/get_environment.R | 12 +++++++++--- tests/testthat/test-get_package_info.R | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index 04699aaf..9a3405f4 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -64,8 +64,7 @@ get_package_info <- function( get_individual_package_info <- function(packagename) { log_trace("Getting package info for {packagename}.") pkg_details <- as.list(pkgdepends::lib_status(packages = packagename)) - output <- list() - output[[packagename]] <- list( + details_list <- list( package = pkg_details[["package"]], version = pkg_details[["version"]], library = pkg_details[["library"]], @@ -77,6 +76,13 @@ get_individual_package_info <- function(packagename) { remoteref = pkg_details[["remoteref"]], remotesha = pkg_details[["remotesha"]] ) - output[[packagename]] <- pkg_details + clean_details_list <- lapply( + X = details_list, + FUN = function(x) { + ifelse(is.null(x), NA_character_, x) + } + ) + output <- list() + output[[packagename]] <- clean_details_list return(output) } diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index f82ca82a..ab2b4745 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -104,11 +104,11 @@ test_that("get_individual_package_info collects information for local packages c ) expect_identical( package_info[["rmini"]][["remoteref"]], - NA #logical + NA_character_ ) expect_identical( package_info[["rmini"]][["remotesha"]], - NA #logical + NA_character_ ) }) }) From 6e86e29d97f1803fa8f049ea537b51523b6ad22a Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 11:39:12 +0100 Subject: [PATCH 15/90] Add pak to testing deps --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index be0a78c9..77429306 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,7 @@ Imports: pkgdepends Suggests: git2r, + pak, testthat (>= 3.0.0), withr Config/testthat/edition: 3 From 6281f19ee9f08e188708c0b19122a44e74490908 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 11:47:25 +0100 Subject: [PATCH 16/90] copy pak functions before messing with libpaths --- tests/testthat/test-get_package_info.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index ab2b4745..0cd4fe22 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -45,10 +45,11 @@ test_that("get_individual_package_info collects information for local packages c local_path = dest_dir, progress = FALSE ) + local_install <- pak::local_install # copy function before we break libpaths withr::with_temp_libpaths(action = "replace", code = { new_lib <- .libPaths()[1] #nolint: undesirable_function_linter testthat::capture_output( #make pak quiet - pak::local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter + local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter ) package_info <- get_individual_package_info("rmini") expect_type(package_info, "list") @@ -117,10 +118,11 @@ test_that("get_individual_package_info collects information for GitHub packages cache_dir <- withr::local_tempdir() withr::local_envvar(.new = c(R_USER_CACHE_DIR = cache_dir)) testthat::skip_on_cran() + pkg_install <- pak::pkg_install # copy function before we break libpaths withr::with_temp_libpaths(action = "replace", code = { new_lib <- .libPaths()[1] #nolint: undesirable_function_linter testthat::capture_output( #make pak quiet - pak::pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter + pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter ) package_info <- get_individual_package_info("rmini") expect_type(package_info, "list") From bf63e19125214de787302d61f5dc025997943b60 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 13:05:35 +0100 Subject: [PATCH 17/90] Fix madness with libpaths --- tests/testthat/test-get_package_info.R | 262 ++++++++++++------------- 1 file changed, 129 insertions(+), 133 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 0cd4fe22..b396eafa 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -26,7 +26,7 @@ test_that("get_individual_package_info collects information for CRAN packages co x = utils::packageDescription("digest")[["Built"]], split = "; ", fixed = TRUE - )[[1L]][[2L]], + )[[1L]][[2L]], built = utils::packageDescription("digest")[["Built"]], remotetype = "standard", remotepkgref = "digest", @@ -45,144 +45,140 @@ test_that("get_individual_package_info collects information for local packages c local_path = dest_dir, progress = FALSE ) - local_install <- pak::local_install # copy function before we break libpaths - withr::with_temp_libpaths(action = "replace", code = { - new_lib <- .libPaths()[1] #nolint: undesirable_function_linter - testthat::capture_output( #make pak quiet - local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter - ) - package_info <- get_individual_package_info("rmini") - expect_type(package_info, "list") - expect_named( - package_info, - "rmini" - ) - expect_named( - package_info[["rmini"]], - c( - "package", - "version", - "library", - "repository", - "platform", - "built", - "remotetype", - "remotepkgref", - "remoteref", - "remotesha" - ) - ) - expect_identical( - package_info[["rmini"]][["package"]], - "rmini" - ) - expect_identical( - package_info[["rmini"]][["version"]], - as.character(utils::packageVersion("rmini")) - ) - expect_match( - package_info[["rmini"]][["library"]], - paste0(new_lib, "$") - ) - expect_identical( - package_info[["rmini"]][["repository"]], - NA_character_ - ) - expect_identical( - package_info[["rmini"]][["platform"]], - R.version[["platform"]] - ) - expect_false( - is.null(package_info[["rmini"]][["built"]]) - ) - expect_identical( - package_info[["rmini"]][["remotetype"]], - "local" - ) - expect_match( - package_info[["rmini"]][["remotepkgref"]], - paste0("^local::/.*", basename(dest_dir)) - ) - expect_identical( - package_info[["rmini"]][["remoteref"]], - NA_character_ - ) - expect_identical( - package_info[["rmini"]][["remotesha"]], - NA_character_ + new_lib <- withr::local_tempdir() + withr::local_libpaths(new_lib) + testthat::capture_output( #make pak quiet + pak::local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter + ) + package_info <- get_individual_package_info("rmini") + expect_type(package_info, "list") + expect_named( + package_info, + "rmini" + ) + expect_named( + package_info[["rmini"]], + c( + "package", + "version", + "library", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" ) - }) + ) + expect_identical( + package_info[["rmini"]][["package"]], + "rmini" + ) + expect_identical( + package_info[["rmini"]][["version"]], + as.character(utils::packageVersion("rmini")) + ) + expect_identical( + package_info[["rmini"]][["library"]], + normalizePath(new_lib) + ) + expect_identical( + package_info[["rmini"]][["repository"]], + NA_character_ + ) + expect_identical( + package_info[["rmini"]][["platform"]], + R.version[["platform"]] + ) + expect_false( + is.null(package_info[["rmini"]][["built"]]) + ) + expect_identical( + package_info[["rmini"]][["remotetype"]], + "local" + ) + expect_match( + package_info[["rmini"]][["remotepkgref"]], + paste0("^local::/.*", basename(dest_dir)) + ) + expect_identical( + package_info[["rmini"]][["remoteref"]], + NA_character_ + ) + expect_identical( + package_info[["rmini"]][["remotesha"]], + NA_character_ + ) }) test_that("get_individual_package_info collects information for GitHub packages correctly", { #nolint: line_length_linter cache_dir <- withr::local_tempdir() withr::local_envvar(.new = c(R_USER_CACHE_DIR = cache_dir)) testthat::skip_on_cran() - pkg_install <- pak::pkg_install # copy function before we break libpaths - withr::with_temp_libpaths(action = "replace", code = { - new_lib <- .libPaths()[1] #nolint: undesirable_function_linter - testthat::capture_output( #make pak quiet - pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter - ) - package_info <- get_individual_package_info("rmini") - expect_type(package_info, "list") - expect_named( - package_info, - "rmini" - ) - expect_named( - package_info[["rmini"]], - c( - "package", - "version", - "library", - "repository", - "platform", - "built", - "remotetype", - "remotepkgref", - "remoteref", - "remotesha" - ) - ) - expect_identical( - package_info[["rmini"]][["package"]], - "rmini" - ) - expect_identical( - package_info[["rmini"]][["version"]], - as.character(utils::packageVersion("rmini")) - ) - expect_match( - package_info[["rmini"]][["library"]], - paste0(new_lib, "$") - ) - expect_identical( - package_info[["rmini"]][["repository"]], - NA_character_ - ) - expect_identical( - package_info[["rmini"]][["platform"]], - R.version[["platform"]] - ) - expect_false( - is.null(package_info[["rmini"]][["built"]]) - ) - expect_identical( - package_info[["rmini"]][["remotetype"]], - "github" - ) - expect_match( - package_info[["rmini"]][["remotepkgref"]], - "yihui/rmini" #nolint: nonportable_path_linter - ) - expect_identical( - package_info[["rmini"]][["remoteref"]], - "HEAD" - ) - expect_identical( - package_info[["rmini"]][["remotesha"]], - "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + new_lib <- withr::local_tempdir() + withr::local_libpaths(new_lib) + testthat::capture_output( #make pak quiet + pak::pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter + ) + package_info <- get_individual_package_info("rmini") + expect_type(package_info, "list") + expect_named( + package_info, + "rmini" + ) + expect_named( + package_info[["rmini"]], + c( + "package", + "version", + "library", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" ) - }) + ) + expect_identical( + package_info[["rmini"]][["package"]], + "rmini" + ) + expect_identical( + package_info[["rmini"]][["version"]], + as.character(utils::packageVersion("rmini")) + ) + expect_identical( + package_info[["rmini"]][["library"]], + normalizePath(new_lib) + ) + expect_identical( + package_info[["rmini"]][["repository"]], + NA_character_ + ) + expect_identical( + package_info[["rmini"]][["platform"]], + R.version[["platform"]] + ) + expect_false( + is.null(package_info[["rmini"]][["built"]]) + ) + expect_identical( + package_info[["rmini"]][["remotetype"]], + "github" + ) + expect_match( + package_info[["rmini"]][["remotepkgref"]], + "yihui/rmini" #nolint: nonportable_path_linter + ) + expect_identical( + package_info[["rmini"]][["remoteref"]], + "HEAD" + ) + expect_identical( + package_info[["rmini"]][["remotesha"]], + "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + ) }) From 02390852e5d51f4f63249d73041a553cb88a6e16 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 13:06:29 +0100 Subject: [PATCH 18/90] bump dev version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 77429306..45542b03 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: pacta.workflow.utils Title: Utility functions for PACTA workflows -Version: 0.0.0.9001 +Version: 0.0.0.9002 Authors@R: c(person(given = "Alex", family = "Axthelm", From 0317d14035dc6364486d3f742956065b9f5f3810 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 13:09:23 +0100 Subject: [PATCH 19/90] Add debugging informtaion to test ouput --- tests/testthat/test-get_package_info.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index b396eafa..446da9b3 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -47,6 +47,7 @@ test_that("get_individual_package_info collects information for local packages c ) new_lib <- withr::local_tempdir() withr::local_libpaths(new_lib) + print(.libPaths()) testthat::capture_output( #make pak quiet pak::local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter ) From 0cad051de2ca07a6e4b9ccce097f15972b2ca154 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 13:18:16 +0100 Subject: [PATCH 20/90] prefix libpath, not replace --- tests/testthat/test-get_package_info.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 446da9b3..480086a9 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -26,7 +26,7 @@ test_that("get_individual_package_info collects information for CRAN packages co x = utils::packageDescription("digest")[["Built"]], split = "; ", fixed = TRUE - )[[1L]][[2L]], + )[[1L]][[2L]], built = utils::packageDescription("digest")[["Built"]], remotetype = "standard", remotepkgref = "digest", @@ -46,8 +46,8 @@ test_that("get_individual_package_info collects information for local packages c progress = FALSE ) new_lib <- withr::local_tempdir() - withr::local_libpaths(new_lib) - print(.libPaths()) + withr::local_libpaths(new_lib, action = "prefix") + print(.libPaths()) #nolint testthat::capture_output( #make pak quiet pak::local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter ) @@ -118,7 +118,7 @@ test_that("get_individual_package_info collects information for GitHub packages withr::local_envvar(.new = c(R_USER_CACHE_DIR = cache_dir)) testthat::skip_on_cran() new_lib <- withr::local_tempdir() - withr::local_libpaths(new_lib) + withr::local_libpaths(new_lib, action = "prefix") testthat::capture_output( #make pak quiet pak::pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter ) From 738aeb63ca419eb3be69dd5c00ed2db07920ca83 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 13:20:17 +0100 Subject: [PATCH 21/90] Update Docs --- man/get_manifest_envirionment_info.Rd | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 man/get_manifest_envirionment_info.Rd diff --git a/man/get_manifest_envirionment_info.Rd b/man/get_manifest_envirionment_info.Rd new file mode 100644 index 00000000..d31e5094 --- /dev/null +++ b/man/get_manifest_envirionment_info.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_environment.R +\name{get_manifest_envirionment_info} +\alias{get_manifest_envirionment_info} +\title{Get Environment information for manifest} +\usage{ +get_manifest_envirionment_info() +} +\value{ +nested list of file details, length the same as the input vector. +} +\description{ +This function takes no arguments and returns a nested list, suitable for +inclusion in manifest export. +} From 05753b804039d79bbcf7b64b876183906c28ae43 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 13:56:10 +0100 Subject: [PATCH 22/90] refactor local installs --- tests/testthat/test-get_package_info.R | 41 +++++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 480086a9..ebadc6e8 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -37,21 +37,29 @@ test_that("get_individual_package_info collects information for CRAN packages co ) }) +with_local_install <- function(new_lib, package, code) { + cache_dir <- withr::local_tempdir() + withr::local_envvar(.new = c(R_USER_CACHE_DIR = cache_dir)) + withr::local_libpaths(new_lib, action = "prefix") + testthat::capture_output( #make pak quiet + pak::pak(package, lib = normalizePath(new_lib)) + ) + eval(code) +} + test_that("get_individual_package_info collects information for local packages correctly", { #nolint: line_length_linter testthat::skip_on_cran() - dest_dir <- withr::local_tempdir() + testthat::skip_if_offline() + dest_dir <- normalizePath(withr::local_tempdir()) dl <- git2r::clone( url = "https://github.com/yihui/rmini.git", #nolint: nonportable_path_linter local_path = dest_dir, progress = FALSE ) - new_lib <- withr::local_tempdir() - withr::local_libpaths(new_lib, action = "prefix") - print(.libPaths()) #nolint - testthat::capture_output( #make pak quiet - pak::local_install(root = file.path(dest_dir), dependencies = FALSE) #nolint: nonportable_path_linter - ) - package_info <- get_individual_package_info("rmini") + new_lib <- normalizePath(withr::local_tempdir()) + package_info <- with_local_install(new_lib, dest_dir, { + get_individual_package_info("rmini") + }) expect_type(package_info, "list") expect_named( package_info, @@ -78,7 +86,7 @@ test_that("get_individual_package_info collects information for local packages c ) expect_identical( package_info[["rmini"]][["version"]], - as.character(utils::packageVersion("rmini")) + "0.0.4" ) expect_identical( package_info[["rmini"]][["library"]], @@ -114,15 +122,12 @@ test_that("get_individual_package_info collects information for local packages c }) test_that("get_individual_package_info collects information for GitHub packages correctly", { #nolint: line_length_linter - cache_dir <- withr::local_tempdir() - withr::local_envvar(.new = c(R_USER_CACHE_DIR = cache_dir)) testthat::skip_on_cran() - new_lib <- withr::local_tempdir() - withr::local_libpaths(new_lib, action = "prefix") - testthat::capture_output( #make pak quiet - pak::pkg_install("yihui/rmini", dependencies = FALSE) #nolint: nonportable_path_linter - ) - package_info <- get_individual_package_info("rmini") + testthat::skip_if_offline() + new_lib <- normalizePath(withr::local_tempdir()) + package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter + get_individual_package_info("rmini") + }) expect_type(package_info, "list") expect_named( package_info, @@ -149,7 +154,7 @@ test_that("get_individual_package_info collects information for GitHub packages ) expect_identical( package_info[["rmini"]][["version"]], - as.character(utils::packageVersion("rmini")) + "0.0.4" ) expect_identical( package_info[["rmini"]][["library"]], From 24bbd9677b8682ebae84ca90c5a0b1b204a87e05 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 14:21:16 +0100 Subject: [PATCH 23/90] refactor package info expectations --- tests/testthat/test-get_package_info.R | 234 +++++++++++-------------- 1 file changed, 100 insertions(+), 134 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index ebadc6e8..cc9ac11f 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -13,28 +13,90 @@ logger::log_appender(logger::appender_stdout) logger::log_threshold(logger::FATAL) logger::log_layout(logger::layout_simple) -test_that("get_individual_package_info collects information for CRAN packages correctly", { #nolint: line_length_linter - expect_identical( - get_individual_package_info("digest"), - list( - digest = list( - package = "digest", - version = as.character(utils::packageVersion("digest")), - library = .libPaths()[1], #nolint: undesirable_function_linter - repository = "CRAN", - platform = strsplit( - x = utils::packageDescription("digest")[["Built"]], - split = "; ", - fixed = TRUE - )[[1L]][[2L]], - built = utils::packageDescription("digest")[["Built"]], - remotetype = "standard", - remotepkgref = "digest", - remoteref = "digest", - remotesha = as.character(utils::packageVersion("digest")) - ) +expect_package_info <- function( + package_info, + package_identical, + version_identical, + library_identical, + repository_identical, + remotetype_identical, + remotepkgref_match, + remoteref_identical, + remotesha_identical +) { + testthat::expect_type(package_info, "list") + testthat::expect_named( + package_info, + package_identical + ) + testthat::expect_named( + package_info[[package_identical]], + c( + "package", + "version", + "library", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" ) ) + testthat::expect_identical( + package_info[[package_identical]][["package"]], + package_identical + ) + testthat::expect_identical( + package_info[[package_identical]][["version"]], + version_identical + ) + testthat::expect_identical( + package_info[[package_identical]][["library"]], + library_identical + ) + testthat::expect_identical( + package_info[[package_identical]][["repository"]], + repository_identical + ) + testthat::expect_identical( + package_info[[package_identical]][["platform"]], + R.version[["platform"]] + ) + testthat::expect_false( + is.null(package_info[[package_identical]][["built"]]) + ) + testthat::expect_identical( + package_info[[package_identical]][["remotetype"]], + remotetype_identical + ) + testthat::expect_match( + package_info[[package_identical]][["remotepkgref"]], + remotepkgref_match + ) + testthat::expect_identical( + package_info[[package_identical]][["remoteref"]], + remoteref_identical + ) + testthat::expect_identical( + package_info[[package_identical]][["remotesha"]], + remotesha_identical + ) +} + +test_that("get_individual_package_info collects information for CRAN packages correctly", { #nolint: line_length_linter + expect_package_info( + package_info = get_individual_package_info("digest"), + package_identical = "digest", + version_identical = as.character(utils::packageVersion("digest")), + library_identical = .libPaths()[1], #nolint: undesirable_function_linter + repository_identical = "CRAN", + remotetype_identical = "standard", + remotepkgref_match = "^digest$", + remoteref_identical = "digest", + remotesha_identical = as.character(utils::packageVersion("digest")) + ) }) with_local_install <- function(new_lib, package, code) { @@ -60,64 +122,16 @@ test_that("get_individual_package_info collects information for local packages c package_info <- with_local_install(new_lib, dest_dir, { get_individual_package_info("rmini") }) - expect_type(package_info, "list") - expect_named( + expect_package_info( package_info, - "rmini" - ) - expect_named( - package_info[["rmini"]], - c( - "package", - "version", - "library", - "repository", - "platform", - "built", - "remotetype", - "remotepkgref", - "remoteref", - "remotesha" - ) - ) - expect_identical( - package_info[["rmini"]][["package"]], - "rmini" - ) - expect_identical( - package_info[["rmini"]][["version"]], - "0.0.4" - ) - expect_identical( - package_info[["rmini"]][["library"]], - normalizePath(new_lib) - ) - expect_identical( - package_info[["rmini"]][["repository"]], - NA_character_ - ) - expect_identical( - package_info[["rmini"]][["platform"]], - R.version[["platform"]] - ) - expect_false( - is.null(package_info[["rmini"]][["built"]]) - ) - expect_identical( - package_info[["rmini"]][["remotetype"]], - "local" - ) - expect_match( - package_info[["rmini"]][["remotepkgref"]], - paste0("^local::/.*", basename(dest_dir)) - ) - expect_identical( - package_info[["rmini"]][["remoteref"]], - NA_character_ - ) - expect_identical( - package_info[["rmini"]][["remotesha"]], - NA_character_ + package_identical = "rmini", + version_identical = "0.0.4", + library_identical = normalizePath(new_lib), + repository_identical = NA_character_, + remotetype_identical = "local", + remotepkgref_match = paste0("^local::", dest_dir, "$"), + remoteref_identical = NA_character_, + remotesha_identical = NA_character_ ) }) @@ -128,63 +142,15 @@ test_that("get_individual_package_info collects information for GitHub packages package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter get_individual_package_info("rmini") }) - expect_type(package_info, "list") - expect_named( + expect_package_info( package_info, - "rmini" - ) - expect_named( - package_info[["rmini"]], - c( - "package", - "version", - "library", - "repository", - "platform", - "built", - "remotetype", - "remotepkgref", - "remoteref", - "remotesha" - ) - ) - expect_identical( - package_info[["rmini"]][["package"]], - "rmini" - ) - expect_identical( - package_info[["rmini"]][["version"]], - "0.0.4" - ) - expect_identical( - package_info[["rmini"]][["library"]], - normalizePath(new_lib) - ) - expect_identical( - package_info[["rmini"]][["repository"]], - NA_character_ - ) - expect_identical( - package_info[["rmini"]][["platform"]], - R.version[["platform"]] - ) - expect_false( - is.null(package_info[["rmini"]][["built"]]) - ) - expect_identical( - package_info[["rmini"]][["remotetype"]], - "github" - ) - expect_match( - package_info[["rmini"]][["remotepkgref"]], - "yihui/rmini" #nolint: nonportable_path_linter - ) - expect_identical( - package_info[["rmini"]][["remoteref"]], - "HEAD" - ) - expect_identical( - package_info[["rmini"]][["remotesha"]], - "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + package_identical = "rmini", + version_identical = "0.0.4", + library_identical = normalizePath(new_lib), + repository_identical = NA_character_, + remotetype_identical = "github", + remotepkgref_match = "^yihui/rmini", #nolint: nonportable_path_linter + remoteref_identical = "HEAD", + remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) }) From 9788431cc0375f8cf30bdf1fb333e5dac7b42947 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 15:21:45 +0100 Subject: [PATCH 24/90] Allow matching for repo --- tests/testthat/test-get_package_info.R | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index cc9ac11f..e9889e78 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -18,7 +18,7 @@ expect_package_info <- function( package_identical, version_identical, library_identical, - repository_identical, + repository_match, remotetype_identical, remotepkgref_match, remoteref_identical, @@ -56,10 +56,17 @@ expect_package_info <- function( package_info[[package_identical]][["library"]], library_identical ) - testthat::expect_identical( - package_info[[package_identical]][["repository"]], - repository_identical - ) + if (is.na(repository_match)) { + testthat::expect_identical( + package_info[[package_identical]][["repository"]], + repository_match + ) + } else { + testthat::expect_match( + package_info[[package_identical]][["repository"]], + repository_match + ) + } testthat::expect_identical( package_info[[package_identical]][["platform"]], R.version[["platform"]] @@ -91,7 +98,7 @@ test_that("get_individual_package_info collects information for CRAN packages co package_identical = "digest", version_identical = as.character(utils::packageVersion("digest")), library_identical = .libPaths()[1], #nolint: undesirable_function_linter - repository_identical = "CRAN", + repository_match = "^(CRAN|RSPM)$", #GH Actions installs from RSPM, not CRAN remotetype_identical = "standard", remotepkgref_match = "^digest$", remoteref_identical = "digest", @@ -127,7 +134,7 @@ test_that("get_individual_package_info collects information for local packages c package_identical = "rmini", version_identical = "0.0.4", library_identical = normalizePath(new_lib), - repository_identical = NA_character_, + repository_match = NA_character_, remotetype_identical = "local", remotepkgref_match = paste0("^local::", dest_dir, "$"), remoteref_identical = NA_character_, @@ -147,7 +154,7 @@ test_that("get_individual_package_info collects information for GitHub packages package_identical = "rmini", version_identical = "0.0.4", library_identical = normalizePath(new_lib), - repository_identical = NA_character_, + repository_match = NA_character_, remotetype_identical = "github", remotepkgref_match = "^yihui/rmini", #nolint: nonportable_path_linter remoteref_identical = "HEAD", From 1a5233b381544a0382bba618c9305f24fbc87685 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 16:35:17 +0100 Subject: [PATCH 25/90] Change from `git2r` to `gert` --- tests/testthat/test-get_package_info.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index e9889e78..b5160305 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -120,9 +120,9 @@ test_that("get_individual_package_info collects information for local packages c testthat::skip_on_cran() testthat::skip_if_offline() dest_dir <- normalizePath(withr::local_tempdir()) - dl <- git2r::clone( + dl <- gert::git_clone( url = "https://github.com/yihui/rmini.git", #nolint: nonportable_path_linter - local_path = dest_dir, + path = dest_dir, progress = FALSE ) new_lib <- normalizePath(withr::local_tempdir()) From 4096ad8f7c114c46a8950e46ef3229139c84a396 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 16:37:49 +0100 Subject: [PATCH 26/90] Chagne dependency in DESCRIPTION --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 45542b03..2e0b7f56 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,7 @@ Imports: logger, pkgdepends Suggests: - git2r, + gert, pak, testthat (>= 3.0.0), withr From 408825e30ae116b52c6bcfa48062320302f701cd Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 16:43:14 +0100 Subject: [PATCH 27/90] Change argument name --- tests/testthat/test-get_package_info.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index b5160305..014abb54 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -123,7 +123,7 @@ test_that("get_individual_package_info collects information for local packages c dl <- gert::git_clone( url = "https://github.com/yihui/rmini.git", #nolint: nonportable_path_linter path = dest_dir, - progress = FALSE + verbose = FALSE ) new_lib <- normalizePath(withr::local_tempdir()) package_info <- with_local_install(new_lib, dest_dir, { From 21b1b4f5f78f4910f9e1f9cb5429a67e257d4270 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 17:06:18 +0100 Subject: [PATCH 28/90] explicitly define pak sources --- tests/testthat/test-get_package_info.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 014abb54..a241edd0 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -126,7 +126,7 @@ test_that("get_individual_package_info collects information for local packages c verbose = FALSE ) new_lib <- normalizePath(withr::local_tempdir()) - package_info <- with_local_install(new_lib, dest_dir, { + package_info <- with_local_install(new_lib, paste0("local::", dest_dir), { get_individual_package_info("rmini") }) expect_package_info( @@ -146,7 +146,7 @@ test_that("get_individual_package_info collects information for GitHub packages testthat::skip_on_cran() testthat::skip_if_offline() new_lib <- normalizePath(withr::local_tempdir()) - package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter + package_info <- with_local_install(new_lib, "github::yihui/rmini", { #nolint: nonportable_path_linter get_individual_package_info("rmini") }) expect_package_info( From e932448d815f44fc62241fd3bbc5e3bb31241883 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 17:10:41 +0100 Subject: [PATCH 29/90] better define matching regex --- tests/testthat/test-get_package_info.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index a241edd0..b5a8a46e 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -146,7 +146,7 @@ test_that("get_individual_package_info collects information for GitHub packages testthat::skip_on_cran() testthat::skip_if_offline() new_lib <- normalizePath(withr::local_tempdir()) - package_info <- with_local_install(new_lib, "github::yihui/rmini", { #nolint: nonportable_path_linter + package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter get_individual_package_info("rmini") }) expect_package_info( @@ -156,7 +156,7 @@ test_that("get_individual_package_info collects information for GitHub packages library_identical = normalizePath(new_lib), repository_match = NA_character_, remotetype_identical = "github", - remotepkgref_match = "^yihui/rmini", #nolint: nonportable_path_linter + remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter remoteref_identical = "HEAD", remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) From cd0fcb00d9a6c27fca0c2ad50a28638e62af00f1 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 19:05:26 +0100 Subject: [PATCH 30/90] add libPaths to session info --- R/get_environment.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/get_environment.R b/R/get_environment.R index 9a3405f4..937d0f4c 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -19,7 +19,8 @@ get_r_session_info <- function() { platform = utils::sessionInfo()[["platform"]], running = utils::sessionInfo()[["running"]], locale = utils::sessionInfo()[["locale"]], - tzone = utils::sessionInfo()[["tzone"]] + tzone = utils::sessionInfo()[["tzone"]], + libPaths = .libPaths() ) ) } From 09d54c8faa7bd21e50e6201298d9ce0f433899a0 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 19:12:49 +0100 Subject: [PATCH 31/90] Convert filepath sep in expectations --- tests/testthat/test-get_package_info.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index b5a8a46e..7a8217bb 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -54,7 +54,8 @@ expect_package_info <- function( ) testthat::expect_identical( package_info[[package_identical]][["library"]], - library_identical + # gsub is used to make windows path into something matching .libPaths() + gsub(x = library_identical, pattern = "[\\]", replacement = "/"), ) if (is.na(repository_match)) { testthat::expect_identical( @@ -133,7 +134,7 @@ test_that("get_individual_package_info collects information for local packages c package_info, package_identical = "rmini", version_identical = "0.0.4", - library_identical = normalizePath(new_lib), + library_identical = new_lib, repository_match = NA_character_, remotetype_identical = "local", remotepkgref_match = paste0("^local::", dest_dir, "$"), @@ -153,7 +154,7 @@ test_that("get_individual_package_info collects information for GitHub packages package_info, package_identical = "rmini", version_identical = "0.0.4", - library_identical = normalizePath(new_lib), + library_identical = new_lib, repository_match = NA_character_, remotetype_identical = "github", remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter From bfb3f7a3de46b7d538fbc1953cd4efab1cb8f439 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 19:25:07 +0100 Subject: [PATCH 32/90] Add updated libpaths to tests --- tests/testthat/test-get_environment.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_environment.R b/tests/testthat/test-get_environment.R index c1bcc3cd..dc6f0280 100644 --- a/tests/testthat/test-get_environment.R +++ b/tests/testthat/test-get_environment.R @@ -21,7 +21,8 @@ test_that("get_single_file_metadata processes CSV tables correctly", { platform = utils::sessionInfo()[["platform"]], running = utils::sessionInfo()[["running"]], locale = utils::sessionInfo()[["locale"]], - tzone = utils::sessionInfo()[["tzone"]] + tzone = utils::sessionInfo()[["tzone"]], + libPaths = .libPaths() ) ) }) From 5079cc85c858804d6c72169f1504bfe2d1397dd7 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 19:31:19 +0100 Subject: [PATCH 33/90] Add fix for remotepkgref on Windows --- tests/testthat/test-get_package_info.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 7a8217bb..5708a2a7 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -81,7 +81,8 @@ expect_package_info <- function( ) testthat::expect_match( package_info[[package_identical]][["remotepkgref"]], - remotepkgref_match + # gsub is used to make windows path into something matching .libPaths() + gsub(x = remotepkgref_match, pattern = "[\\]", replacement = "\\\\"), ) testthat::expect_identical( package_info[[package_identical]][["remoteref"]], From ef590c615b85240c1ec4652699c7d206109ae19c Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 19:32:29 +0100 Subject: [PATCH 34/90] nolint --- tests/testthat/test-get_environment.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get_environment.R b/tests/testthat/test-get_environment.R index dc6f0280..e4de41ab 100644 --- a/tests/testthat/test-get_environment.R +++ b/tests/testthat/test-get_environment.R @@ -22,7 +22,7 @@ test_that("get_single_file_metadata processes CSV tables correctly", { running = utils::sessionInfo()[["running"]], locale = utils::sessionInfo()[["locale"]], tzone = utils::sessionInfo()[["tzone"]], - libPaths = .libPaths() + libPaths = .libPaths() # nolint: undesirable_function_linter ) ) }) From 8825b7654143baf422e742719ddb86645bc8ac63 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 19:34:17 +0100 Subject: [PATCH 35/90] Add test for missing package --- tests/testthat/test-get_package_info.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 5708a2a7..9cae5927 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -163,3 +163,10 @@ test_that("get_individual_package_info collects information for GitHub packages remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) }) + +test_that("get_individual_package_info errors for package that doesn't exist", { #nolint: line_length_linter + expect_error( + get_individual_package_info("this_package_does_not_exist"), + ) +}) + From 41f40b5821cf95609fc61aeb77e3efb47aae66ad Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Wed, 20 Mar 2024 19:44:49 +0100 Subject: [PATCH 36/90] Switch pattern and replacement in file path fix --- tests/testthat/test-get_package_info.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 9cae5927..b098c598 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -82,7 +82,7 @@ expect_package_info <- function( testthat::expect_match( package_info[[package_identical]][["remotepkgref"]], # gsub is used to make windows path into something matching .libPaths() - gsub(x = remotepkgref_match, pattern = "[\\]", replacement = "\\\\"), + gsub(x = remotepkgref_match, pattern = "[\\\\]", replacement = "\\"), ) testthat::expect_identical( package_info[[package_identical]][["remoteref"]], @@ -166,7 +166,7 @@ test_that("get_individual_package_info collects information for GitHub packages test_that("get_individual_package_info errors for package that doesn't exist", { #nolint: line_length_linter expect_error( - get_individual_package_info("this_package_does_not_exist"), + get_individual_package_info("this_package_does_not_exist") ) }) From 930a8ad56e154b077326fc8beecea6936eb087a8 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 09:55:59 +0100 Subject: [PATCH 37/90] add lintr exclusion --- R/get_environment.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/get_environment.R b/R/get_environment.R index 937d0f4c..ca55ba22 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -20,7 +20,7 @@ get_r_session_info <- function() { running = utils::sessionInfo()[["running"]], locale = utils::sessionInfo()[["locale"]], tzone = utils::sessionInfo()[["tzone"]], - libPaths = .libPaths() + libPaths = .libPaths() # nolint: undesirable_function_linter ) ) } From 22498513aed614023164c4aa62f490cf60c2d814 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 10:01:10 +0100 Subject: [PATCH 38/90] Add check for singularity --- R/get_environment.R | 51 +++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index ca55ba22..32a52dd0 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -63,27 +63,32 @@ get_package_info <- function( } get_individual_package_info <- function(packagename) { - log_trace("Getting package info for {packagename}.") - pkg_details <- as.list(pkgdepends::lib_status(packages = packagename)) - details_list <- list( - package = pkg_details[["package"]], - version = pkg_details[["version"]], - library = pkg_details[["library"]], - repository = pkg_details[["repository"]], - platform = pkg_details[["platform"]], - built = pkg_details[["built"]], - remotetype = pkg_details[["remotetype"]], - remotepkgref = pkg_details[["remotepkgref"]], - remoteref = pkg_details[["remoteref"]], - remotesha = pkg_details[["remotesha"]] - ) - clean_details_list <- lapply( - X = details_list, - FUN = function(x) { - ifelse(is.null(x), NA_character_, x) - } - ) - output <- list() - output[[packagename]] <- clean_details_list - return(output) + if (length(packagename) != 1 || !is.character(packagename)) { + log_error("packagename must be a single string.") + stop("packagename must be a single string.") + } else { + log_trace("Getting package info for {packagename}.") + pkg_details <- as.list(pkgdepends::lib_status(packages = packagename)) + details_list <- list( + package = pkg_details[["package"]], + version = pkg_details[["version"]], + library = pkg_details[["library"]], + repository = pkg_details[["repository"]], + platform = pkg_details[["platform"]], + built = pkg_details[["built"]], + remotetype = pkg_details[["remotetype"]], + remotepkgref = pkg_details[["remotepkgref"]], + remoteref = pkg_details[["remoteref"]], + remotesha = pkg_details[["remotesha"]] + ) + clean_details_list <- lapply( + X = details_list, + FUN = function(x) { + ifelse(is.null(x), NA_character_, x) + } + ) + output <- list() + output[[packagename]] <- clean_details_list + return(output) + } } From 80f1c23c77c7d9bd1798d250a54a1e5f8ec26543 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 10:03:17 +0100 Subject: [PATCH 39/90] Add test for singularity --- tests/testthat/test-get_package_info.R | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index b098c598..d1264c4b 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -82,7 +82,12 @@ expect_package_info <- function( testthat::expect_match( package_info[[package_identical]][["remotepkgref"]], # gsub is used to make windows path into something matching .libPaths() - gsub(x = remotepkgref_match, pattern = "[\\\\]", replacement = "\\"), + gsub( + x = remotepkgref_match, + pattern = "[\\\\]", + replacement = "\\", + fixed = TRUE + ), ) testthat::expect_identical( package_info[[package_identical]][["remoteref"]], @@ -164,6 +169,12 @@ test_that("get_individual_package_info collects information for GitHub packages ) }) +test_that("get_individual_package_info errors for multiple packages", { #nolint: line_length_linter + expect_error( + get_individual_package_info(c("digest", "jsonlite")) + ) +}) + test_that("get_individual_package_info errors for package that doesn't exist", { #nolint: line_length_linter expect_error( get_individual_package_info("this_package_does_not_exist") From 17d3782f0ec32c08deef0fa6d883b67e7b5d5f0f Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 10:54:10 +0100 Subject: [PATCH 40/90] Add check for package existence --- R/get_environment.R | 57 +++++++++++++++----------- tests/testthat/test-get_package_info.R | 13 ++++++ 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index 32a52dd0..7ddd7e69 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -63,32 +63,41 @@ get_package_info <- function( } get_individual_package_info <- function(packagename) { - if (length(packagename) != 1 || !is.character(packagename)) { + if (length(packagename) != 1L || !is.character(packagename)) { log_error("packagename must be a single string.") stop("packagename must be a single string.") } else { - log_trace("Getting package info for {packagename}.") - pkg_details <- as.list(pkgdepends::lib_status(packages = packagename)) - details_list <- list( - package = pkg_details[["package"]], - version = pkg_details[["version"]], - library = pkg_details[["library"]], - repository = pkg_details[["repository"]], - platform = pkg_details[["platform"]], - built = pkg_details[["built"]], - remotetype = pkg_details[["remotetype"]], - remotepkgref = pkg_details[["remotepkgref"]], - remoteref = pkg_details[["remoteref"]], - remotesha = pkg_details[["remotesha"]] - ) - clean_details_list <- lapply( - X = details_list, - FUN = function(x) { - ifelse(is.null(x), NA_character_, x) - } - ) - output <- list() - output[[packagename]] <- clean_details_list - return(output) + if (packagename %in% installed.packages()[, "Package"]) { + log_trace( + "Package \"{packagename}\" is installed at", + "{installed.packages()[packagename, \"LibPath\"]}." + ) + } else { + log_error("Package \"{packagename}\" is not installed.") + stop("Package is not installed.") + } } + log_trace("Getting package info for {packagename}.") + pkg_details <- as.list(pkgdepends::lib_status(packages = packagename)) + details_list <- list( + package = pkg_details[["package"]], + version = pkg_details[["version"]], + library = pkg_details[["library"]], + repository = pkg_details[["repository"]], + platform = pkg_details[["platform"]], + built = pkg_details[["built"]], + remotetype = pkg_details[["remotetype"]], + remotepkgref = pkg_details[["remotepkgref"]], + remoteref = pkg_details[["remoteref"]], + remotesha = pkg_details[["remotesha"]] + ) + clean_details_list <- lapply( + X = details_list, + FUN = function(x) { + ifelse(is.null(x), NA_character_, x) + } + ) + output <- list() + output[[packagename]] <- clean_details_list + return(output) } diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index d1264c4b..97166854 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -181,3 +181,16 @@ test_that("get_individual_package_info errors for package that doesn't exist", { ) }) +test_that("get_individual_package_info errors for empty string", { #nolint: line_length_linter + expect_error( + get_individual_package_info("") + ) +}) + +test_that("get_individual_package_info errors for no arguments", { #nolint: line_length_linter + expect_error( + get_individual_package_info(), + "^argument \"packagename\" is missing, with no default$" + ) +}) + From df2f2967f75719828524918ec465866290919b54 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 10:56:31 +0100 Subject: [PATCH 41/90] clean up unneeded nolints --- tests/testthat/test-get_package_info.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 97166854..8a71a547 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -169,25 +169,25 @@ test_that("get_individual_package_info collects information for GitHub packages ) }) -test_that("get_individual_package_info errors for multiple packages", { #nolint: line_length_linter +test_that("get_individual_package_info errors for multiple packages", { expect_error( get_individual_package_info(c("digest", "jsonlite")) ) }) -test_that("get_individual_package_info errors for package that doesn't exist", { #nolint: line_length_linter +test_that("get_individual_package_info errors for package that doesn't exist", { expect_error( get_individual_package_info("this_package_does_not_exist") ) }) -test_that("get_individual_package_info errors for empty string", { #nolint: line_length_linter +test_that("get_individual_package_info errors for empty string", { expect_error( get_individual_package_info("") ) }) -test_that("get_individual_package_info errors for no arguments", { #nolint: line_length_linter +test_that("get_individual_package_info errors for no arguments", { expect_error( get_individual_package_info(), "^argument \"packagename\" is missing, with no default$" From 286e7707a53f7b1a30a4e59b5967f1e64ddf1bad Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 11:29:44 +0100 Subject: [PATCH 42/90] add check for multiple installations of package --- R/get_environment.R | 18 ++++++++++++++---- tests/testthat/test-get_package_info.R | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index 7ddd7e69..f7be8872 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -68,10 +68,19 @@ get_individual_package_info <- function(packagename) { stop("packagename must be a single string.") } else { if (packagename %in% installed.packages()[, "Package"]) { - log_trace( - "Package \"{packagename}\" is installed at", - "{installed.packages()[packagename, \"LibPath\"]}." - ) + installed_index <- which(installed.packages()[, "Package"] == packagename) + installed_path <- installed.packages()[installed_index, "LibPath"] + if (length(installed_path) > 1L) { + log_warn( + "Multiple installations of package \"{packagename}\" found: ", + "{installed_path}" + ) + log_warn("Using installation first on the search path.") + warning("Multiple installations of package found.") + } + lib_index <- min(which(.libPaths() == installed_path)) + lib <- .libPaths()[lib_index] #nolint: undesirable_function_linter + log_trace("Package \"{packagename}\" is installed at {lib}") } else { log_error("Package \"{packagename}\" is not installed.") stop("Package is not installed.") @@ -83,6 +92,7 @@ get_individual_package_info <- function(packagename) { package = pkg_details[["package"]], version = pkg_details[["version"]], library = pkg_details[["library"]], + library_index = lib_index, repository = pkg_details[["repository"]], platform = pkg_details[["platform"]], built = pkg_details[["built"]], diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 8a71a547..e0781912 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -194,3 +194,21 @@ test_that("get_individual_package_info errors for no arguments", { ) }) +logger::with_log_threshold({ + +test_that("get_individual_package_info gets correct libpath for multiple installs", { #nolint: line_length_linter + testthat::skip_on_cran() + testthat::skip_if_offline() + new_lib <- normalizePath(withr::local_tempdir()) + newer_lib <- normalizePath(withr::local_tempdir()) + package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter + with_local_install(newer_lib, "yihui/rmini", { #nolint: nonportable_path_linter + expect_warning( + get_individual_package_info("rmini"), + "^Multiple installations of package found.$" + ) +}) + }) +}) + +}, threshold = logger::TRACE) From 941044a50a186772b259cfadcbd6db2a7785c25c Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 11:41:34 +0100 Subject: [PATCH 43/90] add test for libpaths down the search tree --- tests/testthat/test-get_package_info.R | 87 ++++++++++++++++++++------ 1 file changed, 67 insertions(+), 20 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index e0781912..1f14731e 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -23,7 +23,7 @@ expect_package_info <- function( remotepkgref_match, remoteref_identical, remotesha_identical -) { + ) { testthat::expect_type(package_info, "list") testthat::expect_named( package_info, @@ -35,6 +35,7 @@ expect_package_info <- function( "package", "version", "library", + "library_index", "repository", "platform", "built", @@ -57,6 +58,14 @@ expect_package_info <- function( # gsub is used to make windows path into something matching .libPaths() gsub(x = library_identical, pattern = "[\\]", replacement = "/"), ) + testthat::expect_type( + package_info[[package_identical]][["library_index"]], + "integer" + ) + testthat::expect_true( + package_info[[package_identical]][["library_index"]] > 0 && + package_info[[package_identical]][["library_index"]] <= length(.libPaths()) #nolint: undesirable_function_linter + ) if (is.na(repository_match)) { testthat::expect_identical( package_info[[package_identical]][["repository"]], @@ -87,7 +96,7 @@ expect_package_info <- function( pattern = "[\\\\]", replacement = "\\", fixed = TRUE - ), + ), ) testthat::expect_identical( package_info[[package_identical]][["remoteref"]], @@ -111,7 +120,7 @@ test_that("get_individual_package_info collects information for CRAN packages co remoteref_identical = "digest", remotesha_identical = as.character(utils::packageVersion("digest")) ) -}) + }) with_local_install <- function(new_lib, package, code) { cache_dir <- withr::local_tempdir() @@ -147,7 +156,7 @@ test_that("get_individual_package_info collects information for local packages c remoteref_identical = NA_character_, remotesha_identical = NA_character_ ) -}) + }) test_that("get_individual_package_info collects information for GitHub packages correctly", { #nolint: line_length_linter testthat::skip_on_cran() @@ -167,48 +176,86 @@ test_that("get_individual_package_info collects information for GitHub packages remoteref_identical = "HEAD", remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) -}) + }) test_that("get_individual_package_info errors for multiple packages", { expect_error( get_individual_package_info(c("digest", "jsonlite")) ) -}) + }) test_that("get_individual_package_info errors for package that doesn't exist", { expect_error( get_individual_package_info("this_package_does_not_exist") ) -}) + }) test_that("get_individual_package_info errors for empty string", { expect_error( get_individual_package_info("") ) -}) + }) test_that("get_individual_package_info errors for no arguments", { expect_error( get_individual_package_info(), "^argument \"packagename\" is missing, with no default$" ) -}) + }) -logger::with_log_threshold({ +# test_that("get_individual_package_info gets correct libpath for multiple installs", { #nolint: line_length_linter +# testthat::skip_on_cran() +# testthat::skip_if_offline() +# new_lib <- normalizePath(withr::local_tempdir()) +# newer_lib <- normalizePath(withr::local_tempdir()) +# package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter +# with_local_install(newer_lib, "yihui/rmini", { #nolint: nonportable_path_linter +# expect_warning( +# get_individual_package_info("rmini"), +# "^Multiple installations of package found.$" +# ) +# }) +# }) +# expect_package_info( +# package_info, +# package_identical = "rmini", +# version_identical = "0.0.4", +# library_identical = newer_lib, +# repository_match = NA_character_, +# remotetype_identical = "github", +# remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter +# remoteref_identical = "HEAD", +# remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" +# ) +# # expect_identical( +# # package_info[["rmini"]][["library_index"]], +# # 1L +# # ) +# }) -test_that("get_individual_package_info gets correct libpath for multiple installs", { #nolint: line_length_linter +test_that("get_individual_package_info gets correct libpath for lower search priority", { #nolint: line_length_linter testthat::skip_on_cran() testthat::skip_if_offline() new_lib <- normalizePath(withr::local_tempdir()) newer_lib <- normalizePath(withr::local_tempdir()) - package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter - with_local_install(newer_lib, "yihui/rmini", { #nolint: nonportable_path_linter - expect_warning( - get_individual_package_info("rmini"), - "^Multiple installations of package found.$" - ) -}) + package_info <- with_local_install(new_lib, "yihui/rmini", { + with_local_install(newer_lib, "digest", { #nolint: nonportable_path_linter + get_individual_package_info("rmini") + }) }) + expect_package_info( + package_info, + package_identical = "rmini", + version_identical = "0.0.4", + library_identical = newer_lib, + repository_match = NA_character_, + remotetype_identical = "github", + remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter + remoteref_identical = "HEAD", + remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + ) + expect_identical( + package_info[["rmini"]][["library_index"]], + 2L + ) }) - -}, threshold = logger::TRACE) From 5cab781a4ce8fe6bb4d36f0245495c9b8397e6f2 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 12:00:57 +0100 Subject: [PATCH 44/90] Fix behavior for down-search-path libraries --- R/get_environment.R | 9 +++- tests/testthat/test-get_package_info.R | 59 +++++++++++++------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index f7be8872..b27ca847 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -78,7 +78,7 @@ get_individual_package_info <- function(packagename) { log_warn("Using installation first on the search path.") warning("Multiple installations of package found.") } - lib_index <- min(which(.libPaths() == installed_path)) + lib_index <- min(which(.libPaths() == installed_path)) #nolint: undesirable_function_linter lib <- .libPaths()[lib_index] #nolint: undesirable_function_linter log_trace("Package \"{packagename}\" is installed at {lib}") } else { @@ -87,7 +87,12 @@ get_individual_package_info <- function(packagename) { } } log_trace("Getting package info for {packagename}.") - pkg_details <- as.list(pkgdepends::lib_status(packages = packagename)) + pkg_details <- as.list( + pkgdepends::lib_status( + library = lib, + packages = packagename + ) + ) details_list <- list( package = pkg_details[["package"]], version = pkg_details[["version"]], diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 1f14731e..9bb5d423 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -203,35 +203,34 @@ test_that("get_individual_package_info errors for no arguments", { ) }) -# test_that("get_individual_package_info gets correct libpath for multiple installs", { #nolint: line_length_linter -# testthat::skip_on_cran() -# testthat::skip_if_offline() -# new_lib <- normalizePath(withr::local_tempdir()) -# newer_lib <- normalizePath(withr::local_tempdir()) -# package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter -# with_local_install(newer_lib, "yihui/rmini", { #nolint: nonportable_path_linter -# expect_warning( -# get_individual_package_info("rmini"), -# "^Multiple installations of package found.$" -# ) -# }) -# }) -# expect_package_info( -# package_info, -# package_identical = "rmini", -# version_identical = "0.0.4", -# library_identical = newer_lib, -# repository_match = NA_character_, -# remotetype_identical = "github", -# remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter -# remoteref_identical = "HEAD", -# remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" -# ) -# # expect_identical( -# # package_info[["rmini"]][["library_index"]], -# # 1L -# # ) -# }) +test_that("get_individual_package_info gets correct libpath for multiple installs", { #nolint: line_length_linter + testthat::skip_on_cran() + testthat::skip_if_offline() + new_lib <- normalizePath(withr::local_tempdir()) + newer_lib <- normalizePath(withr::local_tempdir()) + expect_warning( + package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter + with_local_install(newer_lib, "yihui/rmini", { #nolint: nonportable_path_linter + get_individual_package_info("rmini") + }) + }) + ) + expect_package_info( + package_info, + package_identical = "rmini", + version_identical = "0.0.4", + library_identical = newer_lib, + repository_match = NA_character_, + remotetype_identical = "github", + remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter + remoteref_identical = "HEAD", + remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + ) + expect_identical( + package_info[["rmini"]][["library_index"]], + 1L + ) + }) test_that("get_individual_package_info gets correct libpath for lower search priority", { #nolint: line_length_linter testthat::skip_on_cran() @@ -247,7 +246,7 @@ test_that("get_individual_package_info gets correct libpath for lower search pri package_info, package_identical = "rmini", version_identical = "0.0.4", - library_identical = newer_lib, + library_identical = new_lib, repository_match = NA_character_, remotetype_identical = "github", remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter From eafbc8568e9ceca63fac9c1d7d5c11fb33768dc5 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 12:04:40 +0100 Subject: [PATCH 45/90] namespace `utils::installed.packages()` --- R/get_environment.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index b27ca847..73f823d7 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -67,9 +67,9 @@ get_individual_package_info <- function(packagename) { log_error("packagename must be a single string.") stop("packagename must be a single string.") } else { - if (packagename %in% installed.packages()[, "Package"]) { - installed_index <- which(installed.packages()[, "Package"] == packagename) - installed_path <- installed.packages()[installed_index, "LibPath"] + if (packagename %in% utils::installed.packages()[, "Package"]) { + installed_index <- which(utils::installed.packages()[, "Package"] == packagename) + installed_path <- utils::installed.packages()[installed_index, "LibPath"] if (length(installed_path) > 1L) { log_warn( "Multiple installations of package \"{packagename}\" found: ", From 4a8f591ee63f20a12c343562a3ac0d4983e9ad76 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 12:10:36 +0100 Subject: [PATCH 46/90] fix IMCOMPLETE_STRING lintr error --- tests/testthat/test-get_package_info.R | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 9bb5d423..2b7a9ec0 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -56,7 +56,12 @@ expect_package_info <- function( testthat::expect_identical( package_info[[package_identical]][["library"]], # gsub is used to make windows path into something matching .libPaths() - gsub(x = library_identical, pattern = "[\\]", replacement = "/"), + gsub( + x = library_identical, + pattern = "\\", + replacement = "/", + fixed = TRUE + ) ) testthat::expect_type( package_info[[package_identical]][["library_index"]], @@ -90,13 +95,7 @@ expect_package_info <- function( ) testthat::expect_match( package_info[[package_identical]][["remotepkgref"]], - # gsub is used to make windows path into something matching .libPaths() - gsub( - x = remotepkgref_match, - pattern = "[\\\\]", - replacement = "\\", - fixed = TRUE - ), + remotepkgref_match, ) testthat::expect_identical( package_info[[package_identical]][["remoteref"]], From daf35267655ef5d13af2c3056fe2b952988a6443 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 12:13:51 +0100 Subject: [PATCH 47/90] Linting --- R/get_environment.R | 4 +++- tests/testthat/test-get_package_info.R | 33 ++++++++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index 73f823d7..9cf4adf5 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -68,7 +68,9 @@ get_individual_package_info <- function(packagename) { stop("packagename must be a single string.") } else { if (packagename %in% utils::installed.packages()[, "Package"]) { - installed_index <- which(utils::installed.packages()[, "Package"] == packagename) + installed_index <- which( + utils::installed.packages()[, "Package"] == packagename + ) installed_path <- utils::installed.packages()[installed_index, "LibPath"] if (length(installed_path) > 1L) { log_warn( diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 2b7a9ec0..3ca9b54b 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -23,7 +23,7 @@ expect_package_info <- function( remotepkgref_match, remoteref_identical, remotesha_identical - ) { +) { testthat::expect_type(package_info, "list") testthat::expect_named( package_info, @@ -67,9 +67,12 @@ expect_package_info <- function( package_info[[package_identical]][["library_index"]], "integer" ) - testthat::expect_true( - package_info[[package_identical]][["library_index"]] > 0 && - package_info[[package_identical]][["library_index"]] <= length(.libPaths()) #nolint: undesirable_function_linter + testthat::expect_gt( + package_info[[package_identical]][["library_index"]] > 0L + ) + testthat::expect_lte( + package_info[[package_identical]][["library_index"]], + length(.libPaths()) #nolint: undesirable_function_linter ) if (is.na(repository_match)) { testthat::expect_identical( @@ -95,7 +98,7 @@ expect_package_info <- function( ) testthat::expect_match( package_info[[package_identical]][["remotepkgref"]], - remotepkgref_match, + remotepkgref_match ) testthat::expect_identical( package_info[[package_identical]][["remoteref"]], @@ -119,7 +122,7 @@ test_that("get_individual_package_info collects information for CRAN packages co remoteref_identical = "digest", remotesha_identical = as.character(utils::packageVersion("digest")) ) - }) +}) with_local_install <- function(new_lib, package, code) { cache_dir <- withr::local_tempdir() @@ -155,7 +158,7 @@ test_that("get_individual_package_info collects information for local packages c remoteref_identical = NA_character_, remotesha_identical = NA_character_ ) - }) +}) test_that("get_individual_package_info collects information for GitHub packages correctly", { #nolint: line_length_linter testthat::skip_on_cran() @@ -175,32 +178,32 @@ test_that("get_individual_package_info collects information for GitHub packages remoteref_identical = "HEAD", remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) - }) +}) test_that("get_individual_package_info errors for multiple packages", { expect_error( get_individual_package_info(c("digest", "jsonlite")) ) - }) +}) test_that("get_individual_package_info errors for package that doesn't exist", { expect_error( get_individual_package_info("this_package_does_not_exist") ) - }) +}) test_that("get_individual_package_info errors for empty string", { expect_error( get_individual_package_info("") ) - }) +}) test_that("get_individual_package_info errors for no arguments", { expect_error( get_individual_package_info(), "^argument \"packagename\" is missing, with no default$" ) - }) +}) test_that("get_individual_package_info gets correct libpath for multiple installs", { #nolint: line_length_linter testthat::skip_on_cran() @@ -229,15 +232,15 @@ test_that("get_individual_package_info gets correct libpath for multiple install package_info[["rmini"]][["library_index"]], 1L ) - }) +}) test_that("get_individual_package_info gets correct libpath for lower search priority", { #nolint: line_length_linter testthat::skip_on_cran() testthat::skip_if_offline() new_lib <- normalizePath(withr::local_tempdir()) newer_lib <- normalizePath(withr::local_tempdir()) - package_info <- with_local_install(new_lib, "yihui/rmini", { - with_local_install(newer_lib, "digest", { #nolint: nonportable_path_linter + package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter + with_local_install(newer_lib, "digest", { get_individual_package_info("rmini") }) }) From 9aee81e5a82ae94096e21e08032f14fe0669949d Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 12:14:59 +0100 Subject: [PATCH 48/90] Fix failing test --- tests/testthat/test-get_package_info.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 3ca9b54b..3b13ad09 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -68,7 +68,8 @@ expect_package_info <- function( "integer" ) testthat::expect_gt( - package_info[[package_identical]][["library_index"]] > 0L + package_info[[package_identical]][["library_index"]], + 0L ) testthat::expect_lte( package_info[[package_identical]][["library_index"]], From 631b9263b2647d033dd105a38ac046da66be7e0c Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 12:19:26 +0100 Subject: [PATCH 49/90] Check version as part of multiple installs --- tests/testthat/test-get_package_info.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 3b13ad09..18b0902d 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -206,14 +206,14 @@ test_that("get_individual_package_info errors for no arguments", { ) }) -test_that("get_individual_package_info gets correct libpath for multiple installs", { #nolint: line_length_linter +test_that("get_individual_package_info gets correct libpath fdn version or multiple installs", { #nolint: line_length_linter testthat::skip_on_cran() testthat::skip_if_offline() new_lib <- normalizePath(withr::local_tempdir()) newer_lib <- normalizePath(withr::local_tempdir()) expect_warning( package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter - with_local_install(newer_lib, "yihui/rmini", { #nolint: nonportable_path_linter + with_local_install(newer_lib, "yihui/rmini@308d27d", { #nolint: nonportable_path_linter get_individual_package_info("rmini") }) }) @@ -221,13 +221,13 @@ test_that("get_individual_package_info gets correct libpath for multiple install expect_package_info( package_info, package_identical = "rmini", - version_identical = "0.0.4", + version_identical = "0.0.3", # Note: not latest version library_identical = newer_lib, repository_match = NA_character_, remotetype_identical = "github", - remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter - remoteref_identical = "HEAD", - remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + remotepkgref_match = "^yihui/rmini@308d27d$", #nolint: nonportable_path_linter + remoteref_identical = "308d27d", + remotesha_identical = "308d27ddb0b45fda34fc259492145834d72849a9" ) expect_identical( package_info[["rmini"]][["library_index"]], From 21d76604579474220526ea96b51f4498c176df31 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 12:31:58 +0100 Subject: [PATCH 50/90] Attempt fixing windows paths --- tests/testthat/test-get_package_info.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 18b0902d..c8d0f8ad 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -99,7 +99,13 @@ expect_package_info <- function( ) testthat::expect_match( package_info[[package_identical]][["remotepkgref"]], - remotepkgref_match + # gsub is used to make windows path work + gsub( + x = remotepkgref_match, + pattern = "\\", + replacement = "\\\\", + fixed = TRUE + ) ) testthat::expect_identical( package_info[[package_identical]][["remoteref"]], From 8367fb0ad603c2b1b1fcd09891e972e74638c180 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 14:50:27 +0100 Subject: [PATCH 51/90] reduce strictness for platform check On windows, the package build version can include architecture: ``` `actual`: "i386+x86_64-w64-mingw32" `expected`: "x86_64-w64-mingw32" ``` --- tests/testthat/test-get_package_info.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index c8d0f8ad..ea5d5325 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -86,7 +86,7 @@ expect_package_info <- function( repository_match ) } - testthat::expect_identical( + testthat::expect_match( package_info[[package_identical]][["platform"]], R.version[["platform"]] ) From f48d550e5cbb8f527484d2aeaf681c91b790e78f Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:00:49 +0100 Subject: [PATCH 52/90] reflow tests when altering libpaths against current --- tests/testthat/test-get_package_info.R | 64 +++++++++++++++----------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index ea5d5325..f8f748d9 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -17,7 +17,6 @@ expect_package_info <- function( package_info, package_identical, version_identical, - library_identical, repository_match, remotetype_identical, remotepkgref_match, @@ -53,15 +52,13 @@ expect_package_info <- function( package_info[[package_identical]][["version"]], version_identical ) + testthat::expect_in( + package_info[[package_identical]][["library"]], + .libPaths() #nolint: undesirable_function_linter + ) testthat::expect_identical( package_info[[package_identical]][["library"]], - # gsub is used to make windows path into something matching .libPaths() - gsub( - x = library_identical, - pattern = "\\", - replacement = "/", - fixed = TRUE - ) + .libPaths()[package_info[[package_identical]][["library_index"]]] #nolint: undesirable_function_linter ) testthat::expect_type( package_info[[package_identical]][["library_index"]], @@ -122,7 +119,6 @@ test_that("get_individual_package_info collects information for CRAN packages co package_info = get_individual_package_info("digest"), package_identical = "digest", version_identical = as.character(utils::packageVersion("digest")), - library_identical = .libPaths()[1], #nolint: undesirable_function_linter repository_match = "^(CRAN|RSPM)$", #GH Actions installs from RSPM, not CRAN remotetype_identical = "standard", remotepkgref_match = "^digest$", @@ -151,20 +147,23 @@ test_that("get_individual_package_info collects information for local packages c verbose = FALSE ) new_lib <- normalizePath(withr::local_tempdir()) - package_info <- with_local_install(new_lib, paste0("local::", dest_dir), { - get_individual_package_info("rmini") - }) + with_local_install(new_lib, paste0("local::", dest_dir), { + package_info <- get_individual_package_info("rmini") expect_package_info( package_info, package_identical = "rmini", version_identical = "0.0.4", - library_identical = new_lib, repository_match = NA_character_, remotetype_identical = "local", remotepkgref_match = paste0("^local::", dest_dir, "$"), remoteref_identical = NA_character_, remotesha_identical = NA_character_ ) + expect_identical( + package_info[["rmini"]][["library"]], + new_lib + ) + }) }) test_that("get_individual_package_info collects information for GitHub packages correctly", { #nolint: line_length_linter @@ -172,19 +171,22 @@ test_that("get_individual_package_info collects information for GitHub packages testthat::skip_if_offline() new_lib <- normalizePath(withr::local_tempdir()) package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter - get_individual_package_info("rmini") - }) + package_info <- get_individual_package_info("rmini") expect_package_info( package_info, package_identical = "rmini", version_identical = "0.0.4", - library_identical = new_lib, repository_match = NA_character_, remotetype_identical = "github", remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter remoteref_identical = "HEAD", remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) + expect_identical( + package_info[["rmini"]][["library"]], + new_lib + ) + }) }) test_that("get_individual_package_info errors for multiple packages", { @@ -212,32 +214,35 @@ test_that("get_individual_package_info errors for no arguments", { ) }) -test_that("get_individual_package_info gets correct libpath fdn version or multiple installs", { #nolint: line_length_linter +test_that("get_individual_package_info gets correct libpath and version of multiple installs", { #nolint: line_length_linter testthat::skip_on_cran() testthat::skip_if_offline() new_lib <- normalizePath(withr::local_tempdir()) newer_lib <- normalizePath(withr::local_tempdir()) expect_warning( - package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter + with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter with_local_install(newer_lib, "yihui/rmini@308d27d", { #nolint: nonportable_path_linter - get_individual_package_info("rmini") - }) - }) - ) + package_info <- get_individual_package_info("rmini") expect_package_info( package_info, package_identical = "rmini", version_identical = "0.0.3", # Note: not latest version - library_identical = newer_lib, repository_match = NA_character_, remotetype_identical = "github", remotepkgref_match = "^yihui/rmini@308d27d$", #nolint: nonportable_path_linter remoteref_identical = "308d27d", remotesha_identical = "308d27ddb0b45fda34fc259492145834d72849a9" ) + expect_identical( + package_info[["rmini"]][["library"]], + newer_lib + ) expect_identical( package_info[["rmini"]][["library_index"]], 1L + ) + }) + }) ) }) @@ -246,24 +251,27 @@ test_that("get_individual_package_info gets correct libpath for lower search pri testthat::skip_if_offline() new_lib <- normalizePath(withr::local_tempdir()) newer_lib <- normalizePath(withr::local_tempdir()) - package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter + with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter with_local_install(newer_lib, "digest", { - get_individual_package_info("rmini") - }) - }) + package_info <- get_individual_package_info("rmini") expect_package_info( package_info, package_identical = "rmini", version_identical = "0.0.4", - library_identical = new_lib, repository_match = NA_character_, remotetype_identical = "github", remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter remoteref_identical = "HEAD", remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) + expect_identical( + package_info[["rmini"]][["library"]], + new_lib + ) expect_identical( package_info[["rmini"]][["library_index"]], 2L ) + }) + }) }) From aee5cc1290e0260f19bace61f460a33339c3a07d Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:02:22 +0100 Subject: [PATCH 53/90] Reindent --- tests/testthat/test-get_package_info.R | 128 ++++++++++++------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index f8f748d9..6c125dfb 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -149,20 +149,20 @@ test_that("get_individual_package_info collects information for local packages c new_lib <- normalizePath(withr::local_tempdir()) with_local_install(new_lib, paste0("local::", dest_dir), { package_info <- get_individual_package_info("rmini") - expect_package_info( - package_info, - package_identical = "rmini", - version_identical = "0.0.4", - repository_match = NA_character_, - remotetype_identical = "local", - remotepkgref_match = paste0("^local::", dest_dir, "$"), - remoteref_identical = NA_character_, - remotesha_identical = NA_character_ - ) - expect_identical( - package_info[["rmini"]][["library"]], - new_lib - ) + expect_package_info( + package_info, + package_identical = "rmini", + version_identical = "0.0.4", + repository_match = NA_character_, + remotetype_identical = "local", + remotepkgref_match = paste0("^local::", dest_dir, "$"), + remoteref_identical = NA_character_, + remotesha_identical = NA_character_ + ) + expect_identical( + package_info[["rmini"]][["library"]], + new_lib + ) }) }) @@ -172,20 +172,20 @@ test_that("get_individual_package_info collects information for GitHub packages new_lib <- normalizePath(withr::local_tempdir()) package_info <- with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter package_info <- get_individual_package_info("rmini") - expect_package_info( - package_info, - package_identical = "rmini", - version_identical = "0.0.4", - repository_match = NA_character_, - remotetype_identical = "github", - remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter - remoteref_identical = "HEAD", - remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" - ) - expect_identical( - package_info[["rmini"]][["library"]], - new_lib - ) + expect_package_info( + package_info, + package_identical = "rmini", + version_identical = "0.0.4", + repository_match = NA_character_, + remotetype_identical = "github", + remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter + remoteref_identical = "HEAD", + remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + ) + expect_identical( + package_info[["rmini"]][["library"]], + new_lib + ) }) }) @@ -223,24 +223,24 @@ test_that("get_individual_package_info gets correct libpath and version of multi with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter with_local_install(newer_lib, "yihui/rmini@308d27d", { #nolint: nonportable_path_linter package_info <- get_individual_package_info("rmini") - expect_package_info( - package_info, - package_identical = "rmini", - version_identical = "0.0.3", # Note: not latest version - repository_match = NA_character_, - remotetype_identical = "github", - remotepkgref_match = "^yihui/rmini@308d27d$", #nolint: nonportable_path_linter - remoteref_identical = "308d27d", - remotesha_identical = "308d27ddb0b45fda34fc259492145834d72849a9" - ) - expect_identical( - package_info[["rmini"]][["library"]], - newer_lib - ) - expect_identical( - package_info[["rmini"]][["library_index"]], - 1L - ) + expect_package_info( + package_info, + package_identical = "rmini", + version_identical = "0.0.3", # Note: not latest version + repository_match = NA_character_, + remotetype_identical = "github", + remotepkgref_match = "^yihui/rmini@308d27d$", #nolint: nonportable_path_linter + remoteref_identical = "308d27d", + remotesha_identical = "308d27ddb0b45fda34fc259492145834d72849a9" + ) + expect_identical( + package_info[["rmini"]][["library"]], + newer_lib + ) + expect_identical( + package_info[["rmini"]][["library_index"]], + 1L + ) }) }) ) @@ -254,24 +254,24 @@ test_that("get_individual_package_info gets correct libpath for lower search pri with_local_install(new_lib, "yihui/rmini", { #nolint: nonportable_path_linter with_local_install(newer_lib, "digest", { package_info <- get_individual_package_info("rmini") - expect_package_info( - package_info, - package_identical = "rmini", - version_identical = "0.0.4", - repository_match = NA_character_, - remotetype_identical = "github", - remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter - remoteref_identical = "HEAD", - remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" - ) - expect_identical( - package_info[["rmini"]][["library"]], - new_lib - ) - expect_identical( - package_info[["rmini"]][["library_index"]], - 2L - ) + expect_package_info( + package_info, + package_identical = "rmini", + version_identical = "0.0.4", + repository_match = NA_character_, + remotetype_identical = "github", + remotepkgref_match = "^yihui/rmini$", #nolint: nonportable_path_linter + remoteref_identical = "HEAD", + remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" + ) + expect_identical( + package_info[["rmini"]][["library"]], + new_lib + ) + expect_identical( + package_info[["rmini"]][["library_index"]], + 2L + ) }) }) }) From 72da85f86defcea2538d4a7675d11d827f024f86 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:16:15 +0100 Subject: [PATCH 54/90] Fix paths on windows (again) --- tests/testthat/test-get_package_info.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 6c125dfb..949aa00a 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -161,7 +161,7 @@ test_that("get_individual_package_info collects information for local packages c ) expect_identical( package_info[["rmini"]][["library"]], - new_lib + normalizePath(new_lib, winslash = "/") ) }) }) @@ -184,7 +184,7 @@ test_that("get_individual_package_info collects information for GitHub packages ) expect_identical( package_info[["rmini"]][["library"]], - new_lib + normalizePath(new_lib, winslash = "/") ) }) }) @@ -235,7 +235,7 @@ test_that("get_individual_package_info gets correct libpath and version of multi ) expect_identical( package_info[["rmini"]][["library"]], - newer_lib + normalizePath(newer_lib, winslash = "/") ) expect_identical( package_info[["rmini"]][["library_index"]], @@ -266,7 +266,7 @@ test_that("get_individual_package_info gets correct libpath for lower search pri ) expect_identical( package_info[["rmini"]][["library"]], - new_lib + normalizePath(new_lib, winslash = "/") ) expect_identical( package_info[["rmini"]][["library_index"]], From 5b5cb77d8f43720ed6e02626e61e7cd5dde0d1e2 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:23:30 +0100 Subject: [PATCH 55/90] Change placeholder return value --- R/get_environment.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/get_environment.R b/R/get_environment.R index 9cf4adf5..951a4ecc 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -5,11 +5,8 @@ #' #' @return nested list of file details, length the same as the input vector. get_manifest_envirionment_info <- function() { - #: Envvars - - - return(invisible(FALSE)) + return(invisible(NULL)) } get_r_session_info <- function() { From 23a1c342826defb4210a474a59aea2d13cec1132 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:24:38 +0100 Subject: [PATCH 56/90] Add placeholder test --- tests/testthat/test-get_environment.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testthat/test-get_environment.R b/tests/testthat/test-get_environment.R index e4de41ab..35cc249b 100644 --- a/tests/testthat/test-get_environment.R +++ b/tests/testthat/test-get_environment.R @@ -26,3 +26,7 @@ test_that("get_single_file_metadata processes CSV tables correctly", { ) ) }) + +testthat::expect_null( + get_manifest_envirionment_info() +) From 447532b157d58fd02afca01ae571e009f6a6739b Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:26:34 +0100 Subject: [PATCH 57/90] move functions into own file --- R/get_environment.R | 94 -------------------------------------------- R/get_package_info.R | 94 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 94 deletions(-) create mode 100644 R/get_package_info.R diff --git a/R/get_environment.R b/R/get_environment.R index 951a4ecc..f6db6ed7 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -21,97 +21,3 @@ get_r_session_info <- function() { ) ) } - -get_package_info <- function( - base = utils::sessionInfo()[["basePkgs"]], - attached = names(utils::sessionInfo()[["otherPkgs"]]), - loaded = names(utils::sessionInfo()[["loadedOnly"]]) -) { - log_debug("Getting package info.") - log_trace("Base packages: {base}") - base_pkgs <- vapply( - X = base, - FUN = get_individual_package_info, - FUN.VALUE = list(10L), - USE.NAMES = TRUE - ) - log_trace("Attached packages: {attached}") - attached_pkgs <- vapply( - X = attached, - FUN = get_individual_package_info, - FUN.VALUE = list(1L), - USE.NAMES = TRUE - ) - log_trace("Loaded packages: {loaded}") - loaded_pkgs <- vapply( - X = loaded, - FUN = get_individual_package_info, - FUN.VALUE = list(10L), - USE.NAMES = TRUE - ) - log_debug("Done fetching package info.") - return( - list( - base = base_pkgs, - attached = attached_pkgs, - loaded = loaded_pkgs - ) - ) -} - -get_individual_package_info <- function(packagename) { - if (length(packagename) != 1L || !is.character(packagename)) { - log_error("packagename must be a single string.") - stop("packagename must be a single string.") - } else { - if (packagename %in% utils::installed.packages()[, "Package"]) { - installed_index <- which( - utils::installed.packages()[, "Package"] == packagename - ) - installed_path <- utils::installed.packages()[installed_index, "LibPath"] - if (length(installed_path) > 1L) { - log_warn( - "Multiple installations of package \"{packagename}\" found: ", - "{installed_path}" - ) - log_warn("Using installation first on the search path.") - warning("Multiple installations of package found.") - } - lib_index <- min(which(.libPaths() == installed_path)) #nolint: undesirable_function_linter - lib <- .libPaths()[lib_index] #nolint: undesirable_function_linter - log_trace("Package \"{packagename}\" is installed at {lib}") - } else { - log_error("Package \"{packagename}\" is not installed.") - stop("Package is not installed.") - } - } - log_trace("Getting package info for {packagename}.") - pkg_details <- as.list( - pkgdepends::lib_status( - library = lib, - packages = packagename - ) - ) - details_list <- list( - package = pkg_details[["package"]], - version = pkg_details[["version"]], - library = pkg_details[["library"]], - library_index = lib_index, - repository = pkg_details[["repository"]], - platform = pkg_details[["platform"]], - built = pkg_details[["built"]], - remotetype = pkg_details[["remotetype"]], - remotepkgref = pkg_details[["remotepkgref"]], - remoteref = pkg_details[["remoteref"]], - remotesha = pkg_details[["remotesha"]] - ) - clean_details_list <- lapply( - X = details_list, - FUN = function(x) { - ifelse(is.null(x), NA_character_, x) - } - ) - output <- list() - output[[packagename]] <- clean_details_list - return(output) -} diff --git a/R/get_package_info.R b/R/get_package_info.R new file mode 100644 index 00000000..0fe8e8a7 --- /dev/null +++ b/R/get_package_info.R @@ -0,0 +1,94 @@ +get_package_info <- function( + base = utils::sessionInfo()[["basePkgs"]], + attached = names(utils::sessionInfo()[["otherPkgs"]]), + loaded = names(utils::sessionInfo()[["loadedOnly"]]) +) { + log_debug("Getting package info.") + log_trace("Base packages: {base}") + base_pkgs <- vapply( + X = base, + FUN = get_individual_package_info, + FUN.VALUE = list(10L), + USE.NAMES = TRUE + ) + log_trace("Attached packages: {attached}") + attached_pkgs <- vapply( + X = attached, + FUN = get_individual_package_info, + FUN.VALUE = list(1L), + USE.NAMES = TRUE + ) + log_trace("Loaded packages: {loaded}") + loaded_pkgs <- vapply( + X = loaded, + FUN = get_individual_package_info, + FUN.VALUE = list(10L), + USE.NAMES = TRUE + ) + log_debug("Done fetching package info.") + return( + list( + base = base_pkgs, + attached = attached_pkgs, + loaded = loaded_pkgs + ) + ) +} + +get_individual_package_info <- function(packagename) { + if (length(packagename) != 1L || !is.character(packagename)) { + log_error("packagename must be a single string.") + stop("packagename must be a single string.") + } else { + if (packagename %in% utils::installed.packages()[, "Package"]) { + installed_index <- which( + utils::installed.packages()[, "Package"] == packagename + ) + installed_path <- utils::installed.packages()[installed_index, "LibPath"] + if (length(installed_path) > 1L) { + log_warn( + "Multiple installations of package \"{packagename}\" found: ", + "{installed_path}" + ) + log_warn("Using installation first on the search path.") + warning("Multiple installations of package found.") + } + lib_index <- min(which(.libPaths() == installed_path)) #nolint: undesirable_function_linter + lib <- .libPaths()[lib_index] #nolint: undesirable_function_linter + log_trace("Package \"{packagename}\" is installed at {lib}") + } else { + log_error("Package \"{packagename}\" is not installed.") + stop("Package is not installed.") + } + } + log_trace("Getting package info for {packagename}.") + pkg_details <- as.list( + pkgdepends::lib_status( + library = lib, + packages = packagename + ) + ) + details_list <- list( + package = pkg_details[["package"]], + version = pkg_details[["version"]], + library = pkg_details[["library"]], + library_index = lib_index, + repository = pkg_details[["repository"]], + platform = pkg_details[["platform"]], + built = pkg_details[["built"]], + remotetype = pkg_details[["remotetype"]], + remotepkgref = pkg_details[["remotepkgref"]], + remoteref = pkg_details[["remoteref"]], + remotesha = pkg_details[["remotesha"]] + ) + clean_details_list <- lapply( + X = details_list, + FUN = function(x) { + ifelse(is.null(x), NA_character_, x) + } + ) + output <- list() + output[[packagename]] <- clean_details_list + return(output) +} + From fe0f9d2b46541f9012d0eb3163c6ca7d5d7dcfcc Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:42:10 +0100 Subject: [PATCH 58/90] Document session info --- R/get_environment.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/get_environment.R b/R/get_environment.R index f6db6ed7..60af2216 100644 --- a/R/get_environment.R +++ b/R/get_environment.R @@ -9,6 +9,13 @@ get_manifest_envirionment_info <- function() { return(invisible(NULL)) } +#' Get session information for manifest +#' +#' This function takes no arguments and returns a list, suitable for +#' inclusion in manifest export. +#' +#' @return list of session details, including R Version, platform, OS +#' (`running`), locale, timezone, and library paths. get_r_session_info <- function() { return( list( From 39d971606693c052c247ada9e0d6a4fadbcdf82e Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:58:51 +0100 Subject: [PATCH 59/90] update docstrings --- R/get_package_info.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/R/get_package_info.R b/R/get_package_info.R index 0fe8e8a7..5072f26c 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -1,3 +1,15 @@ +#' Get package information for active packages +#' +#' This function takes 3 vectors of package names and returns a nested list of +#' package details, suitable for inclusion in manifest export. +#' +#' @param base vector of package names. Best left as default, which includes the loaded base packages. +#' @param attached vector of package names. Best left as default, which includes the attached packages. +#' @param loaded vector of package names. Best left as default, which includes the loaded packages. +#' +#' @return nested list of file details, length 3, with top level keys being `base`, `attached`, and `loaded`. +#' Underneath those keys are lists of package details, with the package names as keys, and further details as returned by [get_individual_package_info()]. +#' @seealso [get_individual_package_info()] get_package_info <- function( base = utils::sessionInfo()[["basePkgs"]], attached = names(utils::sessionInfo()[["otherPkgs"]]), @@ -35,6 +47,28 @@ get_package_info <- function( ) } +#' Get package information for a package +#' +#' This function takes a single package name and returns a list of package +#' details, suitable for inclusion in manifest export. +#' +#' @param Singular charater string of package name +#' +#' @return nested list of file details, length 1, with the top-level key being +#' the `packagename` passed as an argument. underneath that key are: +#' - `package`: The name of the package +#' - `version`: The version of the package +#' - `library`: The path of the library the package is installed in +#' - `library_index`: The index of the library in the `.libPaths()` vector +#' - `repository`: The repository the package was pulled from +#' - `platform`: The platform the package was built for +#' - `built`: Information about the packages build (relevant for binary packages) +#' - `remotetype`: The type of remote repository the package was pulled from +#' - `remotepkgref`: The reference used by `pak` to install the package +#' - `remoteref`: The reference of the package when it was pulled from REPO +#' - `remotesha`: the SHA-1 hash of the reference (if applicable) +#' @examples +#' get_individual_package_info("digest") get_individual_package_info <- function(packagename) { if (length(packagename) != 1L || !is.character(packagename)) { log_error("packagename must be a single string.") From cd67cc12e453ff9049ab0d393d5186b4dba31471 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 15:59:18 +0100 Subject: [PATCH 60/90] Update rendered docs --- man/get_individual_package_info.Rd | 35 ++++++++++++++++++++++++++++++ man/get_package_info.Rd | 30 +++++++++++++++++++++++++ man/get_r_session_info.Rd | 16 ++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 man/get_individual_package_info.Rd create mode 100644 man/get_package_info.Rd create mode 100644 man/get_r_session_info.Rd diff --git a/man/get_individual_package_info.Rd b/man/get_individual_package_info.Rd new file mode 100644 index 00000000..ebc3c5d5 --- /dev/null +++ b/man/get_individual_package_info.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_package_info.R +\name{get_individual_package_info} +\alias{get_individual_package_info} +\title{Get package information for a package} +\usage{ +get_individual_package_info(packagename) +} +\arguments{ +\item{Singular}{charater string of package name} +} +\value{ +nested list of file details, length 1, with the top-level key being +the \code{packagename} passed as an argument. underneath that key are: +\itemize{ +\item \code{package}: The name of the package +\item \code{version}: The version of the package +\item \code{library}: The path of the library the package is installed in +\item \code{library_index}: The index of the library in the \code{.libPaths()} vector +\item \code{repository}: The repository the package was pulled from +\item \code{platform}: The platform the package was built for +\item \code{built}: Information about the packages build (relevant for binary packages) +\item \code{remotetype}: The type of remote repository the package was pulled from +\item \code{remotepkgref}: The reference used by \code{pak} to install the package +\item \code{remoteref}: The reference of the package when it was pulled from REPO +\item \code{remotesha}: the SHA-1 hash of the reference (if applicable) +} +} +\description{ +This function takes a single package name and returns a list of package +details, suitable for inclusion in manifest export. +} +\examples{ +get_individual_package_info("digest") +} diff --git a/man/get_package_info.Rd b/man/get_package_info.Rd new file mode 100644 index 00000000..326c47c8 --- /dev/null +++ b/man/get_package_info.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_package_info.R +\name{get_package_info} +\alias{get_package_info} +\title{Get package information for active packages} +\usage{ +get_package_info( + base = utils::sessionInfo()[["basePkgs"]], + attached = names(utils::sessionInfo()[["otherPkgs"]]), + loaded = names(utils::sessionInfo()[["loadedOnly"]]) +) +} +\arguments{ +\item{base}{vector of package names. Best left as default, which includes the loaded base packages.} + +\item{attached}{vector of package names. Best left as default, which includes the attached packages.} + +\item{loaded}{vector of package names. Best left as default, which includes the loaded packages.} +} +\value{ +nested list of file details, length 3, with top level keys being \code{base}, \code{attached}, and \code{loaded}. +Underneath those keys are lists of package details, with the package names as keys, and further details as returned by \code{\link[=get_individual_package_info]{get_individual_package_info()}}. +} +\description{ +This function takes 3 vectors of package names and returns a nested list of +package details, suitable for inclusion in manifest export. +} +\seealso{ +\code{\link[=get_individual_package_info]{get_individual_package_info()}} +} diff --git a/man/get_r_session_info.Rd b/man/get_r_session_info.Rd new file mode 100644 index 00000000..2e3d7ad3 --- /dev/null +++ b/man/get_r_session_info.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_environment.R +\name{get_r_session_info} +\alias{get_r_session_info} +\title{Get session information for manifest} +\usage{ +get_r_session_info() +} +\value{ +list of session details, including R Version, platform, OS +(\code{running}), locale, timezone, and library paths. +} +\description{ +This function takes no arguments and returns a list, suitable for +inclusion in manifest export. +} From 01f82b903909b73f08ebe4b9f16d20f26c2fac2c Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 16:00:17 +0100 Subject: [PATCH 61/90] Rename test file --- ...test-get_package_info.R => test-get_individual_package_info.R} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/testthat/{test-get_package_info.R => test-get_individual_package_info.R} (100%) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_individual_package_info.R similarity index 100% rename from tests/testthat/test-get_package_info.R rename to tests/testthat/test-get_individual_package_info.R From 567a88d96f411c9e744dcd2ca810517ebf41c6c8 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 16:30:40 +0100 Subject: [PATCH 62/90] Name testthat args --- .../test-get_individual_package_info.R | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/testthat/test-get_individual_package_info.R b/tests/testthat/test-get_individual_package_info.R index 949aa00a..5c2614fc 100644 --- a/tests/testthat/test-get_individual_package_info.R +++ b/tests/testthat/test-get_individual_package_info.R @@ -26,11 +26,11 @@ expect_package_info <- function( testthat::expect_type(package_info, "list") testthat::expect_named( package_info, - package_identical + expected = package_identical ) testthat::expect_named( package_info[[package_identical]], - c( + expected = c( "package", "version", "library", @@ -45,59 +45,59 @@ expect_package_info <- function( ) ) testthat::expect_identical( - package_info[[package_identical]][["package"]], - package_identical + object = package_info[[package_identical]][["package"]], + expected = package_identical ) testthat::expect_identical( - package_info[[package_identical]][["version"]], - version_identical + object = package_info[[package_identical]][["version"]], + expected = version_identical ) testthat::expect_in( - package_info[[package_identical]][["library"]], + object = package_info[[package_identical]][["library"]], .libPaths() #nolint: undesirable_function_linter ) testthat::expect_identical( - package_info[[package_identical]][["library"]], - .libPaths()[package_info[[package_identical]][["library_index"]]] #nolint: undesirable_function_linter + object = package_info[[package_identical]][["library"]], + expected = .libPaths()[package_info[[package_identical]][["library_index"]]] #nolint: undesirable_function_linter ) testthat::expect_type( - package_info[[package_identical]][["library_index"]], - "integer" + object = package_info[[package_identical]][["library_index"]], + type = "integer" ) testthat::expect_gt( - package_info[[package_identical]][["library_index"]], - 0L + object = package_info[[package_identical]][["library_index"]], + expected = 0L ) testthat::expect_lte( - package_info[[package_identical]][["library_index"]], - length(.libPaths()) #nolint: undesirable_function_linter + object = package_info[[package_identical]][["library_index"]], + expected = length(.libPaths()) #nolint: undesirable_function_linter ) if (is.na(repository_match)) { testthat::expect_identical( package_info[[package_identical]][["repository"]], - repository_match + expected = repository_match ) } else { testthat::expect_match( - package_info[[package_identical]][["repository"]], - repository_match + object = package_info[[package_identical]][["repository"]], + regexp = repository_match ) } testthat::expect_match( - package_info[[package_identical]][["platform"]], - R.version[["platform"]] + object = package_info[[package_identical]][["platform"]], + regexp = R.version[["platform"]] ) testthat::expect_false( - is.null(package_info[[package_identical]][["built"]]) + is.null(x = package_info[[package_identical]][["built"]]) ) testthat::expect_identical( - package_info[[package_identical]][["remotetype"]], - remotetype_identical + object = package_info[[package_identical]][["remotetype"]], + expected = remotetype_identical ) testthat::expect_match( - package_info[[package_identical]][["remotepkgref"]], + object = package_info[[package_identical]][["remotepkgref"]], # gsub is used to make windows path work - gsub( + regexp = gsub( x = remotepkgref_match, pattern = "\\", replacement = "\\\\", @@ -105,11 +105,11 @@ expect_package_info <- function( ) ) testthat::expect_identical( - package_info[[package_identical]][["remoteref"]], + object = package_info[[package_identical]][["remoteref"]], remoteref_identical ) testthat::expect_identical( - package_info[[package_identical]][["remotesha"]], + object = package_info[[package_identical]][["remotesha"]], remotesha_identical ) } From 2bd9954e736a654f7fd69a8d9f17b449463ae51c Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 16:32:41 +0100 Subject: [PATCH 63/90] Allow NA fgor pkg ref (base pkgs) --- .../test-get_individual_package_info.R | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test-get_individual_package_info.R b/tests/testthat/test-get_individual_package_info.R index 5c2614fc..ec4eda54 100644 --- a/tests/testthat/test-get_individual_package_info.R +++ b/tests/testthat/test-get_individual_package_info.R @@ -94,16 +94,23 @@ expect_package_info <- function( object = package_info[[package_identical]][["remotetype"]], expected = remotetype_identical ) - testthat::expect_match( - object = package_info[[package_identical]][["remotepkgref"]], - # gsub is used to make windows path work - regexp = gsub( - x = remotepkgref_match, - pattern = "\\", - replacement = "\\\\", - fixed = TRUE + if (is.na(remotepkgref_match)) { + testthat::expect_identical( + package_info[[package_identical]][["remotepkgref"]], + expected = remotepkgref_match ) - ) + } else { + testthat::expect_match( + object = package_info[[package_identical]][["remotepkgref"]], + # gsub is used to make windows path work + regexp = gsub( + x = remotepkgref_match, + pattern = "\\", + replacement = "\\\\", + fixed = TRUE + ) + ) + } testthat::expect_identical( object = package_info[[package_identical]][["remoteref"]], remoteref_identical @@ -127,6 +134,23 @@ test_that("get_individual_package_info collects information for CRAN packages co ) }) +test_that("get_individual_package_info collects information for base packages correctly", { #nolint: line_length_linter + expect_package_info( + package_info = get_individual_package_info("utils"), + package_identical = "utils", + version_identical = paste( + R.version[["major"]], + R.version[["minor"]], + sep = "." + ), + repository_match = NA_character_, #GH Actions installs from RSPM, not CRAN + remotetype_identical = NA_character_, + remotepkgref_match = NA_character_, + remoteref_identical = NA_character_, + remotesha_identical = NA_character_ + ) +}) + with_local_install <- function(new_lib, package, code) { cache_dir <- withr::local_tempdir() withr::local_envvar(.new = c(R_USER_CACHE_DIR = cache_dir)) From ca3a8eb71fa066c2f4fb4dab41d204fc8cecb6c2 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 16:35:09 +0100 Subject: [PATCH 64/90] Reflow docstrings --- R/get_package_info.R | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index 5072f26c..89ffacca 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -3,12 +3,15 @@ #' This function takes 3 vectors of package names and returns a nested list of #' package details, suitable for inclusion in manifest export. #' -#' @param base vector of package names. Best left as default, which includes the loaded base packages. -#' @param attached vector of package names. Best left as default, which includes the attached packages. -#' @param loaded vector of package names. Best left as default, which includes the loaded packages. +#' @param base vector of package names. Best left as default, which includes +#' the loaded base packages. @param attached vector of package names. Best left +#' as default, which includes the attached packages. @param loaded vector of +#' package names. Best left as default, which includes the loaded packages. #' -#' @return nested list of file details, length 3, with top level keys being `base`, `attached`, and `loaded`. -#' Underneath those keys are lists of package details, with the package names as keys, and further details as returned by [get_individual_package_info()]. +#' @return nested list of file details, length 3, with top level keys being +#' `base`, `attached`, and `loaded`. Underneath those keys are lists of package +#' details, with the package names as keys, and further details as returned by +#' [get_individual_package_info()]. #' @seealso [get_individual_package_info()] get_package_info <- function( base = utils::sessionInfo()[["basePkgs"]], @@ -62,7 +65,7 @@ get_package_info <- function( #' - `library_index`: The index of the library in the `.libPaths()` vector #' - `repository`: The repository the package was pulled from #' - `platform`: The platform the package was built for -#' - `built`: Information about the packages build (relevant for binary packages) +#' - `built`: Information about package build (relevant for binary packages) #' - `remotetype`: The type of remote repository the package was pulled from #' - `remotepkgref`: The reference used by `pak` to install the package #' - `remoteref`: The reference of the package when it was pulled from REPO @@ -125,4 +128,3 @@ get_individual_package_info <- function(packagename) { output[[packagename]] <- clean_details_list return(output) } - From 73f17733c801597a88d780d382e68de596575a5f Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 17:40:17 +0100 Subject: [PATCH 65/90] improve tests --- tests/testthat/test-get_package_info.R | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/testthat/test-get_package_info.R diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R new file mode 100644 index 00000000..eba359fb --- /dev/null +++ b/tests/testthat/test-get_package_info.R @@ -0,0 +1,80 @@ +## save current settings so that we can reset later +threshold <- logger::log_threshold() +appender <- logger::log_appender() +layout <- logger::log_layout() +on.exit({ + ## reset logger settings + logger::log_threshold(threshold) + logger::log_layout(layout) + logger::log_appender(appender) +}) + +logger::log_appender(logger::appender_stdout) +logger::log_threshold(logger::FATAL) +logger::log_layout(logger::layout_simple) + +test_that("get_package_info outputs correct structure", { + package_info <- get_package_info() + expect_named( + object = package_info, + expected = c("base", "attached", "loaded") + ) + expect_named( + object = package_info[["base"]], + expected = utils::sessionInfo()[["basePkgs"]] + ) + expect_named( + object = package_info[["attached"]], + expected = names(utils::sessionInfo()[["otherPkgs"]]) + ) + expect_named( + object = package_info[["loaded"]], + expected = names(utils::sessionInfo()[["loadedOnly"]]) + ) + # Check that the structure of the package_info is correct + expect_true( + object = all( + vapply( + X = package_info, + FUN = function(x) { + all( + vapply( + X = x, + FUN = function(x) { + all( + names(x) == c( + "package", + "version", + "library", + "library_index", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" + ) + ) + }, + FUN.VALUE = logical(1L) + ) + ) + }, + FUN.VALUE = logical(1L) + ) + ) + + ) +}) + +# test_that("get_package_info with empty args returns empty lists", { +# expect_identical( +# object = get_package_info(), +# expected = list( +# base = list(), +# attached = list(), +# loaded = list() +# ) +# ) +# }) From d9f24309b9f2027eb556079a5affc394bcc61dd5 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 19:35:47 +0100 Subject: [PATCH 66/90] Add test for empty arguments --- tests/testthat/test-get_package_info.R | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index eba359fb..da8c0cf5 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -68,13 +68,19 @@ test_that("get_package_info outputs correct structure", { ) }) -# test_that("get_package_info with empty args returns empty lists", { -# expect_identical( -# object = get_package_info(), -# expected = list( -# base = list(), -# attached = list(), -# loaded = list() -# ) -# ) -# }) +test_that("get_package_info with empty args returns empty lists", { + empty_named_list <- list() + names(empty_named_list) <- character(0L) + expect_identical( + object = get_package_info( + base = character(), + attached = character(), + loaded = character() + ), + expected = list( + base = empty_named_list, + attached = empty_named_list, + loaded = empty_named_list + ) + ) +}) From 41bbce08a89faa6ccc4ef2b2651b5ec5922a5019 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 19:52:46 +0100 Subject: [PATCH 67/90] Add tests for `get_package_info()` --- tests/testthat/test-get_package_info.R | 61 ++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index da8c0cf5..859bf6ac 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -68,9 +68,10 @@ test_that("get_package_info outputs correct structure", { ) }) -test_that("get_package_info with empty args returns empty lists", { - empty_named_list <- list() - names(empty_named_list) <- character(0L) +empty_named_list <- list() +names(empty_named_list) <- character(0L) + +test_that("get_package_info with empty character args returns empty named lists", { #nolint: line_length_linter expect_identical( object = get_package_info( base = character(), @@ -84,3 +85,57 @@ test_that("get_package_info with empty args returns empty lists", { ) ) }) + +test_that("get_package_info with empty args returns empty lists", { + expect_identical( + object = get_package_info( + base = c(), + attached = c(), + loaded = c() + ), + expected = list( + base = list(), + attached = list(), + loaded = list() + ) + ) +}) + +test_that("get_package_info accepts length 1 arguments", { + digest_info <- get_individual_package_info("digest") + expect_identical( + object = get_package_info( + base = "digest", + attached = "digest", + loaded = "digest" + ), + expected = list( + base = digest_info, + attached = digest_info, + loaded = digest_info + ) + ) +}) + +test_that("get_package_info respects order", { + digest_info <- get_individual_package_info("digest") + utils_info <- get_individual_package_info("utils") + expect_identical( + object = get_package_info( + base = c("digest", "utils"), + attached = c("utils", "digest"), + loaded = character() + ), + expected = list( + base = c( # using c(), to concatenate already named lists) + digest_info, + utils_info + ), + attached = c( + utils_info, + digest_info + ), + loaded = empty_named_list + ) + ) +}) From 181edbdabd961d7b80b7a337cd7d87814b6b88f4 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 20:08:27 +0100 Subject: [PATCH 68/90] Update docstrings --- R/get_package_info.R | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index 89ffacca..ee090960 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -23,7 +23,7 @@ get_package_info <- function( base_pkgs <- vapply( X = base, FUN = get_individual_package_info, - FUN.VALUE = list(10L), + FUN.VALUE = list(1L), USE.NAMES = TRUE ) log_trace("Attached packages: {attached}") @@ -37,7 +37,7 @@ get_package_info <- function( loaded_pkgs <- vapply( X = loaded, FUN = get_individual_package_info, - FUN.VALUE = list(10L), + FUN.VALUE = list(1L), USE.NAMES = TRUE ) log_debug("Done fetching package info.") @@ -55,7 +55,7 @@ get_package_info <- function( #' This function takes a single package name and returns a list of package #' details, suitable for inclusion in manifest export. #' -#' @param Singular charater string of package name +#' @param packagename Singular charater string of package name #' #' @return nested list of file details, length 1, with the top-level key being #' the `packagename` passed as an argument. underneath that key are: @@ -70,8 +70,6 @@ get_package_info <- function( #' - `remotepkgref`: The reference used by `pak` to install the package #' - `remoteref`: The reference of the package when it was pulled from REPO #' - `remotesha`: the SHA-1 hash of the reference (if applicable) -#' @examples -#' get_individual_package_info("digest") get_individual_package_info <- function(packagename) { if (length(packagename) != 1L || !is.character(packagename)) { log_error("packagename must be a single string.") From 52470c2edfbf661d3962990ee5bcfe658103bd26 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 20:12:17 +0100 Subject: [PATCH 69/90] update rendered docs --- man/get_individual_package_info.Rd | 7 ++----- man/get_package_info.Rd | 15 ++++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/man/get_individual_package_info.Rd b/man/get_individual_package_info.Rd index ebc3c5d5..2a3b906b 100644 --- a/man/get_individual_package_info.Rd +++ b/man/get_individual_package_info.Rd @@ -7,7 +7,7 @@ get_individual_package_info(packagename) } \arguments{ -\item{Singular}{charater string of package name} +\item{packagename}{Singular charater string of package name} } \value{ nested list of file details, length 1, with the top-level key being @@ -19,7 +19,7 @@ the \code{packagename} passed as an argument. underneath that key are: \item \code{library_index}: The index of the library in the \code{.libPaths()} vector \item \code{repository}: The repository the package was pulled from \item \code{platform}: The platform the package was built for -\item \code{built}: Information about the packages build (relevant for binary packages) +\item \code{built}: Information about package build (relevant for binary packages) \item \code{remotetype}: The type of remote repository the package was pulled from \item \code{remotepkgref}: The reference used by \code{pak} to install the package \item \code{remoteref}: The reference of the package when it was pulled from REPO @@ -30,6 +30,3 @@ the \code{packagename} passed as an argument. underneath that key are: This function takes a single package name and returns a list of package details, suitable for inclusion in manifest export. } -\examples{ -get_individual_package_info("digest") -} diff --git a/man/get_package_info.Rd b/man/get_package_info.Rd index 326c47c8..f5d7ce3f 100644 --- a/man/get_package_info.Rd +++ b/man/get_package_info.Rd @@ -11,15 +11,16 @@ get_package_info( ) } \arguments{ -\item{base}{vector of package names. Best left as default, which includes the loaded base packages.} - -\item{attached}{vector of package names. Best left as default, which includes the attached packages.} - -\item{loaded}{vector of package names. Best left as default, which includes the loaded packages.} +\item{base}{vector of package names. Best left as default, which includes +the loaded base packages. @param attached vector of package names. Best left +as default, which includes the attached packages. @param loaded vector of +package names. Best left as default, which includes the loaded packages.} } \value{ -nested list of file details, length 3, with top level keys being \code{base}, \code{attached}, and \code{loaded}. -Underneath those keys are lists of package details, with the package names as keys, and further details as returned by \code{\link[=get_individual_package_info]{get_individual_package_info()}}. +nested list of file details, length 3, with top level keys being +\code{base}, \code{attached}, and \code{loaded}. Underneath those keys are lists of package +details, with the package names as keys, and further details as returned by +\code{\link[=get_individual_package_info]{get_individual_package_info()}}. } \description{ This function takes 3 vectors of package names and returns a nested list of From d0228c255c7ae50fecfcec66ca4411ec0911c3ca Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 21:42:48 +0100 Subject: [PATCH 70/90] Reflow docstrings --- R/get_package_info.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index ee090960..3c387d8b 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -4,9 +4,11 @@ #' package details, suitable for inclusion in manifest export. #' #' @param base vector of package names. Best left as default, which includes -#' the loaded base packages. @param attached vector of package names. Best left -#' as default, which includes the attached packages. @param loaded vector of -#' package names. Best left as default, which includes the loaded packages. +#' the loaded base packages. +#' @param attached vector of package names. Best left as default, which +#' includes the attached packages. +#' @param loaded vector of package names. Best left as default, which includes +#' the loaded packages. #' #' @return nested list of file details, length 3, with top level keys being #' `base`, `attached`, and `loaded`. Underneath those keys are lists of package From 092c95794d6f2ec8eafb9d52b518868ccd2221bb Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 21 Mar 2024 22:10:10 +0100 Subject: [PATCH 71/90] Update rendered docs --- man/get_package_info.Rd | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/man/get_package_info.Rd b/man/get_package_info.Rd index f5d7ce3f..39d5aeed 100644 --- a/man/get_package_info.Rd +++ b/man/get_package_info.Rd @@ -12,9 +12,13 @@ get_package_info( } \arguments{ \item{base}{vector of package names. Best left as default, which includes -the loaded base packages. @param attached vector of package names. Best left -as default, which includes the attached packages. @param loaded vector of -package names. Best left as default, which includes the loaded packages.} +the loaded base packages.} + +\item{attached}{vector of package names. Best left as default, which +includes the attached packages.} + +\item{loaded}{vector of package names. Best left as default, which includes +the loaded packages.} } \value{ nested list of file details, length 3, with top level keys being From 26afb9c2474c15ddbbaefb30e8bbec7bf55da2cd Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Fri, 22 Mar 2024 10:26:18 +0100 Subject: [PATCH 72/90] Add tests for NULL arguments --- tests/testthat/test-get_package_info.R | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 859bf6ac..32009551 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -89,9 +89,24 @@ test_that("get_package_info with empty character args returns empty named lists" test_that("get_package_info with empty args returns empty lists", { expect_identical( object = get_package_info( - base = c(), - attached = c(), - loaded = c() + base = c(), # nolint: unnecessary_concatenation_linter + attached = c(), # nolint: unnecessary_concatenation_linter + loaded = c() # nolint: unnecessary_concatenation_linter + ), + expected = list( + base = list(), + attached = list(), + loaded = list() + ) + ) +}) + +test_that("get_package_info with NULL args returns empty lists", { + expect_identical( + object = get_package_info( + base = NULL, + attached = NULL, + loaded = NULL ), expected = list( base = list(), From 9a7847e51eb3508f5243b06701fbcdfc2f4e57a9 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Fri, 22 Mar 2024 11:32:18 +0100 Subject: [PATCH 73/90] change structure of outputs --- R/get_package_info.R | 4 +- .../test-get_individual_package_info.R | 50 +++++++++---------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index 3c387d8b..9681017e 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -124,7 +124,5 @@ get_individual_package_info <- function(packagename) { ifelse(is.null(x), NA_character_, x) } ) - output <- list() - output[[packagename]] <- clean_details_list - return(output) + return(clean_details_list) } diff --git a/tests/testthat/test-get_individual_package_info.R b/tests/testthat/test-get_individual_package_info.R index ec4eda54..9a3ddc2e 100644 --- a/tests/testthat/test-get_individual_package_info.R +++ b/tests/testthat/test-get_individual_package_info.R @@ -26,10 +26,6 @@ expect_package_info <- function( testthat::expect_type(package_info, "list") testthat::expect_named( package_info, - expected = package_identical - ) - testthat::expect_named( - package_info[[package_identical]], expected = c( "package", "version", @@ -45,63 +41,63 @@ expect_package_info <- function( ) ) testthat::expect_identical( - object = package_info[[package_identical]][["package"]], + object = package_info[["package"]], expected = package_identical ) testthat::expect_identical( - object = package_info[[package_identical]][["version"]], + object = package_info[["version"]], expected = version_identical ) testthat::expect_in( - object = package_info[[package_identical]][["library"]], + object = package_info[["library"]], .libPaths() #nolint: undesirable_function_linter ) testthat::expect_identical( - object = package_info[[package_identical]][["library"]], - expected = .libPaths()[package_info[[package_identical]][["library_index"]]] #nolint: undesirable_function_linter + object = package_info[["library"]], + expected = .libPaths()[package_info[["library_index"]]] #nolint: undesirable_function_linter ) testthat::expect_type( - object = package_info[[package_identical]][["library_index"]], + object = package_info[["library_index"]], type = "integer" ) testthat::expect_gt( - object = package_info[[package_identical]][["library_index"]], + object = package_info[["library_index"]], expected = 0L ) testthat::expect_lte( - object = package_info[[package_identical]][["library_index"]], + object = package_info[["library_index"]], expected = length(.libPaths()) #nolint: undesirable_function_linter ) if (is.na(repository_match)) { testthat::expect_identical( - package_info[[package_identical]][["repository"]], + package_info[["repository"]], expected = repository_match ) } else { testthat::expect_match( - object = package_info[[package_identical]][["repository"]], + object = package_info[["repository"]], regexp = repository_match ) } testthat::expect_match( - object = package_info[[package_identical]][["platform"]], + object = package_info[["platform"]], regexp = R.version[["platform"]] ) testthat::expect_false( - is.null(x = package_info[[package_identical]][["built"]]) + is.null(x = package_info[["built"]]) ) testthat::expect_identical( - object = package_info[[package_identical]][["remotetype"]], + object = package_info[["remotetype"]], expected = remotetype_identical ) if (is.na(remotepkgref_match)) { testthat::expect_identical( - package_info[[package_identical]][["remotepkgref"]], + package_info[["remotepkgref"]], expected = remotepkgref_match ) } else { testthat::expect_match( - object = package_info[[package_identical]][["remotepkgref"]], + object = package_info[["remotepkgref"]], # gsub is used to make windows path work regexp = gsub( x = remotepkgref_match, @@ -112,11 +108,11 @@ expect_package_info <- function( ) } testthat::expect_identical( - object = package_info[[package_identical]][["remoteref"]], + object = package_info[["remoteref"]], remoteref_identical ) testthat::expect_identical( - object = package_info[[package_identical]][["remotesha"]], + object = package_info[["remotesha"]], remotesha_identical ) } @@ -184,7 +180,7 @@ test_that("get_individual_package_info collects information for local packages c remotesha_identical = NA_character_ ) expect_identical( - package_info[["rmini"]][["library"]], + package_info[["library"]], normalizePath(new_lib, winslash = "/") ) }) @@ -207,7 +203,7 @@ test_that("get_individual_package_info collects information for GitHub packages remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) expect_identical( - package_info[["rmini"]][["library"]], + package_info[["library"]], normalizePath(new_lib, winslash = "/") ) }) @@ -258,11 +254,11 @@ test_that("get_individual_package_info gets correct libpath and version of multi remotesha_identical = "308d27ddb0b45fda34fc259492145834d72849a9" ) expect_identical( - package_info[["rmini"]][["library"]], + package_info[["library"]], normalizePath(newer_lib, winslash = "/") ) expect_identical( - package_info[["rmini"]][["library_index"]], + package_info[["library_index"]], 1L ) }) @@ -289,11 +285,11 @@ test_that("get_individual_package_info gets correct libpath for lower search pri remotesha_identical = "f839b7327c4cb422705b9f3b7c5ffc87555d98e2" ) expect_identical( - package_info[["rmini"]][["library"]], + package_info[["library"]], normalizePath(new_lib, winslash = "/") ) expect_identical( - package_info[["rmini"]][["library_index"]], + package_info[["library_index"]], 2L ) }) From c1d1f72e04ab1cbc981c228fcd3d9a263dba2c95 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 10:41:39 +0100 Subject: [PATCH 74/90] Update signature for get_package_info Now accepts a single list/vector and returns a nested list --- R/get_package_info.R | 74 +++++------ tests/testthat/test-get_package_info.R | 164 +++++++++++++++---------- 2 files changed, 134 insertions(+), 104 deletions(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index 9681017e..bab89118 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -1,14 +1,12 @@ #' Get package information for active packages #' -#' This function takes 3 vectors of package names and returns a nested list of -#' package details, suitable for inclusion in manifest export. +#' This function takes a vector or (possibly nested) list of package names and +#' returns a nested list of package details, suitable for inclusion in manifest +#' export. #' -#' @param base vector of package names. Best left as default, which includes -#' the loaded base packages. -#' @param attached vector of package names. Best left as default, which -#' includes the attached packages. -#' @param loaded vector of package names. Best left as default, which includes -#' the loaded packages. +#' @param packagelist vector or list of package names. Best left as default, +#' which includes the currently loaded and attached namespaces separated into +#' useful categories. #' #' @return nested list of file details, length 3, with top level keys being #' `base`, `attached`, and `loaded`. Underneath those keys are lists of package @@ -16,40 +14,35 @@ #' [get_individual_package_info()]. #' @seealso [get_individual_package_info()] get_package_info <- function( - base = utils::sessionInfo()[["basePkgs"]], - attached = names(utils::sessionInfo()[["otherPkgs"]]), - loaded = names(utils::sessionInfo()[["loadedOnly"]]) + packagelist = list( + base = utils::sessionInfo()[["basePkgs"]], + attached = names(utils::sessionInfo()[["otherPkgs"]]), + loaded = names(utils::sessionInfo()[["loadedOnly"]]) + ) ) { log_debug("Getting package info.") - log_trace("Base packages: {base}") - base_pkgs <- vapply( - X = base, - FUN = get_individual_package_info, - FUN.VALUE = list(1L), - USE.NAMES = TRUE - ) - log_trace("Attached packages: {attached}") - attached_pkgs <- vapply( - X = attached, - FUN = get_individual_package_info, - FUN.VALUE = list(1L), - USE.NAMES = TRUE - ) - log_trace("Loaded packages: {loaded}") - loaded_pkgs <- vapply( - X = loaded, - FUN = get_individual_package_info, - FUN.VALUE = list(1L), - USE.NAMES = TRUE - ) - log_debug("Done fetching package info.") - return( - list( - base = base_pkgs, - attached = attached_pkgs, - loaded = loaded_pkgs + if (inherits(packagelist, "character")) { + out <- vapply( + X = packagelist, + FUN = function(x) { + list(x = get_individual_package_info(x)) + }, + FUN.VALUE = list(1L), + USE.NAMES = TRUE ) - ) + } else { + out <- vapply( + X = packagelist, + FUN = function(x) { + list( + x = get_package_info(x) + ) + }, + FUN.VALUE = list(1L), + USE.NAMES = TRUE + ) + } + return(out) } #' Get package information for a package @@ -59,8 +52,7 @@ get_package_info <- function( #' #' @param packagename Singular charater string of package name #' -#' @return nested list of file details, length 1, with the top-level key being -#' the `packagename` passed as an argument. underneath that key are: +#' @return nested list of file details, length 11, with keys: #' - `package`: The name of the package #' - `version`: The version of the package #' - `library`: The path of the library the package is installed in diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 32009551..65410f76 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -13,7 +13,7 @@ logger::log_appender(logger::appender_stdout) logger::log_threshold(logger::FATAL) logger::log_layout(logger::layout_simple) -test_that("get_package_info outputs correct structure", { +test_that("get_package_info outputs correct structure for defaults", { package_info <- get_package_info() expect_named( object = package_info, @@ -68,89 +68,127 @@ test_that("get_package_info outputs correct structure", { ) }) -empty_named_list <- list() -names(empty_named_list) <- character(0L) - -test_that("get_package_info with empty character args returns empty named lists", { #nolint: line_length_linter +test_that("get_package_info outputs expected value for single package", { + package_info <- get_package_info("digest") expect_identical( - object = get_package_info( - base = character(), - attached = character(), - loaded = character() - ), - expected = list( - base = empty_named_list, - attached = empty_named_list, - loaded = empty_named_list + package_info, + list( + digest = get_individual_package_info("digest") ) ) }) -test_that("get_package_info with empty args returns empty lists", { +test_that("get_package_info outputs expected value for simple vector", { + package_info <- get_package_info(c("digest", "utils")) expect_identical( - object = get_package_info( - base = c(), # nolint: unnecessary_concatenation_linter - attached = c(), # nolint: unnecessary_concatenation_linter - loaded = c() # nolint: unnecessary_concatenation_linter - ), - expected = list( - base = list(), - attached = list(), - loaded = list() + package_info, + list( + digest = get_individual_package_info("digest"), + utils = get_individual_package_info("utils") ) ) }) -test_that("get_package_info with NULL args returns empty lists", { +test_that("get_package_info outputs expected value for named vector", { + package_info <- get_package_info(c(foo = "digest", bar = "utils")) expect_identical( - object = get_package_info( - base = NULL, - attached = NULL, - loaded = NULL - ), - expected = list( - base = list(), - attached = list(), - loaded = list() + package_info, + list( + foo = get_individual_package_info("digest"), + bar = get_individual_package_info("utils") ) ) }) -test_that("get_package_info accepts length 1 arguments", { - digest_info <- get_individual_package_info("digest") +test_that("get_package_info outputs unamed list for unnamed list input", { + package_info <- get_package_info(list("digest", "utils")) expect_identical( - object = get_package_info( - base = "digest", - attached = "digest", - loaded = "digest" - ), - expected = list( - base = digest_info, - attached = digest_info, - loaded = digest_info + package_info, + list( + list(digest = get_individual_package_info("digest")), + list(utils = get_individual_package_info("utils")) ) ) }) -test_that("get_package_info respects order", { - digest_info <- get_individual_package_info("digest") - utils_info <- get_individual_package_info("utils") +test_that("get_package_info outputs expected value for simple named list", { + package_info <- get_package_info(list(foo = "digest", bar = "utils")) expect_identical( - object = get_package_info( - base = c("digest", "utils"), - attached = c("utils", "digest"), - loaded = character() - ), - expected = list( - base = c( # using c(), to concatenate already named lists) - digest_info, - utils_info - ), - attached = c( - utils_info, - digest_info - ), - loaded = empty_named_list + package_info, + list( + foo = list(digest = get_individual_package_info("digest")), + bar = list(utils = get_individual_package_info("utils")) ) ) }) + +empty_named_list <- list() +names(empty_named_list) <- character(0L) + +# test_that("get_package_info with empty character args returns empty named lists", { #nolint: line_length_linter +# expect_identical( +# object = get_package_info(list( +# base = character(), +# attached = character(), +# loaded = character() +# )), +# expected = list( +# base = empty_named_list, +# attached = empty_named_list, +# loaded = empty_named_list +# ) +# ) +# }) + +# test_that("get_package_info with empty args returns empty lists", { +# expect_identical( +# object = get_package_info(list( +# base = c(), # nolint: unnecessary_concatenation_linter +# attached = c(), # nolint: unnecessary_concatenation_linter +# loaded = c() # nolint: unnecessary_concatenation_linter +# )), +# expected = list( +# base = list(), +# attached = list(), +# loaded = list() +# ) +# ) +# }) + +# test_that("get_package_info with NULL args returns empty lists", { +# expect_identical( +# object = get_package_info(list( +# base = NULL, +# attached = NULL, +# loaded = NULL +# )), +# expected = list( +# base = list(), +# attached = list(), +# loaded = list() +# ) +# ) +# }) + +# test_that("get_package_info respects order", { +# digest_info <- get_individual_package_info("digest") +# utils_info <- get_individual_package_info("utils") +# expect_identical( +# object = get_package_info( +# list( +# base = c("digest", "utils"), +# attached = c("utils", "digest") +# ) +# ), +# expected = list( +# base = list( +# digest = digest_info, +# utils = utils_info +# ), +# attached = list( +# utils = utils_info, +# digest = digest_info +# ) +# ) +# ) +# }) From ebc651798a55790d1a5e478c920773a6b4cddfd5 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 10:44:33 +0100 Subject: [PATCH 75/90] update rendered docs --- man/get_individual_package_info.Rd | 3 +-- man/get_package_info.Rd | 22 +++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/man/get_individual_package_info.Rd b/man/get_individual_package_info.Rd index 2a3b906b..4f56aecb 100644 --- a/man/get_individual_package_info.Rd +++ b/man/get_individual_package_info.Rd @@ -10,8 +10,7 @@ get_individual_package_info(packagename) \item{packagename}{Singular charater string of package name} } \value{ -nested list of file details, length 1, with the top-level key being -the \code{packagename} passed as an argument. underneath that key are: +nested list of file details, length 11, with keys: \itemize{ \item \code{package}: The name of the package \item \code{version}: The version of the package diff --git a/man/get_package_info.Rd b/man/get_package_info.Rd index 39d5aeed..910150e4 100644 --- a/man/get_package_info.Rd +++ b/man/get_package_info.Rd @@ -5,20 +5,15 @@ \title{Get package information for active packages} \usage{ get_package_info( - base = utils::sessionInfo()[["basePkgs"]], - attached = names(utils::sessionInfo()[["otherPkgs"]]), - loaded = names(utils::sessionInfo()[["loadedOnly"]]) + packagelist = list(base = utils::sessionInfo()[["basePkgs"]], attached = + names(utils::sessionInfo()[["otherPkgs"]]), loaded = + names(utils::sessionInfo()[["loadedOnly"]])) ) } \arguments{ -\item{base}{vector of package names. Best left as default, which includes -the loaded base packages.} - -\item{attached}{vector of package names. Best left as default, which -includes the attached packages.} - -\item{loaded}{vector of package names. Best left as default, which includes -the loaded packages.} +\item{packagelist}{vector or list of package names. Best left as default, +which includes the currently loaded and attached namespaces separated into +useful categories.} } \value{ nested list of file details, length 3, with top level keys being @@ -27,8 +22,9 @@ details, with the package names as keys, and further details as returned by \code{\link[=get_individual_package_info]{get_individual_package_info()}}. } \description{ -This function takes 3 vectors of package names and returns a nested list of -package details, suitable for inclusion in manifest export. +This function takes a vector or (possibly nested) list of package names and +returns a nested list of package details, suitable for inclusion in manifest +export. } \seealso{ \code{\link[=get_individual_package_info]{get_individual_package_info()}} From f2c816ffbcb4841a9d4b3c07cd8d2cbe63108c33 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 10:47:33 +0100 Subject: [PATCH 76/90] re-enable tests --- tests/testthat/test-get_package_info.R | 128 ++++++++++++------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 65410f76..d0fa917e 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -125,70 +125,70 @@ test_that("get_package_info outputs expected value for simple named list", { empty_named_list <- list() names(empty_named_list) <- character(0L) -# test_that("get_package_info with empty character args returns empty named lists", { #nolint: line_length_linter -# expect_identical( -# object = get_package_info(list( -# base = character(), -# attached = character(), -# loaded = character() -# )), -# expected = list( -# base = empty_named_list, -# attached = empty_named_list, -# loaded = empty_named_list -# ) -# ) -# }) +test_that("get_package_info with empty character args returns empty named lists", { #nolint: line_length_linter + expect_identical( + object = get_package_info(list( + base = character(), + attached = character(), + loaded = character() + )), + expected = list( + base = empty_named_list, + attached = empty_named_list, + loaded = empty_named_list + ) + ) +}) -# test_that("get_package_info with empty args returns empty lists", { -# expect_identical( -# object = get_package_info(list( -# base = c(), # nolint: unnecessary_concatenation_linter -# attached = c(), # nolint: unnecessary_concatenation_linter -# loaded = c() # nolint: unnecessary_concatenation_linter -# )), -# expected = list( -# base = list(), -# attached = list(), -# loaded = list() -# ) -# ) -# }) +test_that("get_package_info with empty args returns empty lists", { + expect_identical( + object = get_package_info(list( + base = c(), # nolint: unnecessary_concatenation_linter + attached = c(), # nolint: unnecessary_concatenation_linter + loaded = c() # nolint: unnecessary_concatenation_linter + )), + expected = list( + base = list(), + attached = list(), + loaded = list() + ) + ) +}) -# test_that("get_package_info with NULL args returns empty lists", { -# expect_identical( -# object = get_package_info(list( -# base = NULL, -# attached = NULL, -# loaded = NULL -# )), -# expected = list( -# base = list(), -# attached = list(), -# loaded = list() -# ) -# ) -# }) +test_that("get_package_info with NULL args returns empty lists", { + expect_identical( + object = get_package_info(list( + base = NULL, + attached = NULL, + loaded = NULL + )), + expected = list( + base = list(), + attached = list(), + loaded = list() + ) + ) +}) -# test_that("get_package_info respects order", { -# digest_info <- get_individual_package_info("digest") -# utils_info <- get_individual_package_info("utils") -# expect_identical( -# object = get_package_info( -# list( -# base = c("digest", "utils"), -# attached = c("utils", "digest") -# ) -# ), -# expected = list( -# base = list( -# digest = digest_info, -# utils = utils_info -# ), -# attached = list( -# utils = utils_info, -# digest = digest_info -# ) -# ) -# ) -# }) +test_that("get_package_info respects order", { + digest_info <- get_individual_package_info("digest") + utils_info <- get_individual_package_info("utils") + expect_identical( + object = get_package_info( + list( + base = c("digest", "utils"), + attached = c("utils", "digest") + ) + ), + expected = list( + base = list( + digest = digest_info, + utils = utils_info + ), + attached = list( + utils = utils_info, + digest = digest_info + ) + ) + ) +}) From 86b0db7b29170999f5a8d249e48f4457b6a72f4b Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 10:50:00 +0100 Subject: [PATCH 77/90] Add test for mixed nesting --- tests/testthat/test-get_package_info.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index d0fa917e..7a171bfa 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -122,6 +122,24 @@ test_that("get_package_info outputs expected value for simple named list", { ) }) +test_that("get_package_info outputs expected value for list with mixed nesting", { + package_info <- get_package_info( + list( + foo = list(list("digest")), + bar = list("digest"), + baz = "utils" + ) + ) + expect_identical( + package_info, + list( + foo = list(list(list(digest = get_individual_package_info("digest")))), + bar = list(list(digest = get_individual_package_info("digest"))), + baz = list(utils = get_individual_package_info("utils")) + ) + ) +}) + empty_named_list <- list() names(empty_named_list) <- character(0L) From cc7f45d66e71b34393081e5ba87c98c7ecc3d3c8 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 11:44:55 +0100 Subject: [PATCH 78/90] lintr exclusion --- tests/testthat/test-get_package_info.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 7a171bfa..aba8929b 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -122,7 +122,7 @@ test_that("get_package_info outputs expected value for simple named list", { ) }) -test_that("get_package_info outputs expected value for list with mixed nesting", { +test_that("get_package_info outputs expected value for list with mixed nesting", { #nolint: line_length_linter package_info <- get_package_info( list( foo = list(list("digest")), From c5581123b1f3ac6da9efbd1967466ca759b63774 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 15:14:15 +0100 Subject: [PATCH 79/90] Add handling for packages loaded with pkgload --- R/get_package_info.R | 31 +++++- .../test-get_individual_package_info.R | 89 ++++++++++++--- tests/testthat/test-get_package_info.R | 101 +++++++++--------- 3 files changed, 155 insertions(+), 66 deletions(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index bab89118..6a5ebafe 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -55,6 +55,8 @@ get_package_info <- function( #' @return nested list of file details, length 11, with keys: #' - `package`: The name of the package #' - `version`: The version of the package +#' - `dev_version`: Is this version a development version (loaded with +#' `pkgload`)? #' - `library`: The path of the library the package is installed in #' - `library_index`: The index of the library in the `.libPaths()` vector #' - `repository`: The repository the package was pulled from @@ -67,7 +69,30 @@ get_package_info <- function( get_individual_package_info <- function(packagename) { if (length(packagename) != 1L || !is.character(packagename)) { log_error("packagename must be a single string.") + # Early return stop("packagename must be a single string.") + } + dev_package <- pkgload::is_dev_package(packagename) + if (dev_package) { + log_warn("Package \"{packagename}\" is a development package.") + log_warn("Package information may not be accurate.") + warning("Identifying development packages may not be accurate.") + package_dev_dir <- pkgload::pkg_path( + path = dirname(system.file("DESCRIPTION", package = packagename)) + ) + pkg_details <- list( + package = pkgload::pkg_name(package_dev_dir), + version = paste("DEV", pkgload::pkg_version(package_dev_dir)), + library = NA_character_, + library_index = NA_integer_, + repository = NA_character_, + platform = NA_character_, + built = NA_character_, + remotetype = "pkgload", + remotepkgref = package_dev_dir, + remoteref = NA_character_, + remotesha = NA_character_ + ) } else { if (packagename %in% utils::installed.packages()[, "Package"]) { installed_index <- which( @@ -89,7 +114,6 @@ get_individual_package_info <- function(packagename) { log_error("Package \"{packagename}\" is not installed.") stop("Package is not installed.") } - } log_trace("Getting package info for {packagename}.") pkg_details <- as.list( pkgdepends::lib_status( @@ -97,11 +121,14 @@ get_individual_package_info <- function(packagename) { packages = packagename ) ) + pkg_details[["library_index"]] <- lib_index + } details_list <- list( package = pkg_details[["package"]], version = pkg_details[["version"]], + dev_version = dev_package, library = pkg_details[["library"]], - library_index = lib_index, + library_index = pkg_details[["library_index"]], repository = pkg_details[["repository"]], platform = pkg_details[["platform"]], built = pkg_details[["built"]], diff --git a/tests/testthat/test-get_individual_package_info.R b/tests/testthat/test-get_individual_package_info.R index 9a3ddc2e..b7667519 100644 --- a/tests/testthat/test-get_individual_package_info.R +++ b/tests/testthat/test-get_individual_package_info.R @@ -21,7 +21,8 @@ expect_package_info <- function( remotetype_identical, remotepkgref_match, remoteref_identical, - remotesha_identical + remotesha_identical, + dev_version_identical = FALSE ) { testthat::expect_type(package_info, "list") testthat::expect_named( @@ -29,6 +30,7 @@ expect_package_info <- function( expected = c( "package", "version", + "dev_version", "library", "library_index", "repository", @@ -48,10 +50,43 @@ expect_package_info <- function( object = package_info[["version"]], expected = version_identical ) - testthat::expect_in( - object = package_info[["library"]], - .libPaths() #nolint: undesirable_function_linter + testthat::expect_identical( + object = package_info[["dev_version"]], + expected = dev_version_identical ) + + if (dev_version_identical) { + testthat::expect_identical( + object = package_info[["library"]], + expected = NA_character_ + ) + testthat::expect_identical( + object = package_info[["library_index"]], + expected = NA_integer_ + ) + testthat::expect_identical( + object = package_info[["platform"]], + expected = NA_character_ + ) + } else { + testthat::expect_in( + object = package_info[["library"]], + .libPaths() #nolint: undesirable_function_linter + ) + testthat::expect_gt( + object = package_info[["library_index"]], + expected = 0L + ) + testthat::expect_lte( + object = package_info[["library_index"]], + expected = length(.libPaths()) #nolint: undesirable_function_linter + ) + testthat::expect_match( + object = package_info[["platform"]], + regexp = R.version[["platform"]] + ) + } + testthat::expect_identical( object = package_info[["library"]], expected = .libPaths()[package_info[["library_index"]]] #nolint: undesirable_function_linter @@ -60,14 +95,6 @@ expect_package_info <- function( object = package_info[["library_index"]], type = "integer" ) - testthat::expect_gt( - object = package_info[["library_index"]], - expected = 0L - ) - testthat::expect_lte( - object = package_info[["library_index"]], - expected = length(.libPaths()) #nolint: undesirable_function_linter - ) if (is.na(repository_match)) { testthat::expect_identical( package_info[["repository"]], @@ -79,10 +106,6 @@ expect_package_info <- function( regexp = repository_match ) } - testthat::expect_match( - object = package_info[["platform"]], - regexp = R.version[["platform"]] - ) testthat::expect_false( is.null(x = package_info[["built"]]) ) @@ -209,6 +232,40 @@ test_that("get_individual_package_info collects information for GitHub packages }) }) +test_that("get_individual_package_info collects information for packages loaded with pkgload correctly", { #nolint: line_length_linter + testthat::skip_on_cran() + testthat::skip_if_offline() + dest_dir <- normalizePath(withr::local_tempdir()) + dl <- gert::git_clone( + url = "https://github.com/yihui/rmini.git", #nolint: nonportable_path_linter + path = dest_dir, + verbose = FALSE + ) + loaded <- pkgload::load_all(dest_dir, quiet = TRUE) + withr::defer({devtools::unload(package = "rmini")}) + testthat::expect_warning( + object = { + package_info <- get_individual_package_info("rmini") + expect_package_info( + package_info, + package_identical = "rmini", + version_identical = "DEV 0.0.4", + dev_version_identical = TRUE, + repository_match = NA_character_, + remotetype_identical = "pkgload", + remotepkgref_match = paste0("^", dest_dir, "$"), + remoteref_identical = NA_character_, + remotesha_identical = NA_character_ + ) + expect_identical( + package_info[["remotepkgref"]], + normalizePath(dest_dir) + ) + }, + "^Identifying development packages may not be accurate.$" + ) +}) + test_that("get_individual_package_info errors for multiple packages", { expect_error( get_individual_package_info(c("digest", "jsonlite")) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index aba8929b..95480033 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -14,57 +14,62 @@ logger::log_threshold(logger::FATAL) logger::log_layout(logger::layout_simple) test_that("get_package_info outputs correct structure for defaults", { - package_info <- get_package_info() - expect_named( - object = package_info, - expected = c("base", "attached", "loaded") - ) - expect_named( - object = package_info[["base"]], - expected = utils::sessionInfo()[["basePkgs"]] - ) - expect_named( - object = package_info[["attached"]], - expected = names(utils::sessionInfo()[["otherPkgs"]]) - ) - expect_named( - object = package_info[["loaded"]], - expected = names(utils::sessionInfo()[["loadedOnly"]]) - ) - # Check that the structure of the package_info is correct - expect_true( - object = all( - vapply( - X = package_info, - FUN = function(x) { - all( - vapply( - X = x, - FUN = function(x) { - all( - names(x) == c( - "package", - "version", - "library", - "library_index", - "repository", - "platform", - "built", - "remotetype", - "remotepkgref", - "remoteref", - "remotesha" - ) + testthat::expect_warning( + object = { + package_info <- get_package_info() + expect_named( + object = package_info, + expected = c("base", "attached", "loaded") + ) + expect_named( + object = package_info[["base"]], + expected = utils::sessionInfo()[["basePkgs"]] + ) + expect_named( + object = package_info[["attached"]], + expected = names(utils::sessionInfo()[["otherPkgs"]]) + ) + expect_named( + object = package_info[["loaded"]], + expected = names(utils::sessionInfo()[["loadedOnly"]]) + ) + # Check that the structure of the package_info is correct + expect_true( + object = all( + vapply( + X = package_info, + FUN = function(x) { + all( + vapply( + X = x, + FUN = function(x) { + all( + names(x) == c( + "package", + "version", + "dev_version", + "library", + "library_index", + "repository", + "platform", + "built", + "remotetype", + "remotepkgref", + "remoteref", + "remotesha" + ) + ) + }, + FUN.VALUE = logical(1L) ) - }, - FUN.VALUE = logical(1L) - ) + ) + }, + FUN.VALUE = logical(1L) ) - }, - FUN.VALUE = logical(1L) + ) ) - ) - + }, + "^Identifying development packages may not be accurate.$" ) }) From ed66d62201c222bfe64174247fd493b2b3c90427 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 15:17:12 +0100 Subject: [PATCH 80/90] Add test for `devtools::load_all()` --- .../test-get_individual_package_info.R | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_individual_package_info.R b/tests/testthat/test-get_individual_package_info.R index b7667519..7ca25ba6 100644 --- a/tests/testthat/test-get_individual_package_info.R +++ b/tests/testthat/test-get_individual_package_info.R @@ -242,7 +242,45 @@ test_that("get_individual_package_info collects information for packages loaded verbose = FALSE ) loaded <- pkgload::load_all(dest_dir, quiet = TRUE) - withr::defer({devtools::unload(package = "rmini")}) + withr::defer({ + pkgload::unload(package = "rmini") + }) + testthat::expect_warning( + object = { + package_info <- get_individual_package_info("rmini") + expect_package_info( + package_info, + package_identical = "rmini", + version_identical = "DEV 0.0.4", + dev_version_identical = TRUE, + repository_match = NA_character_, + remotetype_identical = "pkgload", + remotepkgref_match = paste0("^", dest_dir, "$"), + remoteref_identical = NA_character_, + remotesha_identical = NA_character_ + ) + expect_identical( + package_info[["remotepkgref"]], + normalizePath(dest_dir) + ) + }, + "^Identifying development packages may not be accurate.$" + ) +}) + +test_that("get_individual_package_info collects information for packages loaded with devtools correctly", { #nolint: line_length_linter + testthat::skip_on_cran() + testthat::skip_if_offline() + dest_dir <- normalizePath(withr::local_tempdir()) + dl <- gert::git_clone( + url = "https://github.com/yihui/rmini.git", #nolint: nonportable_path_linter + path = dest_dir, + verbose = FALSE + ) + loaded <- devtools::load_all(dest_dir, quiet = TRUE) + withr::defer({ + devtools::unload(package = "rmini") + }) testthat::expect_warning( object = { package_info <- get_individual_package_info("rmini") From 9addb26a68a307ffac0d3b4a18d0ce1ed9295233 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 15:21:13 +0100 Subject: [PATCH 81/90] Add pkgload dependency --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2e0b7f56..cbbb32d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,8 @@ Imports: digest, jsonlite, logger, - pkgdepends + pkgdepends, + pkgload Suggests: gert, pak, From eb69f3a1e03c26d3f1dc1714bc483abaa5198629 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 15:21:32 +0100 Subject: [PATCH 82/90] Add skips for missing packages --- tests/testthat/test-get_individual_package_info.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-get_individual_package_info.R b/tests/testthat/test-get_individual_package_info.R index 7ca25ba6..edf68faa 100644 --- a/tests/testthat/test-get_individual_package_info.R +++ b/tests/testthat/test-get_individual_package_info.R @@ -235,6 +235,7 @@ test_that("get_individual_package_info collects information for GitHub packages test_that("get_individual_package_info collects information for packages loaded with pkgload correctly", { #nolint: line_length_linter testthat::skip_on_cran() testthat::skip_if_offline() + testthat::skip_if_not_installed("pkgload") dest_dir <- normalizePath(withr::local_tempdir()) dl <- gert::git_clone( url = "https://github.com/yihui/rmini.git", #nolint: nonportable_path_linter @@ -271,6 +272,7 @@ test_that("get_individual_package_info collects information for packages loaded test_that("get_individual_package_info collects information for packages loaded with devtools correctly", { #nolint: line_length_linter testthat::skip_on_cran() testthat::skip_if_offline() + testthat::skip_if_not_installed("devtools") dest_dir <- normalizePath(withr::local_tempdir()) dl <- gert::git_clone( url = "https://github.com/yihui/rmini.git", #nolint: nonportable_path_linter From f6a54f241a738b674395138fa1ccd4adfdf3d434 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 15:54:21 +0100 Subject: [PATCH 83/90] Add warning handling warning only emitted if package loaded with pkgload, which does not happen with R CMD CHECK --- tests/testthat/test-get_package_info.R | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 95480033..85d5fb2c 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -13,8 +13,20 @@ logger::log_appender(logger::appender_stdout) logger::log_threshold(logger::FATAL) logger::log_layout(logger::layout_simple) +expect_warning_if_not_cran <- function(object, regexp) { + on_cran <- ( + !interactive() && + !isTRUE(as.logical(Sys.getenv("NOT_CRAN", "false"))) + ) + if (on_cran) { + object + } else { + testthat::expect_warning(object = object, regexp = regexp) + } +} + test_that("get_package_info outputs correct structure for defaults", { - testthat::expect_warning( + expect_warning_if_not_cran( object = { package_info <- get_package_info() expect_named( From cb5a36f8c7397da0647b24952adf64721ddb5125 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 15:57:00 +0100 Subject: [PATCH 84/90] Reindent --- R/get_package_info.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index 6a5ebafe..ecb2802a 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -114,14 +114,14 @@ get_individual_package_info <- function(packagename) { log_error("Package \"{packagename}\" is not installed.") stop("Package is not installed.") } - log_trace("Getting package info for {packagename}.") - pkg_details <- as.list( - pkgdepends::lib_status( - library = lib, - packages = packagename + log_trace("Getting package info for {packagename}.") + pkg_details <- as.list( + pkgdepends::lib_status( + library = lib, + packages = packagename + ) ) - ) - pkg_details[["library_index"]] <- lib_index + pkg_details[["library_index"]] <- lib_index } details_list <- list( package = pkg_details[["package"]], From f54db91f818b5c6afb6c778397f7a12d9d6e0eb3 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 16:02:28 +0100 Subject: [PATCH 85/90] Add devtools to suggests --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index cbbb32d1..3f3fc46c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,7 @@ Imports: pkgdepends, pkgload Suggests: + devtools, gert, pak, testthat (>= 3.0.0), From f54e7097d189c811bc6a46e183f3a9e029d5bf67 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 17:41:16 +0100 Subject: [PATCH 86/90] Check for pkgload, not CRAN for warning handler --- tests/testthat/test-get_package_info.R | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 85d5fb2c..b8149dd3 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -13,20 +13,24 @@ logger::log_appender(logger::appender_stdout) logger::log_threshold(logger::FATAL) logger::log_layout(logger::layout_simple) -expect_warning_if_not_cran <- function(object, regexp) { - on_cran <- ( - !interactive() && - !isTRUE(as.logical(Sys.getenv("NOT_CRAN", "false"))) - ) - if (on_cran) { - object - } else { +expect_warning_if_any_pkgload <- function(object, regexp) { + attached_pkgs <- names(utils::sessionInfo()[["otherPkgs"]]) + has_pkgload <- any( + vapply( + X = attached_pkgs, + FUN = pkgload::is_dev_package, + FUN.VALUE = logical(1L) + ) + ) + if (has_pkgload) { testthat::expect_warning(object = object, regexp = regexp) + } else { + testthat::expect_no_warning(object = object) } } test_that("get_package_info outputs correct structure for defaults", { - expect_warning_if_not_cran( + expect_warning_if_any_pkgload( object = { package_info <- get_package_info() expect_named( From a9b856abada5a65091d64806705a46454eee4f22 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 18:00:40 +0100 Subject: [PATCH 87/90] Do not test for silence this interferes with CI systems that may install the package multiple times --- tests/testthat/test-get_package_info.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index b8149dd3..1957d088 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -20,12 +20,15 @@ expect_warning_if_any_pkgload <- function(object, regexp) { X = attached_pkgs, FUN = pkgload::is_dev_package, FUN.VALUE = logical(1L) - ) ) + ) if (has_pkgload) { testthat::expect_warning(object = object, regexp = regexp) } else { - testthat::expect_no_warning(object = object) + # note not using testthat::expect_no_warning(object = object), since there + # are often warnings on CI systems about multiple installations of the + # tested package + object } } From 69ac9bbc50518716421730f3a72b062fdcd81d8a Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 18:04:51 +0100 Subject: [PATCH 88/90] update rendered docs --- man/get_individual_package_info.Rd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/man/get_individual_package_info.Rd b/man/get_individual_package_info.Rd index 4f56aecb..03f31777 100644 --- a/man/get_individual_package_info.Rd +++ b/man/get_individual_package_info.Rd @@ -14,6 +14,8 @@ nested list of file details, length 11, with keys: \itemize{ \item \code{package}: The name of the package \item \code{version}: The version of the package +\item \code{dev_version}: Is this version a development version (loaded with +\code{pkgload})? \item \code{library}: The path of the library the package is installed in \item \code{library_index}: The index of the library in the \code{.libPaths()} vector \item \code{repository}: The repository the package was pulled from From 876b4fb60b8660ad0a2831fd4db869f01a8fa638 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Mon, 25 Mar 2024 18:14:20 +0100 Subject: [PATCH 89/90] Normalize path --- R/get_package_info.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index ecb2802a..95fcd546 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -89,7 +89,7 @@ get_individual_package_info <- function(packagename) { platform = NA_character_, built = NA_character_, remotetype = "pkgload", - remotepkgref = package_dev_dir, + remotepkgref = normalizePath(package_dev_dir), remoteref = NA_character_, remotesha = NA_character_ ) From d94cc6a45c599d5779b7555389aba5b2ae99e375 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 26 Mar 2024 12:19:40 +0100 Subject: [PATCH 90/90] change output key name --- R/get_package_info.R | 6 +++--- man/get_individual_package_info.Rd | 4 ++-- tests/testthat/test-get_individual_package_info.R | 14 +++++++------- tests/testthat/test-get_package_info.R | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/R/get_package_info.R b/R/get_package_info.R index 95fcd546..7da8aa57 100644 --- a/R/get_package_info.R +++ b/R/get_package_info.R @@ -55,8 +55,8 @@ get_package_info <- function( #' @return nested list of file details, length 11, with keys: #' - `package`: The name of the package #' - `version`: The version of the package -#' - `dev_version`: Is this version a development version (loaded with -#' `pkgload`)? +#' - `loaded_with_pkgload`: Is this package loaded with `pkgload`? (logical). +#' Useful for identifying local development versions #' - `library`: The path of the library the package is installed in #' - `library_index`: The index of the library in the `.libPaths()` vector #' - `repository`: The repository the package was pulled from @@ -126,7 +126,7 @@ get_individual_package_info <- function(packagename) { details_list <- list( package = pkg_details[["package"]], version = pkg_details[["version"]], - dev_version = dev_package, + loaded_with_pkgload = dev_package, library = pkg_details[["library"]], library_index = pkg_details[["library_index"]], repository = pkg_details[["repository"]], diff --git a/man/get_individual_package_info.Rd b/man/get_individual_package_info.Rd index 03f31777..b7c1bc29 100644 --- a/man/get_individual_package_info.Rd +++ b/man/get_individual_package_info.Rd @@ -14,8 +14,8 @@ nested list of file details, length 11, with keys: \itemize{ \item \code{package}: The name of the package \item \code{version}: The version of the package -\item \code{dev_version}: Is this version a development version (loaded with -\code{pkgload})? +\item \code{loaded_with_pkgload}: Is this package loaded with \code{pkgload}? (logical). +Useful for identifying local development versions \item \code{library}: The path of the library the package is installed in \item \code{library_index}: The index of the library in the \code{.libPaths()} vector \item \code{repository}: The repository the package was pulled from diff --git a/tests/testthat/test-get_individual_package_info.R b/tests/testthat/test-get_individual_package_info.R index edf68faa..f25385c9 100644 --- a/tests/testthat/test-get_individual_package_info.R +++ b/tests/testthat/test-get_individual_package_info.R @@ -22,7 +22,7 @@ expect_package_info <- function( remotepkgref_match, remoteref_identical, remotesha_identical, - dev_version_identical = FALSE + loaded_with_pkgload_identical = FALSE ) { testthat::expect_type(package_info, "list") testthat::expect_named( @@ -30,7 +30,7 @@ expect_package_info <- function( expected = c( "package", "version", - "dev_version", + "loaded_with_pkgload", "library", "library_index", "repository", @@ -51,11 +51,11 @@ expect_package_info <- function( expected = version_identical ) testthat::expect_identical( - object = package_info[["dev_version"]], - expected = dev_version_identical + object = package_info[["loaded_with_pkgload"]], + expected = loaded_with_pkgload_identical ) - if (dev_version_identical) { + if (loaded_with_pkgload_identical) { testthat::expect_identical( object = package_info[["library"]], expected = NA_character_ @@ -253,7 +253,7 @@ test_that("get_individual_package_info collects information for packages loaded package_info, package_identical = "rmini", version_identical = "DEV 0.0.4", - dev_version_identical = TRUE, + loaded_with_pkgload_identical = TRUE, repository_match = NA_character_, remotetype_identical = "pkgload", remotepkgref_match = paste0("^", dest_dir, "$"), @@ -290,7 +290,7 @@ test_that("get_individual_package_info collects information for packages loaded package_info, package_identical = "rmini", version_identical = "DEV 0.0.4", - dev_version_identical = TRUE, + loaded_with_pkgload_identical = TRUE, repository_match = NA_character_, remotetype_identical = "pkgload", remotepkgref_match = paste0("^", dest_dir, "$"), diff --git a/tests/testthat/test-get_package_info.R b/tests/testthat/test-get_package_info.R index 1957d088..23682723 100644 --- a/tests/testthat/test-get_package_info.R +++ b/tests/testthat/test-get_package_info.R @@ -66,7 +66,7 @@ test_that("get_package_info outputs correct structure for defaults", { names(x) == c( "package", "version", - "dev_version", + "loaded_with_pkgload", "library", "library_index", "repository",